Tokebot ported to codebase.
This commit is contained in:
parent
1da7cab9cd
commit
2fc8f16e9d
6 changed files with 1888 additions and 2521 deletions
|
|
@ -238,6 +238,7 @@ Channel.prototype.initModules = function () {
|
|||
"./permissions" : "permissions",
|
||||
"./emotes" : "emotes",
|
||||
"./chat" : "chat",
|
||||
"./tokebot" : "tokebot",
|
||||
"./filters" : "filters",
|
||||
"./customization" : "customization",
|
||||
"./opts" : "options",
|
||||
|
|
|
|||
127
src/channel/tokebot.js
Normal file
127
src/channel/tokebot.js
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
var ChannelModule = require("./module");
|
||||
|
||||
function TokebotModule(_channel){
|
||||
ChannelModule.apply(this, arguments);
|
||||
|
||||
if(this.channel.modules.chat){
|
||||
this.channel.modules.chat.registerCommand("!toke", this.toke.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
TokebotModule.prototype = Object.create(ChannelModule.prototype);
|
||||
|
||||
TokebotModule.prototype.handleEchoTest = function(user, msg, _meta){
|
||||
this.tokesay(msg);
|
||||
};
|
||||
|
||||
TokebotModule.prototype.toking = 0;
|
||||
TokebotModule.prototype.tokers = [];
|
||||
TokebotModule.prototype.cdown = 3;
|
||||
TokebotModule.prototype.cdel = 120;
|
||||
TokebotModule.prototype.ctime = 120;
|
||||
TokebotModule.prototype.solotokes = ["", "https://ourfore.st/img/femotes/onetoker.jpg","https://ourfore.st/img/femotes/solotoke.jpg","https://ourfore.st/img/femotes/1toker.gif"];
|
||||
|
||||
//main toke logic (adapted from chozobot implementation)
|
||||
TokebotModule.prototype.toke = function (user, msg, _meta){
|
||||
var name = user.getName()
|
||||
/*if(name === "Ten"){//use in case of anger
|
||||
bot.sendChatMsg(">:^(");
|
||||
return;
|
||||
}*/
|
||||
switch (this.toking){
|
||||
case 0://ready to start toke
|
||||
this.tokesay("A group toke has been started by " + name + "! We'll be taking a toke in 60 seconds - join in by posting " + msg);
|
||||
this.cdown = 3;
|
||||
this.toking = 1; this.tokers.push(name);
|
||||
setTimeout(this.countdown, 57000, this);
|
||||
break;
|
||||
case 1://taking toke
|
||||
if(this.tokers.includes(name)){
|
||||
this.tokesay(name + " You're already taking part in this toke!");
|
||||
}else{
|
||||
this.tokesay(name + " joined the toke! Post " + msg + " to take part!");
|
||||
this.tokers.push(name);
|
||||
this.cdown = 3;
|
||||
}
|
||||
break;
|
||||
case 2://cooldown
|
||||
this.tokesay(name + " Please wait " + this.ctime + " before starting a new group toke.");
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
TokebotModule.prototype.countdown = function (tb){
|
||||
tb.toking = 1;//set toking mode
|
||||
|
||||
tb.tokesay(tb.cdown + "...");//send countdown msg
|
||||
--tb.cdown;//count down
|
||||
|
||||
if(tb.cdown <= 0){//if cdown hits 0
|
||||
setTimeout(tb.endtoke, 1000, tb);
|
||||
}else{
|
||||
setTimeout(tb.countdown, 1000, tb);//call endtoke
|
||||
}
|
||||
};
|
||||
|
||||
TokebotModule.prototype.endtoke = function (tb){
|
||||
if(tb.cdown != 0){
|
||||
setTimeout(tb.countdown, 1000, tb);
|
||||
return;
|
||||
}
|
||||
if(tb.tokers.length > 1){
|
||||
let callstring = '';
|
||||
|
||||
for(let i = 0; i < tb.tokers.length - 1; i++){
|
||||
callstring += tb.tokers[i] + ', ';
|
||||
}
|
||||
|
||||
callstring += tb.tokers[tb.tokers.length - 1];
|
||||
|
||||
tb.tokesay("Take a toke " + callstring + "! " + tb.tokers.length + " tokers!");
|
||||
}else{
|
||||
tb.tokesay("Take a toke " + tb.tokers.toString() + ". " + (tb.solotokes[tb.getRandomInt(0,tb.solotokes.length)]));
|
||||
}
|
||||
tb.tokers = [];
|
||||
tb.toking = 2;//reset toking mode
|
||||
setTimeout(tb.cooldown, 1000, tb);
|
||||
};
|
||||
|
||||
TokebotModule.prototype.cooldown = function (tb){
|
||||
if(tb.ctime > 0){
|
||||
tb.toking = 2;
|
||||
--tb.ctime;
|
||||
setTimeout(tb.cooldown, 1000, tb);
|
||||
}else{
|
||||
tb.toking = 0;
|
||||
tb.ctime = tb.cdel;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//helper functions
|
||||
TokebotModule.prototype.tokesay = function (msg){
|
||||
var msgobj = {
|
||||
username: "tokebot",
|
||||
msg: msg,
|
||||
meta:{
|
||||
addClass: "shout",
|
||||
addClassToNameAndTimestamp: true,
|
||||
forceShowName: true,
|
||||
modflair: 3
|
||||
},
|
||||
time: Date.now()
|
||||
}
|
||||
|
||||
this.channel.users.forEach(function (u) {
|
||||
u.socket.emit("chatMsg",msgobj);
|
||||
});
|
||||
};
|
||||
|
||||
TokebotModule.prototype.getRandomInt = function (min, max) {
|
||||
min = Math.ceil(min);
|
||||
max = Math.floor(max);
|
||||
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
|
||||
};
|
||||
|
||||
module.exports = TokebotModule;
|
||||
Loading…
Add table
Add a link
Reference in a new issue