improved tokebot whispers/pm's, mod/admin commands added(reset cooldown,

tokesay/tokeyell/tokewhisper, reloadtoke)
This commit is contained in:
rainbownapkin 2022-07-22 11:35:37 +00:00
parent a048e2094c
commit 46bcb040f2
7 changed files with 252 additions and 22 deletions

View file

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

View file

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

83
tokebot/tokes Normal file
View file

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

View file

@ -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();
},

View file

@ -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"),

View file

@ -341,8 +341,13 @@ fpset.ocall = function(){
processOpts();
}),
),
$("<form>").append(
$("<label>").prop("for","qs-toke-pm").html("Legacy Toke Notification: "),
$("<input>").prop("id","qs-toke-pm").prop("type","checkbox").addClass("qs-form").change(function() {
USEROPTS.toke_pm = $("#qs-toke-pm").prop("checked");
processOpts();
}),
),
])
fpset.loadSettings();
}
@ -364,6 +369,7 @@ fpset.loadSettings = function(){
$("#qs-show-timestamp").prop("checked", USEROPTS.show_timestamps);
$("#qs-timestamp-second").parent().toggle(USEROPTS.show_timestamps);
$("#qs-timestamp-second").prop("checked", USEROPTS.show_seconds);
$("#qs-toke-pm").prop("checked", USEROPTS.toke_pm);
}

View file

@ -244,13 +244,15 @@ function addUserDropdown(entry) {
.appendTo(entry)
.hide();
var istokebot = (name === "tokebot");
$("<strong/>").text(name).appendTo(menu);
$("<br/>").appendTo(menu);
var btngroup = $("<div/>").addClass("btn-group-vertical").appendTo(menu);
/* give/remove leader (moderator+ only) */
if (hasPermission("leaderctl")) {
if (hasPermission("leaderctl") && !istokebot) {
var ldr = $("<button/>").addClass("btn btn-xs btn-default")
.appendTo(btngroup);
if(leader) {
@ -304,7 +306,7 @@ function addUserDropdown(entry) {
});
/* ignore button */
if (name !== CLIENT.name) {
if (name !== CLIENT.name && !istokebot) {
var ignore = $("<button/>").addClass("btn btn-xs btn-default")
.appendTo(btngroup)
.click(function () {
@ -329,7 +331,7 @@ function addUserDropdown(entry) {
}
/* mute buttons */
if (hasPermission("mute")) {
if (hasPermission("mute") && !istokebot) {
var mute = $("<button/>").addClass("btn btn-xs btn-default")
.text("Mute")
.click(function () {
@ -366,7 +368,7 @@ function addUserDropdown(entry) {
}
/* kick button */
if(hasPermission("kick")) {
if(hasPermission("kick") && !istokebot) {
$("<button/>").addClass("btn btn-xs btn-default")
.text("Kick")
.click(function () {
@ -383,7 +385,7 @@ function addUserDropdown(entry) {
}
/* ban buttons */
if(hasPermission("ban")) {
if(hasPermission("ban") && !istokebot) {
$("<button/>").addClass("btn btn-xs btn-default")
.text("Name Ban")
.click(function () {
@ -477,6 +479,30 @@ function calcUserBreakdown() {
function sortUserlist() {
var slice = Array.prototype.slice;
var list = slice.call($("#userlist .userlist_item"));
if(//check if tokebot listing is present
list.filter(function(u,i){
return($(u).children()[1].innerHTML === "tokebot");
}).length <= 0
){//inject tokebot userlist entry
CyTube._internal_do_not_use_or_you_will_be_banned.addUserToList(
{
name: "tokebot",
rank: 3,
profile: {
test: "!TOKE OR DIE!",
image: window.location.origin + "/img/femotes/tokebot.jpg"
},
meta: {
afk: false,
aliases: [],
ip: "127.0.0.1",
muted: false,
smuted: false
}
}
);
var list = slice.call($("#userlist .userlist_item"));//pull list again, make sure tokebot gets sorted
}
list.sort(function (a, b) {
var r1 = $(a).data("rank");
var r2 = $(b).data("rank");
@ -721,6 +747,7 @@ function showUserOptions() {
$("#us-sort-rank").prop("checked", USEROPTS.sort_rank);
$("#us-sort-afk").prop("checked", USEROPTS.sort_afk);
$("#us-legacy-emote").prop("checked", USEROPTS.legacy_emote);
$("#us-toke-pm").prop("checked", USEROPTS.toke_pm);
$("#us-blink-title").val(USEROPTS.blink_title);
$("#us-ping-sound").val(USEROPTS.boop);
$("#us-notifications").val(USEROPTS.notifications);
@ -762,6 +789,7 @@ function saveUserOptions() {
USEROPTS.sort_rank = $("#us-sort-rank").prop("checked");
USEROPTS.sort_afk = $("#us-sort-afk").prop("checked");
USEROPTS.legacy_emote = $("#us-legacy-emote").prop("checked");
USEROPTS.toke_pm = $("#us-toke-pm").prop("checked");
USEROPTS.blink_title = $("#us-blink-title").val();
USEROPTS.boop = $("#us-ping-sound").val();
USEROPTS.notifications = $("#us-notifications").val();