import BaseDirective from "./BaseDirective";

class TestDirective extends BaseDirective {
    match () {
        const {text} = this
        if(/熊猫测试指令/.test(text)) {
            return true
        }
        return false
    }
    async excute ({
        sendMsg = function () {},
    }) {
        return new Promise((resolve , reject) => {
            this.resolve = resolve
            this.reject = reject
            this.testCloseSession({sendMsg})
        })
    }

    closeResponse () {
        if(this.timer) {
            clearInterval(this.timer)
            this.timer = null
        }
        this.reject && this.reject()
    }

    testCloseSession({sendMsg}) {
        let count = 0;
        let random = parseInt(Math.random() * 50 + 1)
        this.timer = setInterval(() => {
            count++
            if(count % random == 0) {
                random =  parseInt(Math.random() * 50 + 1)
                sendMsg(count)
            } 
        }, 100)
    }
}

export default TestDirective