improved tokebot whispers/pm's, mod/admin commands added(reset cooldown,
tokesay/tokeyell/tokewhisper, reloadtoke)
This commit is contained in:
parent
a048e2094c
commit
46bcb040f2
7 changed files with 252 additions and 22 deletions
|
|
@ -1,19 +1,54 @@
|
|||
/*
|
||||
fore.st is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
fore.st is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with fore.st. If not, see < http://www.gnu.org/licenses/ >.
|
||||
(C) 2022- by rainbownapkin, <ourforest@420blaze.it>
|
||||
*/
|
||||
import fs from 'fs';
|
||||
|
||||
var ChannelModule = require("./module");
|
||||
|
||||
|
||||
function loadTokes(){
|
||||
const rawContents = fs.readFileSync("tokebot/tokes").toString('utf8');
|
||||
var spcReg = /^\s*$/g;
|
||||
var t = rawContents.split("\n").filter(function(i){
|
||||
return !spcReg.test(i);
|
||||
});
|
||||
return t;
|
||||
}
|
||||
|
||||
var tokes = loadTokes();
|
||||
|
||||
function TokebotModule(_channel){
|
||||
ChannelModule.apply(this, arguments);
|
||||
|
||||
if(this.channel.modules.chat){
|
||||
this.channel.modules.chat.registerCommand("!toke", this.toke.bind(this));
|
||||
}
|
||||
|
||||
//mod command registration
|
||||
this.channel.modules.chat.registerCommand("!resettoke", this.resettoke.bind(this));
|
||||
|
||||
//admin command registration
|
||||
this.channel.modules.chat.registerCommand("!updatetokes", this.updatetokesCmd.bind(this));
|
||||
this.channel.modules.chat.registerCommand("!tokesay", this.tokesayCmd.bind(this));
|
||||
this.channel.modules.chat.registerCommand("!tokeannounce", this.tokeyellCmd.bind(this));
|
||||
this.channel.modules.chat.registerCommand("!tokeyell", this.tokeyellCmd.bind(this));
|
||||
this.channel.modules.chat.registerCommand("!tokewhisper", this.tokewhisperCmd.bind(this));
|
||||
|
||||
//!toke command registration
|
||||
this.updatetokes();
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
@ -21,6 +56,48 @@ 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"];
|
||||
|
||||
//mod commands
|
||||
TokebotModule.prototype.resettoke = function(user, msg, _meta){
|
||||
if(user.account.effectiveRank >= 2 && this.toking == 2){
|
||||
//this.toking = 0;
|
||||
this.ctime = 0;
|
||||
this.tokewhisper("!toke cooldown reset.", user.account.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//siteowner commands
|
||||
TokebotModule.prototype.updatetokesCmd = function(user, msg, _meta){
|
||||
if(user.account.effectiveRank >= 256){
|
||||
this.updatetokes();
|
||||
this.tokewhisper("Reloading !toke commands...", user.account.name);
|
||||
}
|
||||
}
|
||||
|
||||
TokebotModule.prototype.tokesayCmd = function(user, msg, _meta){
|
||||
if(user.account.effectiveRank >= 256){
|
||||
var fmsg = msg.split(" ");
|
||||
fmsg.shift();
|
||||
this.tokesay(fmsg.join(' '), true);
|
||||
}
|
||||
}
|
||||
|
||||
TokebotModule.prototype.tokeyellCmd = function(user, msg, _meta){
|
||||
if(user.account.effectiveRank >= 256){
|
||||
var fmsg = msg.split(" ");
|
||||
fmsg.shift();
|
||||
this.tokesay(fmsg.join(' '), false);
|
||||
}
|
||||
}
|
||||
|
||||
TokebotModule.prototype.tokewhisperCmd = function(user, msg, _meta){
|
||||
if(user.account.effectiveRank >= 256){
|
||||
var fmsg = msg.split(" ");
|
||||
fmsg.shift();
|
||||
this.tokewhisper(fmsg.join(' '));
|
||||
}
|
||||
}
|
||||
|
||||
//main toke logic (adapted from chozobot implementation)
|
||||
TokebotModule.prototype.toke = function (user, msg, _meta){
|
||||
var name = user.getName()
|
||||
|
|
@ -37,15 +114,15 @@ TokebotModule.prototype.toke = function (user, msg, _meta){
|
|||
break;
|
||||
case 1://taking toke
|
||||
if(this.tokers.includes(name)){
|
||||
this.tokesay(name + " You're already taking part in this toke!");
|
||||
this.tokewhisper(" You're already taking part in this toke!", name);
|
||||
}else{
|
||||
this.tokesay(name + " joined the toke! Post " + msg + " to take part!");
|
||||
this.tokesay("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.");
|
||||
this.tokewhisper(" Please wait " + this.ctime + " seconds before starting a new group toke.", name);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
|
@ -99,13 +176,29 @@ TokebotModule.prototype.cooldown = function (tb){
|
|||
|
||||
};
|
||||
|
||||
//helper functions
|
||||
TokebotModule.prototype.tokesay = function (msg){
|
||||
//helper functions(mostly just syntactic sugar)
|
||||
TokebotModule.prototype.updatetokes = function (){
|
||||
tokes = loadTokes();
|
||||
|
||||
if(this.channel.modules.chat){//register !toke commands
|
||||
if(tokes == null){//if for some reason tokes file couldnt be loaded
|
||||
this.channel.modules.chat.registerCommand("!toke", this.toke.bind(this));
|
||||
console.log("[tokebot] Unable to load toke commands from ./tokebot/tokes, defaulting to !toke definition");
|
||||
}else{//if we we're able to pull toke commands
|
||||
var _this = this;//we need to use this, might put this up higher to replace the tb parameter in other member functions
|
||||
tokes.forEach(function(tokec){
|
||||
_this.channel.modules.chat.registerCommand("!" + tokec, _this.toke.bind(_this));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TokebotModule.prototype.tokesay = function (msg,quiet){
|
||||
var msgobj = {
|
||||
username: "tokebot",
|
||||
msg: msg,
|
||||
meta:{
|
||||
addClass: "shout",
|
||||
addClass: (quiet ? null : "shout"),
|
||||
addClassToNameAndTimestamp: true,
|
||||
forceShowName: true,
|
||||
modflair: 3
|
||||
|
|
@ -118,6 +211,19 @@ TokebotModule.prototype.tokesay = function (msg){
|
|||
});
|
||||
};
|
||||
|
||||
TokebotModule.prototype.tokewhisper = function (msg, usr){//(msg, username)
|
||||
if(this.channel.modules.chat != null){
|
||||
if(usr != null){
|
||||
this.channel.modules.chat.sendModMessage(msg,-1,"tokebot",usr);
|
||||
}else{
|
||||
var _this = this
|
||||
this.channel.users.forEach(function(u){
|
||||
_this.channel.modules.chat.sendModMessage(msg,-1,"tokebot",u.account.name);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TokebotModule.prototype.getRandomInt = function (min, max) {
|
||||
min = Math.ceil(min);
|
||||
max = Math.floor(max);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue