Picarto.tv
のために友人のセットアップにボットを手助けしようとしている
、我々はボットLINKを持っており、デフォルトplugin
は、メッセージを繰り返すためにそこにありませんので、私は非常に原油を作ってみました(真剣に、それはひどいです私は開発者ではありません)plugin
のために、私はSetInterval/SetTimeout
を使用しようとしました、そして、私はそれらを使用すると、メッセージを設定された間隔で一度チャットに入れますインターバルの後に、メッセージを2回、3回などと言うでしょう。のNode.js - のsetInterval&setTimeoutをインクリメンタルに繰り返しコマンド
それは次のようになります。上の
Time 1:
Testing...
Time 2:
Testing...
Testing...
そしてそう。ここでコードは、私が言ったように、それはひどく作られた、私のためにそれをあまりにも難しくしないでください。
var api;
function handleChatMsg(data) {
var recursive = function() {
api.Messages.send("Testing Bot Repeat...");
setTimeout(recursive,15000);
}
recursive();
}
module.exports = {
meta_inf: {
name: "Repeat Message",
version: "1.0.0",
description: "Repeats a message every 5 minutes. Message and interval can be changed.",
author: "ZX6R"
},
load: function (_api) {
api = _api;
},
start: function() {
api.Events.on("userMsg", handleChatMsg);
}
}
メッセージを何度も増やしている理由を理解できますか?
EDIT:問題を修正し、新しいコードは
var api;
// Function to call for the repeating
function handleChatMsg() {
// This sets the interval of 5 minutes, and calls the variable. Edit the numbers after the comma to change the interval. You MUST put it into milliseconds.
setInterval(function(){xyz()}, 15000);
// This sets the variable, edit the text in "api.Messages.send" to change what the bot repeats.
var xyz = function()
{
api.Messages.send("Testing...")
}
}
// defines some information about the plugin, and sets up stuff we need.
module.exports = {
meta_inf: {
name: "Repeat Message",
version: "1.1.1",
description: "Repeats a message every 5 minutes. Message and interval can be changed.",
author: "ZX6R"
},
load: function (_api) {
api = _api;
},
start: function() {
handleChatMsg();
}
}
// The MIT License (MIT)
// Copyright (c) 2016 RedFalconv2 - ZX6R - WalnutGaming
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
これは私の以前のものより少し洗練されていますが、初めてテストの後にさらにテストを追加し続けます。私はそのスタート 'に関連していると思う:function(){ api.Events.on( "userMsg"、handleChatMsg); } } ' – Thunderwolf
メッセージが送信されたことを検出している可能性がありますし、setinterval AGAINを実行しています。しかし、プラグインはこのapi.Events.onや関数の前にすべてのものをロードすることはありません。 – Thunderwolf
私は正しく、最初に "handleChatMsg"関数を呼び出すように変更しました。これで正しく動作します!ちなみに、Node Cronの方が良いと思いますか、この方法ですか?私はちょうどボットを自分の走りのままにして、ストリームの間に置いておきたいと思っています。 – Thunderwolf