diff --git a/defaultTokes.json b/defaultTokes.json new file mode 100644 index 0000000..28d51e6 --- /dev/null +++ b/defaultTokes.json @@ -0,0 +1,339 @@ +{ + "default": "toke", + "array":[ + "tokem", + "toek", + "toak", + "666", + "420", + "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", + "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", + "ballmastr", + "checkitout", + "brule", + "strangerthings", + "strange", + "silicon", + "goteamventure", + "snaildown", + "high", + "stoned", + "drunk", + "glazzballs", + "sin", + "vibe", + "frittata", + "breen", + "soup", + "robots", + "love", + "hootiehoo", + "pot", + "toe", + "feet", + "foot", + "science", + "horse", + "bagel", + "roach", + "ranch", + "weedistight", + "mattea", + "katebush", + "runningupthathill", + "running", + "morbin", + "yee", + "maidenless", + "smellyplants", + "foryourhealth", + "cromdar", + "cbd", + "yeet", + "viking", + "suck", + "vamp", + "sparkle", + "northman", + "jack", + "keanu", + "woof", + "yote", + "pizza", + "dudewhat", + "wine", + "red", + "beer", + "liquor", + "ipa", + "a", + "c", + "d", + "x", + "y", + "z", + "n", + "rat", + "smeg", + "meg", + "kegels", + "greasy", + "bullshitartist", + "spear", + "fang", + "brutal", + "dethklok", + "goodbye", + "tab", + "jfc", + "ghost", + "burger", + "toad", + "snek", + "pill", + "2count", + "doobie", + "dooby", + "yeehaw", + "debra", + "tree", + "69", + "311", + "buttstonked", + "trees", + "treez", + "plants", + "plantz", + "aliens", + "ollie", + "greatscott", + "121gigawatts", + "88mph", + "smokeweedblazeit", + "smek", + "cry", + "smook", + "justdudethings", + "oscarfever", + "007", + "kiff", + "kief", + "jeff", + "gay", + "lesbian", + "bi", + "trans", + "queer", + "meow", + "tocar", + "fumar", + "ruhroh", + "spoop", + "tok", + "fight", + "club", + "stab", + "otke", + "greatergood", + "toker", + "tokes", + "toked", + "twunk", + "twonk", + "doublerainbow", + "kava", + "kratom", + "catjam", + "fuck", + "squanch", + "snortskie", + "zoinks", + "luckoftheirish", + "comeondown", + "ihaventeventriedityet", + "warter", + "water", + "death", + "dead", + "smokeweed", + "quack", + "clurb", + "coffee", + "duck", + "cum", + "nut", + "bong", + "piss", + "smok", + "basmati", + "meds", + "vitamins", + "protein", + "toasty", + "squirt", + "drinkwater", + "chug", + "olympic", + "marihuana", + "hooray", + "flambe", + "flambé", + "tenturnyourrainsoundsoff", + "jabroni", + "lame", + "yoke", + "reefer", + "bloke", + "hailsanta", + "tonks", + "henshin", + "maryjane", + "fart", + "shart", + "jinkies", + "whatastorymark", + "ohhaimark", + "cheep", + "bat", + "bats", + "batman", + "birdgirl", + "himbo", + "t", + "o", + "k", + "e", + "b", + "popcorn", + "puppy", + "puppybowl", + "superbowl", + "super", + "bowl", + "owl", + "kitty", + "crab", + "rso", + "drugs", + "drugz", + "spacesurf", + "birdup", + "eltoke", + "thistooshallpass", + "beber", + "wrasslin", + "her", + "yikes", + "booyak", + "bust", + "bustin", + "weedeven", + "even", + "succ", + "barm", + "propane", + "dope", + "yep", + "dangit", + "bobby", + "dabs", + "mclovin", + "delaware", + "tight", + "doh", + "ass", + "dick", + "scottbaio", + "resin", + "penisman", + "punchy", + "hotto", + "geekedup", + "comedy", + "bake", + "baked", + "shweed", + "kungfu", + "dream", + "MDK", + "3ven", + "SmoothAsEggs", + "nosedive", + "rip", + "slorp" + ] +} \ No newline at end of file diff --git a/src/app/channel/commandPreprocessor.js b/src/app/channel/commandPreprocessor.js index 4330a0c..c89e2dd 100644 --- a/src/app/channel/commandPreprocessor.js +++ b/src/app/channel/commandPreprocessor.js @@ -18,6 +18,7 @@ along with this program. If not, see .*/ const validator = require('validator');//No express here, so regular validator it is! //Local Imports +const tokebot = require('./tokebot'); const permissionModel = require('../../schemas/permissionSchema'); const channelModel = require('../../schemas/channel/channelSchema'); @@ -25,7 +26,8 @@ module.exports = class commandPreprocessor{ constructor(server, chatHandler){ this.server = server; this.chatHandler = chatHandler; - this.commandProcessor = new commandProcessor(server, this, chatHandler); + this.commandProcessor = new commandProcessor(server, chatHandler); + this.tokebot = new tokebot(server, chatHandler); } async preprocess(socket, data){ @@ -71,10 +73,16 @@ module.exports = class commandPreprocessor{ if(this.rawData.msg[0] == '!'){ //if it isn't just an exclimation point, and we have a real command if(this.argumentArray != null && this.commandProcessor[this.argumentArray[0].toLowerCase()] != null){ - //disable chat - this.sendFlag = false; - //Process the command - await this.commandProcessor[this.argumentArray[0].toLowerCase()](); + //Create hash table to hold information about current command + const commandObj = { + socket: this.socket, + commandArray: this.commandArray, + argumentArray: this.argumentArray, + rawData: this.rawData + } + + //Process the command and use the return value to set the sendflag (true if command valid) + this.sendFlag = await this.commandProcessor[this.argumentArray[0].toLowerCase()](commandObj); } } } @@ -89,53 +97,69 @@ module.exports = class commandPreprocessor{ } class commandProcessor{ - constructor(server, preprocessor, chatHandler){ + constructor(server, chatHandler){ this.server = server; - this.preprocessor = preprocessor this.chatHandler = chatHandler; } //Command keywords get run through .toLowerCase(), so we should use lowercase method names for command methods - whisper(){ + whisper(commandObj){ //splice out our whisper - this.preprocessor.commandArray.splice(0,2); + commandObj.commandArray.splice(0,2); + //send it - this.chatHandler.relayChat(this.preprocessor.socket, this.preprocessor.commandArray.join(''), 'whisper'); + this.chatHandler.relayChat(commandObj.socket, commandObj.commandArray.join(''), 'whisper'); - return; + //Make sure to throw the send flag + return false; } - async announce(){ + async announce(commandObj){ //Get the current channel from the database - const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan}); + const chanDB = await channelModel.findOne({name: commandObj.socket.chan}); //Check if the user has permission, and publicly shame them if they don't (lmao) - if(!(this.preprocessor.sendFlag = !(await chanDB.permCheck(this.preprocessor.socket.user, 'announce')))){ + if(chanDB != null && await chanDB.permCheck(commandObj.socket.user, 'announce')){ //splice out our whisper - this.preprocessor.commandArray.splice(0,2); + commandObj.commandArray.splice(0,2); //send it - this.chatHandler.relayChannelAnnouncement(this.preprocessor.socket.chan, this.preprocessor.commandArray.join('')); + this.chatHandler.relayChannelAnnouncement(commandObj.socket.chan, commandObj.commandArray.join('')); + //throw send flag + return false; } + + //throw send flag + return true; } - async serverannounce(){ + async serverannounce(commandObj){ //Check if the user has permission, and publicly shame them if they don't (lmao) - if(!(this.preprocessor.sendFlag = !(await permissionModel.permCheck(this.preprocessor.socket.user, 'announce')))){ + if(await permissionModel.permCheck(commandObj.socket.user, 'announce')){ //splice out our whisper - this.preprocessor.commandArray.splice(0,2); + commandObj.commandArray.splice(0,2); //send it - this.chatHandler.relayServerAnnouncement(this.preprocessor.commandArray.join('')); + this.chatHandler.relayServerAnnouncement(commandObj.commandArray.join('')); + //throw send flag + return false; } + + //throw send flag + return true; } - async clear(){ + async clear(commandObj){ //Get the current channel from the database - const chanDB = await channelModel.findOne({name: this.preprocessor.socket.chan}); + const chanDB = await channelModel.findOne({name: commandObj.socket.chan}); //Check if the user has permission, and publicly shame them if they don't (lmao) - if(!(this.preprocessor.sendFlag = !(await chanDB.permCheck(this.preprocessor.socket.user, 'clearChat')))){ + if(await chanDB.permCheck(commandObj.socket.user, 'clearChat')){ //Send off the command - this.chatHandler.clearChat(this.preprocessor.socket.chan, this.preprocessor.argumentArray[1]); + this.chatHandler.clearChat(commandObj.socket.chan, commandObj.argumentArray[1]); + //throw send flag + return false; } + + //throw send flag + return true; } } \ No newline at end of file diff --git a/src/app/channel/tokebot.js b/src/app/channel/tokebot.js new file mode 100644 index 0000000..f03115c --- /dev/null +++ b/src/app/channel/tokebot.js @@ -0,0 +1,36 @@ +/*Canopy - The next generation of stoner streaming software +Copyright (C) 2024 Rainbownapkin and the TTN Community + +This program 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. + +This program 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 this program. If not, see .*/ + +//Local Imports +const tokeCommandModel = require('../../schemas/tokebot/tokeCommandSchema'); + + +module.exports = class tokebot{ + constructor(server, chatHandler){ + //Set parents + this.server = server; + this.chatHandler = chatHandler; + + //Load in toke commands from the DB + this.refreshCommands(); + } + + async refreshCommands(){ + //Pull Command Strings from DB + this.tokeCommands = await tokeCommandModel.getCommandStrings(); + } + +} \ No newline at end of file diff --git a/src/schemas/tokebot/tokeCommandSchema.js b/src/schemas/tokebot/tokeCommandSchema.js new file mode 100644 index 0000000..4dad7dc --- /dev/null +++ b/src/schemas/tokebot/tokeCommandSchema.js @@ -0,0 +1,77 @@ +/*Canopy - The next generation of stoner streaming software +Copyright (C) 2024 Rainbownapkin and the TTN Community + +This program 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. + +This program 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 this program. If not, see .*/ + +//NPM Imports +const {mongoose} = require('mongoose'); + +//Local Imports +const defaultTokes = require("../../../defaultTokes.json"); + +const tokeCommandSchema = new mongoose.Schema({ + command:{ + type: mongoose.SchemaTypes.String, + required: true + } +}); + +tokeCommandSchema.statics.getCommandStrings = async function(){ + //Get all toke commands in the DB + const tokeDB = await this.find({}); + //Create an empty array to hold the toke commands + var tokeArray = []; + + //for all toke commands found in the database + tokeDB.forEach((toke)=>{ + //Push the command string into the tokeArray + tokeArray.push(toke.command); + }) + + //return the toke command strings from the database + return tokeArray; +} + +tokeCommandSchema.statics.loadDefaults = async function(){ + //Make sure registerToke function is happy + const _this = this; + + //Ensure default comes first (.bind(this) doesn't seem to work here...) + await registerToke(defaultTokes.default); + //For each entry in the defaultTokes.json file + defaultTokes.array.forEach(registerToke); + + async function registerToke(toke){ + try{ + //Look for toke matching the one from our file + const foundToke = await _this.findOne({command: toke}); + + //if the toke doesn't exist + if(!foundToke){ + const tokeDB = await _this.create({command: toke}); + console.log(`Loading default toke command '!${toke}' into DB from defaultTokes.json`); + } + + }catch(err){ + if(toke != null){ + console.log(err); + console.log(`Error loading toke command: '!${toke}'`); + }else{ + console.log("Error, null toke!"); + } + } + } +} + +module.exports = mongoose.model("tokeCommand", tokeCommandSchema); \ No newline at end of file diff --git a/src/server.js b/src/server.js index 9cbaac9..ed08e97 100644 --- a/src/server.js +++ b/src/server.js @@ -28,6 +28,7 @@ const channelManager = require('./app/channel/channelManager'); const scheduler = require('./utils/scheduler'); const statModel = require('./schemas/statSchema'); const flairModel = require('./schemas/flairSchema'); +const tokeCommandModel = require('./schemas/tokebot/tokeCommandSchema'); const indexRouter = require('./routers/indexRouter'); const registerRouter = require('./routers/registerRouter'); const profileRouter = require('./routers/profileRouter'); @@ -110,9 +111,12 @@ app.use(express.static(path.join(__dirname, '../www'))); //Increment launch counter statModel.incrementLaunchCount(); -//Load flairs +//Load default flairs flairModel.loadDefaults(); +//Load default toke commands +tokeCommandModel.loadDefaults(); + //Kick off scheduled-jobs scheduler.kickoff();