From f247f3b2de63fd6d3be36661178cd8cc21594efa Mon Sep 17 00:00:00 2001 From: Ecolipsy Date: Thu, 2 Dec 2021 16:49:30 +0100 Subject: [PATCH] Add Juustobotti interpretation --- index.js | 40 ++++++++++++++++++++++++++++++++++------ start.sh | 4 ++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index b21a0ac..518c318 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,24 @@ const dc = require("discord.js"); const client = new dc.Client({intents: ["GUILDS", "GUILD_MESSAGES"]}); const fs = require("fs"); +function parseCommands(){ + var cmdFiles = []; + var indexes = {} + var rootdir = fs.readdirSync("Juustobotti/commands"); + rootdir.forEach(categorydir => { + categorydir.forEach(file => { + indexes.file = categorydir; + cmdFiles.push(file); + }); + }); + var cmds = []; + cmdFiles.forEach(yes => { + var cmdObj = require("./Juustobotti/commands/" + indexes[yes] + "/yes"); + cmds.push(cmdObj); + }); + return cmds; +} + var shapes = ["rock", "paper", "scissors"]; function rps(shape){ shape = shape.toLowerCase(); @@ -135,12 +153,22 @@ client.on("interactionCreate", (int) => { const allowed = ["831598877320413244"]; client.on("messageCreate", (msg) => { - if(!msg.content.startsWith("rps!ev")) return; - if(!allowed.includes(msg.author.id)) return msg.channel.send("Nu perms!"); - try{ - msg.channel.send(new String(eval(msg.content.replace("rps!ev", ""))).valueOf()).catch(e => {msg.channel.send(e.stack)}); - } catch(e){ - msg.channel.send(e.stack).catch(e => {msg.channel.send("Well thats ironic, an error for an error message: \n" + e.stack)}); + if(msg.content.startsWith("rps!ev")){ + if(!allowed.includes(msg.author.id)) return msg.channel.send("Nu perms!"); + try{ + msg.channel.send(new String(eval(msg.content.replace("rps!ev", ""))).valueOf()).catch(e => {msg.channel.send(e.stack)}); + } catch(e){ + msg.channel.send(e.stack).catch(e => {msg.channel.send("Well thats ironic, an error for an error message: \n" + e.stack)}); + } + } else if(msg.content.startsWith("rps!ju")){ + var commands = parseCommands(); + commands.forEach(cmd => { + if(msg.content.startsWith("rps!ju " + cmd.name)){ + msg.content = msg.content.replace("rps!ju " + cmd.name, "ju!" + cmd.name); + const args = msg.content.slice("ju!".length).trim().split(/ +/); + cmd.execute(msg, args); + } + }); } }); diff --git a/start.sh b/start.sh index 14b5991..32b9b25 100755 --- a/start.sh +++ b/start.sh @@ -1,4 +1,8 @@ while [ true ] do + rm -rf Juustobotti + git clone https://github.com/Pizzakeitto/Juustobotti.git + rm Juustobotti/.git + git pull node . done