From 46bcb040f26ee3f711ba0ec07052b63e2ab48e48 Mon Sep 17 00:00:00 2001 From: rainbownapkin Date: Fri, 22 Jul 2022 11:35:37 +0000 Subject: [PATCH] improved tokebot whispers/pm's, mod/admin commands added(reset cooldown, tokesay/tokeyell/tokewhisper, reloadtoke) --- src/channel/tokebot.js | 132 ++++++++++++++++++++++++++++++++++---- templates/useroptions.pug | 1 + tokebot/tokes | 83 ++++++++++++++++++++++++ www/js/callbacks.js | 9 ++- www/js/data.js | 1 + www/js/fpanel.js | 10 ++- www/js/util.js | 38 +++++++++-- 7 files changed, 252 insertions(+), 22 deletions(-) create mode 100644 tokebot/tokes diff --git a/src/channel/tokebot.js b/src/channel/tokebot.js index baf88b4e..407c6eef 100644 --- a/src/channel/tokebot.js +++ b/src/channel/tokebot.js @@ -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, +*/ +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); diff --git a/templates/useroptions.pug b/templates/useroptions.pug index 2da8f6a8..d82d85c2 100644 --- a/templates/useroptions.pug +++ b/templates/useroptions.pug @@ -86,6 +86,7 @@ mixin us-chat +rcheckbox("us-sort-rank", "Sort userlist by rank") +rcheckbox("us-sort-afk", "Sort AFKers to bottom") +rcheckbox("us-legacy-emote", "Use legacy Cytube emote menu") + +rcheckbox("us-toke-pm", "Legacy Tokebot Notifications (PM)") .form-group label.control-label.col-sm-4(for="#us-blink-title",title="Only applies when not active window/tab.") Blink page title on new messages .col-sm-8 diff --git a/tokebot/tokes b/tokebot/tokes new file mode 100644 index 00000000..815b3c7c --- /dev/null +++ b/tokebot/tokes @@ -0,0 +1,83 @@ +toak +666 +420 +toke +tokem +toek +hailsatan +cheers +toast +toastem +burn +burnem +lightem +dab +dabem +smoke +smokem +blaze +blazeit +blazem +drink +shot +weed +marijuana +cannabis +jazzcabbage +oktem +puff +hit +tjoke +tjokem +devilslettuce +tokem +toakem +grass +liftoff +420blazeit +smokeweed420blazeit +smokeweed420blazem +boof +boofem +tonk +tonkem +tonker +bonghits4jesus +tedcruzdid911 +epsteindidntkillhimself +zillatoke +ekot +mekot +smonk +smonkem +hash +kush +cheeseit +munch +munchem +vape +vapem +fire +firemup +sacrifice +710 +roast +nukem +shit +hydrate +eat +edible +justgirlythings +heyrainbowaddthis +inhale +ignite +THEPLANT +spark +sparkone +sparkem +smokeweederryday +robotoke +witness +roastem +crabpeople +shootthemoon diff --git a/www/js/callbacks.js b/www/js/callbacks.js index fd097a7c..e9f555d7 100644 --- a/www/js/callbacks.js +++ b/www/js/callbacks.js @@ -512,6 +512,7 @@ Callbacks = { /* REGION Chat */ usercount: function(count) { + count++;//add one fer tokebot :P CHANNEL.usercount = count; var text = count + " connected user"; if(count != 1) { @@ -521,6 +522,11 @@ Callbacks = { }, chatMsg: function(data) { + if(data.username === "tokebot" && data.meta.addClass === "server-whisper" && USEROPTS.toke_pm){ + data.meta = {}; + window.Callbacks.pm(data); + return; + } addChatMessage(data); }, @@ -552,8 +558,6 @@ Callbacks = { }, clearchat: function(data) { - console.log(data); - if(data.target == null){ $("#messagebuffer").html(""); }else{ @@ -573,6 +577,7 @@ Callbacks = { addUser: function(data) { CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(data, true); + console.log(data); sortUserlist(); }, diff --git a/www/js/data.js b/www/js/data.js index 522fa459..8e93724e 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -170,6 +170,7 @@ var USEROPTS = { sort_rank : getOrDefault("sort_rank", true), sort_afk : getOrDefault("sort_afk", false), legacy_emote : getOrDefault("legacy_emote", false), + toke_pm : getOrDefault("toke_pm", false), yt_source : getOrDefault("yt_source", "vid.puffyan.us"), show_seconds : getOrDefault("show_seconds", false), default_quality : getOrDefault("default_quality", "auto"), diff --git a/www/js/fpanel.js b/www/js/fpanel.js index 3b5404fe..216f89c8 100644 --- a/www/js/fpanel.js +++ b/www/js/fpanel.js @@ -341,8 +341,13 @@ fpset.ocall = function(){ processOpts(); }), ), - - + $("
").append( + $("