Tokebot ported to codebase.

This commit is contained in:
rainbownapkin 2022-07-20 07:22:16 +00:00
parent 1da7cab9cd
commit 2fc8f16e9d
6 changed files with 1888 additions and 2521 deletions

View file

@ -199,7 +199,11 @@ dev goals for 1.1 pineapple express:
- tokebot control menu
- merge tokebot into ourfore.st codebase, one server instead of two.
- profile and userlist entry
- port chozobot code to cytube module ✓
- CRITICAL BUG FIX: Duplicate username during callout (test toking on multiple channels, etc...)
- load toke commands from tokes file
- tokewhisper (server whisper, can optionally be displayed as PM client side)
- profile and userlist entry(togglable clientside, on by default)
- bot specific rank
- reset cooldown accessible from modmenu (quiet and loud, quiet by default)
- log tokes w/ date to file. This will be switched to mariadb in the next update

4260
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,12 @@
{
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.82.11",
"repository": {
"url": "http://github.com/calzoneman/sync"
"name": "fore.st",
"version": "1.1.0",
"description": "fore.st: A fork of cytube tailored for the TTN Community",
"main": "index.js",
"directories": {
"doc": "docs",
"lib": "lib"
},
"license": "MIT",
"dependencies": {
"@calzoneman/jsli": "^2.0.1",
"@cytube/mediaquery": "github:CyTube/mediaquery#4f803961d72a4fc7a1e09c0babaf8ea685013b1b",

View file

@ -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
View 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;

View file

@ -521,6 +521,7 @@ Callbacks = {
},
chatMsg: function(data) {
console.log(data);
addChatMessage(data);
},