Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在设定的时间段内创建功能阻止程序_Javascript_Function_Timer_Block_Clearinterval - Fatal编程技术网

Javascript 在设定的时间段内创建功能阻止程序

Javascript 在设定的时间段内创建功能阻止程序,javascript,function,timer,block,clearinterval,Javascript,Function,Timer,Block,Clearinterval,我正在为我在plug.dj上运行的一个房间编写一个自定义脚本,并为AFK、工作和睡眠实现了自动消息警报。因此,如果您的状态设置为AFK,并且有人提到您,他们会收到一条与AFK状态相关的自动消息。以下是此操作的代码: function autoRespond(data) { var a = data.type == "mention" && Models.room.data.staff[data.fromID] && Models.room.data.staff[d

我正在为我在plug.dj上运行的一个房间编写一个自定义脚本,并为AFK、工作和睡眠实现了自动消息警报。因此,如果您的状态设置为AFK,并且有人提到您,他们会收到一条与AFK状态相关的自动消息。以下是此操作的代码:

function autoRespond(data) {
var a = data.type == "mention" && Models.room.data.staff[data.fromID] && Models.room.data.staff[data.fromID] >= Models.user.BOUNCER, b = data.message.indexOf('@') >0;
if (data.type == "mention") {
    if (Models.user.data.status == 1)
    API.sendChat("@" + data.from + " automsg: I'm currently AFK");
    if (Models.user.data.status ==2)
    API.sendChat("@" + data.from + "automsg: I'm currently working");
    if (Models.user.data.status ==3)
    API.sendChat("@" + data.from + " automsg: I'm currently sleeping");
    }
}


我想做的是,如果某人在被设置为状态之一时被提及,我想在自动消息之前添加一个计时器,因为它再次处于活动状态。假设我将我的设置为AFK,然后有人提到我,他们将收到一条自动消息,如果有人在计时器内提到我,自动消息将无法发送(延迟后再发送)。我希望能得到正确的帮助,谢谢。

您可以使用setTimeout,如下所示:

HTML:

消息
JavaScript:

$('#button').on('click', function(){
    sendMessage();   
}); 
var sended = false ;
function  sendMessage(){
    if( !sended ){
        $('div').html($('div').html() + '<br />new message');
        sended = true;
        wait( 2000 );
    }
}

function wait( miliseconds ){
     setTimeout(function(){
         sended = false;
     }, miliseconds)   
}
$(“#按钮”)。在('click',function()上{
sendMessage();
}); 
var sended=false;
函数sendMessage(){
如果(!已发送){
$('div').html($('div').html();
sended=真;
等待(2000年);
}
}
功能等待(毫秒){
setTimeout(函数(){
sended=false;
},毫秒)
}
你可以看到这个工作

$('#button').on('click', function(){
    sendMessage();   
}); 
var sended = false ;
function  sendMessage(){
    if( !sended ){
        $('div').html($('div').html() + '<br />new message');
        sended = true;
        wait( 2000 );
    }
}

function wait( miliseconds ){
     setTimeout(function(){
         sended = false;
     }, miliseconds)   
}