From 34115f41cf3f6fd40511b15066e4f436b9c40741 Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 16:06:32 +0100 Subject: [PATCH 1/8] update README to mention shebang --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a69a449..67806c5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Node.JS: 14 npm: 6.14 # Let's get this ~~party~~ bot started! For first time start up, You will need to run ``npm install`` to install the needed npm packages. -Afterwards fill out the ``config-example.json`` and rename it to ``config.json``, then just run ``node start.js``! +Afterwards fill out the ``config-example.json`` and rename it to ``config.json``, then just run ``node start.js`` (or ``./start.js`` on Linux)! ⚠️ If you don't specify the Owner ID, Some commands such as the bot controls will be unusable! # Support Anitrox isn't really supported but you can get help from the Discord server if you need any: discord.gg/5nQtMNpf43 From 3fd6a893dd1f9adb383f1268730da9e2b7a2fb2f Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 16:13:06 +0100 Subject: [PATCH 2/8] Fix string splitting regex to split on any whitespace --- start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.js b/start.js index 9dfde1a..6e59e37 100755 --- a/start.js +++ b/start.js @@ -55,7 +55,7 @@ client.on('message', async (message) => { if (!message.content.startsWith(config.prefix) || message.author.bot) return; - const args = message.content.slice(config.prefix.length).split(/ +/); + const args = message.content.slice(config.prefix.length).split(/\s+/); const command = args.shift().toLowerCase(); if (!client.commands.has(command)) return; From db5c9f4f551dc5706a35f8adbaaded0eb964a96e Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 17:03:01 +0100 Subject: [PATCH 3/8] Update indentation --- start.js | 60 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/start.js b/start.js index 6e59e37..483f924 100755 --- a/start.js +++ b/start.js @@ -32,48 +32,48 @@ client.generateErrorMessage = (errorMsg, messageAuthorURL) => ({embed: { client.on("error", (e) => console.log(`[ERROR] ${error(e)}`)); client.on("warn", (e) => (`[WARN] ${warn(e)}`)); client.once('ready', () => { - console.clear() - console.log(' ___ _ __ '); - console.log(' / | ____ (_) /__________ _ __'); - console.log(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/'); - console.log(' / ___ |/ / / / / /_/ / / /_/ /> < '); - console.log('/_/ |_/_/ /_/_/\\__/_/ \\____/_/|_| '); - console.log(`${config.release}, ${config.build}`); - console.log("Bot online. | Anitrox by IDeletedSystem64 | ALL MY CODE KEEPS BLOWING UP!"); - // Statuses - setInterval(async () => { - // Picks a status from the config file - const index = Math.floor(Math.random() * config.statuses.length); - await client.user.setActivity(config.statuses[index]); - }, 20000); - + console.clear() + console.log(' ___ _ __ '); + console.log(' / | ____ (_) /__________ _ __'); + console.log(' / /| | / __ \\/ / __/ ___/ __ \\| |/_/'); + console.log(' / ___ |/ / / / / /_/ / / /_/ /> < '); + console.log('/_/ |_/_/ /_/_/\\__/_/ \\____/_/|_| '); + console.log(`${config.release}, ${config.build}`); + console.log("Bot online. | Anitrox by IDeletedSystem64 | ALL MY CODE KEEPS BLOWING UP!"); + // Statuses + setInterval(async () => { + // Picks a status from the config file + const index = Math.floor(Math.random() * config.statuses.length); + await client.user.setActivity(config.statuses[index]); + }, 20000); + }); // Begin Command Handler client.on('message', async (message) => { - if (!message.content.startsWith(config.prefix) || message.author.bot) return; + if (!message.content.startsWith(config.prefix) || message.author.bot) return; - const args = message.content.slice(config.prefix.length).split(/\s+/); - const command = args.shift().toLowerCase(); - - if (!client.commands.has(command)) return; + const args = message.content.slice(config.prefix.length).split(/\s+/); + const command = args.shift().toLowerCase(); + + if (!client.commands.has(command)) return; - try { - await client.commands.get(command).execute(client, message, args, config); - } catch (error) { - console.stack; - message.channel.send({embed: { - "title": "<:AnitroxError:809651936563429416> **Something went wrong!**", - "description": error.stack, - "color": 13632027, + try { + await client.commands.get(command).execute(client, message, args, config); + } catch (error) { + console.stack; + message.channel.send({embed: { + "title": "<:AnitroxError:809651936563429416> **Something went wrong!**", + "description": error.stack, + "color": 13632027, "footer": { "icon_url": message.author.displayAvatarURL(), "text": config.footerTxt }, - }}); - } + }}); + } }); client.login(config.token); \ No newline at end of file From fc0235a1ce5f6404d368ac1b9142d3f7357c955b Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 17:06:24 +0100 Subject: [PATCH 4/8] Update parameter names --- commands/eval.js | 2 +- commands/restart.js | 2 +- commands/stop.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/eval.js b/commands/eval.js index cad5859..1b0983c 100644 --- a/commands/eval.js +++ b/commands/eval.js @@ -3,7 +3,7 @@ module.exports = { name: 'eval', description: 'Executes JS code', - async execute(client, message, args, config) { + async execute(_, message, args, config) { if (message.author.id == config.ownerID) { try { const code = args.join(" "); diff --git a/commands/restart.js b/commands/restart.js index 2c78ca6..fafd9e2 100644 --- a/commands/restart.js +++ b/commands/restart.js @@ -1,7 +1,7 @@ module.exports = { name: 'restart', description: 'Restarts the bot', - async execute(client, message, args, config) { + async execute(client, message, _, config) { if (message.author.id == config.ownerID) { console.log("Anitrox is restarting now!") await message.channel.send(" Restarting...") diff --git a/commands/stop.js b/commands/stop.js index f47c4cb..2631741 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -1,7 +1,7 @@ module.exports = { name: "stop", description: "IT'S TIME TO STOP!... the bot", - async execute(_, message, args, config) { + async execute(_0, message, _1, config) { if (message.author.id == config.ownerID) { await message.channel.send({embed: { "title": " **Shutting Down...**", From 0de44087978146df67ffbeab83bdadead6a18eb3 Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 17:06:53 +0100 Subject: [PATCH 5/8] add choose command --- commands/choose.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 commands/choose.js diff --git a/commands/choose.js b/commands/choose.js new file mode 100644 index 0000000..5e5f953 --- /dev/null +++ b/commands/choose.js @@ -0,0 +1,23 @@ +module.exports = { + name: 'choose', + description: "Give some lines of input, and get one back at random", + async execute(client, message, _, config) { + var strarr = message.content.split(/\s*\n\s*/); + strarr[0] = strarr[0].slice(this.name.length + config.prefix.length); + console.log(strarr); + const answer = strarr[Math.floor(Math.random() * strarr.length)]; + if (answer === "") { + await message.channel.send(client.generateErrorMessage("You need to provide some input!", message.author.displayAvatarURL())); + } else { + await message.channel.send({embed: { + "title": "I have made my decision:", + "description": answer, + "color": 8311585, + "footer": { + "icon_url": message.author.displayAvatarURL(), + "text": config.footerTxt + }, + }}); + } + } +} From 74066f666e481d78e3ae6670f65867afd7ee3091 Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 17:25:40 +0100 Subject: [PATCH 6/8] Modules take names from the name of their file --- commands/8ball.js | 4 +++- commands/avatar.js | 8 ++++---- commands/bonk.js | 5 +++-- commands/cheese.js | 5 ++++- commands/choose.js | 6 ++++-- commands/cuddle.js | 4 ++-- commands/eval.js | 4 +++- commands/help.js | 2 +- commands/hug.js | 3 ++- commands/info.js | 37 +++++++++++++++++++------------------ commands/invite.js | 3 ++- commands/kiss.js | 2 +- commands/leskiss.js | 2 +- commands/lick.js | 2 +- commands/nom.js | 2 +- commands/opensource.js | 6 ++++-- commands/pat.js | 3 ++- commands/ping.js | 4 +++- commands/poke.js | 3 ++- commands/reload.js | 4 +++- commands/restart.js | 4 +++- commands/setnick.js | 6 +++--- commands/slap.js | 3 ++- commands/snuggle.js | 3 ++- commands/stop.js | 4 +++- commands/uinfo.js | 5 ++++- 26 files changed, 82 insertions(+), 52 deletions(-) diff --git a/commands/8ball.js b/commands/8ball.js index cd58d94..2748458 100644 --- a/commands/8ball.js +++ b/commands/8ball.js @@ -1,7 +1,9 @@ module.exports = { - name: '8ball', + + name: require('path').parse(__filename).name, description: 'Ask Anitrox a question, any question! and they will answer it!', syntax: ["[Question]"], + async execute(client, message, args, config) { const index = Math.floor(Math.random() * config.answers.length); const answer = config.answers[index] diff --git a/commands/avatar.js b/commands/avatar.js index 356265b..615ce63 100644 --- a/commands/avatar.js +++ b/commands/avatar.js @@ -1,11 +1,11 @@ module.exports = { - name: "avatar", + name: require('path').parse(__filename).name, description: "Gets a user's avatar.", - async execute(client, message, args, config) { - - const user = message.mentions.users.first() || client.users.cache.get(args[0]) || message.author; + async execute(client, message, args, config) { + const user = message.mentions.users.first() || client.users.cache.get(args[0]) || message.author; + await message.channel.send({embed: { "title": `:frame_photo: ${user.username}'s Beautiful Avatar!`, "color": 9442302, diff --git a/commands/bonk.js b/commands/bonk.js index d4d984c..87dc359 100644 --- a/commands/bonk.js +++ b/commands/bonk.js @@ -1,7 +1,8 @@ module.exports = { - - name: "bonk", + + name: require('path').parse(__filename).name, description: "Bonks a user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/cheese.js b/commands/cheese.js index 88516d2..c3b2f59 100644 --- a/commands/cheese.js +++ b/commands/cheese.js @@ -1,8 +1,11 @@ module.exports = { - name: "cheese", + + name: require('path').parse(__filename).name, description: "Cheese an user, or run just ``n!cheese`` for a surprise :eyes:", + async execute(_0, message, _1, config) { const taggedUser = message.mentions.users.first(); + if(!taggedUser) { await message.channel.send("*slams cheese on desk*\n**Cheese.** https://www.youtube.com/watch?v=Or4IE8fkpn4"); } else { diff --git a/commands/choose.js b/commands/choose.js index 5e5f953..178ff5d 100644 --- a/commands/choose.js +++ b/commands/choose.js @@ -1,11 +1,13 @@ module.exports = { - name: 'choose', + + name: require('path').parse(__filename).name, description: "Give some lines of input, and get one back at random", + async execute(client, message, _, config) { var strarr = message.content.split(/\s*\n\s*/); strarr[0] = strarr[0].slice(this.name.length + config.prefix.length); - console.log(strarr); const answer = strarr[Math.floor(Math.random() * strarr.length)]; + if (answer === "") { await message.channel.send(client.generateErrorMessage("You need to provide some input!", message.author.displayAvatarURL())); } else { diff --git a/commands/cuddle.js b/commands/cuddle.js index d14cb10..5825a73 100644 --- a/commands/cuddle.js +++ b/commands/cuddle.js @@ -7,10 +7,10 @@ const gifchoices = [ module.exports = { - name: "cuddle", + name: require('path').parse(__filename).name, description: "Cuddle an user!", - async execute(client, message, _, config) { + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); const index = Math.floor(Math.random() * gifchoices.length); const gif = (gifchoices[index]); diff --git a/commands/eval.js b/commands/eval.js index 1b0983c..86b0f18 100644 --- a/commands/eval.js +++ b/commands/eval.js @@ -1,8 +1,10 @@ const { inspect } = require("util"); + module.exports = { - name: 'eval', + name: require('path').parse(__filename).name, description: 'Executes JS code', + async execute(_, message, args, config) { if (message.author.id == config.ownerID) { try { diff --git a/commands/help.js b/commands/help.js index 940501b..e2bd143 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,6 +1,6 @@ module.exports = { - name: 'help', + name: require('path').parse(__filename).name, description: 'Get help on anything from commands, to what the bot does! just not your homework..', syntax: '', diff --git a/commands/hug.js b/commands/hug.js index a4ddf72..c294752 100644 --- a/commands/hug.js +++ b/commands/hug.js @@ -8,8 +8,9 @@ const gifchoices = [ module.exports = { - name: "hug", + name: require('path').parse(__filename).name, description: "Hugs a user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/info.js b/commands/info.js index bd8a39b..41ce529 100644 --- a/commands/info.js +++ b/commands/info.js @@ -1,28 +1,29 @@ +function Uptime(uptime) { + const totalSeconds = (uptime / 1000); + + const days = parseInt(totalSeconds / 86400); + const hours = parseInt((totalSeconds % 86400) / 3600); + const minutes = parseInt((totalSeconds % 3600) / 60); + const seconds = parseInt(totalSeconds % 60); + + const daystring = days + (days === 1 ? " day" : " days"); + const hourstring = hours + (hours === 1 ? " hour" : " hours"); + const minutetring = minutes + (minutes === 1 ? " minute" : " minutes"); + const secondstring = seconds + (seconds === 1 ? " second" : " seconds"); + + return `${daystring}**, **${hourstring}**, **${minutetring}**, **${secondstring}`; +} + module.exports = { - name: 'info', + name: require('path').parse(__filename).name, description: 'Shows bot and host information', + async execute(client, message, _, config) { - - function Uptime(uptime) { - const totalSeconds = (uptime / 1000); - - const days = parseInt(totalSeconds / 86400); - const hours = parseInt((totalSeconds % 86400) / 3600); - const minutes = parseInt((totalSeconds % 3600) / 60); - const seconds = parseInt(totalSeconds % 60); - - const daystring = days + (days === 1 ? " day" : " days"); - const hourstring = hours + (hours === 1 ? " hour" : " hours"); - const minutetring = minutes + (minutes === 1 ? " minute" : " minutes"); - const secondstring = seconds + (seconds === 1 ? " second" : " seconds"); - - return `${daystring}**, **${hourstring}**, **${minutetring}**, **${secondstring}`; - } - const os = require("os"); const osu = require('node-os-utils'); const cpu = osu.cpu; + await message.channel.send({embed: { "title": "<:AnitroxInfo:809651936831733791> Information about Anitrox", "description": "Everything you've ever wanted to know about your favorite bot, Anitrox!", diff --git a/commands/invite.js b/commands/invite.js index 873e385..a17a2c8 100644 --- a/commands/invite.js +++ b/commands/invite.js @@ -1,8 +1,9 @@ module.exports = { - name: 'invite', + name: require('path').parse(__filename).name, description: 'Add Anitrox to your beautiful server!', syntax: [], + async execute(_0, message, _1, config) { await message.channel.send({embed: { "title": "Add Anitrox to your Server!", diff --git a/commands/kiss.js b/commands/kiss.js index 6b51e9a..f37ff13 100644 --- a/commands/kiss.js +++ b/commands/kiss.js @@ -8,7 +8,7 @@ const gifchoices = [ module.exports = { - name: "kiss", + name: require('path').parse(__filename).name, description: "Kisses a user!", async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/leskiss.js b/commands/leskiss.js index 18242c4..69c60db 100644 --- a/commands/leskiss.js +++ b/commands/leskiss.js @@ -18,7 +18,7 @@ const gifchoices = [ module.exports = { - name: "leskiss", + name: require('path').parse(__filename).name, description: "Lesbian kiss <:lesbian:803831629428686849>", async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/lick.js b/commands/lick.js index f3573ac..fd762be 100644 --- a/commands/lick.js +++ b/commands/lick.js @@ -7,7 +7,7 @@ const gifchoices = [ module.exports = { - name: "lick", + name: require('path').parse(__filename).name, description: "Licks a user!", async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/nom.js b/commands/nom.js index 1ace929..e3b9e7b 100644 --- a/commands/nom.js +++ b/commands/nom.js @@ -7,7 +7,7 @@ const gifchoices = [ module.exports = { - name: "nom", + name: require('path').parse(__filename).name, description: "Noms an user!", async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/opensource.js b/commands/opensource.js index 762a6c1..3b9dc16 100644 --- a/commands/opensource.js +++ b/commands/opensource.js @@ -1,6 +1,8 @@ module.exports = { - name: 'opensource', - description: 'Attributions to open source components used by Anitrox', + + name: require('path').parse(__filename).name, + description: 'Attributions to open source components used by Anitrox', + async execute(_0, message, _1, config){ await message.channel.send({embed: { "title": "Component Attribution", diff --git a/commands/pat.js b/commands/pat.js index 1d818a0..27a7db1 100644 --- a/commands/pat.js +++ b/commands/pat.js @@ -6,8 +6,9 @@ const gifchoices = [ module.exports = { - name: "pat", + name: require('path').parse(__filename).name, description: "Pats a user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/ping.js b/commands/ping.js index 77f9544..df10b93 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -1,6 +1,8 @@ module.exports = { - name: "ping", + + name: require('path').parse(__filename).name, description: "Gets bot ping", + async execute(client, message, _, config) { const index = Math.floor(Math.random() * config.locations.length); const location = config.locations[index] diff --git a/commands/poke.js b/commands/poke.js index 46584ba..346ab47 100644 --- a/commands/poke.js +++ b/commands/poke.js @@ -6,8 +6,9 @@ const gifchoices = [ module.exports = { - name: "poke", + name: require('path').parse(__filename).name, description: "Pokes a user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/reload.js b/commands/reload.js index 84de5cd..05f048d 100644 --- a/commands/reload.js +++ b/commands/reload.js @@ -1,6 +1,8 @@ module.exports = { - name: 'reload', + + name: require('path').parse(__filename).name, description: 'Reloads a command', + async execute(client, message, args, config) { if (message.author.id = config.ownerID) { if (!args.length) { diff --git a/commands/restart.js b/commands/restart.js index fafd9e2..d048849 100644 --- a/commands/restart.js +++ b/commands/restart.js @@ -1,6 +1,8 @@ module.exports = { - name: 'restart', + + name: require('path').parse(__filename).name, description: 'Restarts the bot', + async execute(client, message, _, config) { if (message.author.id == config.ownerID) { console.log("Anitrox is restarting now!") diff --git a/commands/setnick.js b/commands/setnick.js index 3569904..a097ed1 100644 --- a/commands/setnick.js +++ b/commands/setnick.js @@ -1,11 +1,11 @@ module.exports = { - name: 'setnick', + + name: require('path').parse(__filename).name, description: 'Sets your nickname', + async execute(client, message, args, config) { - if (message.channel.permissionsFor(message.author).has("CHANGE_NICKNAME")) { const newnick = args.slice(0).join(" ") - try { await message.member.setNickname(newnick, "Nickname change requested by the server member. If you don't want users to be able to change their nickname disable 'CHANGE_NICKNAME' via Change Nickname in Roles.") await message.channel.send({embed: { diff --git a/commands/slap.js b/commands/slap.js index 8e1d41b..f390d06 100644 --- a/commands/slap.js +++ b/commands/slap.js @@ -1,7 +1,8 @@ module.exports = { - name: "slap", + name: require('path').parse(__filename).name, description: "Slaps an user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/snuggle.js b/commands/snuggle.js index cda8b8a..e94afb9 100644 --- a/commands/snuggle.js +++ b/commands/snuggle.js @@ -7,8 +7,9 @@ const gifchoices = [ module.exports = { - name: "snuggle", + name: require('path').parse(__filename).name, description: "Snuggle an user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/stop.js b/commands/stop.js index 2631741..9e11f13 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -1,6 +1,8 @@ module.exports = { - name: "stop", + + name: require('path').parse(__filename).name, description: "IT'S TIME TO STOP!... the bot", + async execute(_0, message, _1, config) { if (message.author.id == config.ownerID) { await message.channel.send({embed: { diff --git a/commands/uinfo.js b/commands/uinfo.js index f7427a0..aa20282 100644 --- a/commands/uinfo.js +++ b/commands/uinfo.js @@ -1,9 +1,12 @@ module.exports = { - name: "uinfo", + + name: require('path').parse(__filename).name, description: "Gets info about an user, such as ID, Discord Join date and more", syntax: "", + async execute(client, message, args, config) { const user = message.mentions.users.first() || client.users.cache.get(args[0]) || message.author + await message.channel.send({embed: { "title": `Everything you've ever wanted to know about ${user.username}!`, "color": 9442302, From 22821dbd55dccf2d8bd4ce2b0c2488f918c18804 Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 17:30:12 +0100 Subject: [PATCH 7/8] More uniform spacing --- commands/kiss.js | 1 + commands/leskiss.js | 1 + commands/lick.js | 1 + commands/nom.js | 1 + 4 files changed, 4 insertions(+) diff --git a/commands/kiss.js b/commands/kiss.js index f37ff13..921deb8 100644 --- a/commands/kiss.js +++ b/commands/kiss.js @@ -10,6 +10,7 @@ module.exports = { name: require('path').parse(__filename).name, description: "Kisses a user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/leskiss.js b/commands/leskiss.js index 69c60db..85b3d79 100644 --- a/commands/leskiss.js +++ b/commands/leskiss.js @@ -20,6 +20,7 @@ module.exports = { name: require('path').parse(__filename).name, description: "Lesbian kiss <:lesbian:803831629428686849>", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/lick.js b/commands/lick.js index fd762be..92e3ec8 100644 --- a/commands/lick.js +++ b/commands/lick.js @@ -9,6 +9,7 @@ module.exports = { name: require('path').parse(__filename).name, description: "Licks a user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); diff --git a/commands/nom.js b/commands/nom.js index e3b9e7b..314dce4 100644 --- a/commands/nom.js +++ b/commands/nom.js @@ -9,6 +9,7 @@ module.exports = { name: require('path').parse(__filename).name, description: "Noms an user!", + async execute(client, message, _, config) { const taggedUser = message.mentions.users.first(); From 05ed4d9c5c3ad6d81c91c41cec096470d34c9c35 Mon Sep 17 00:00:00 2001 From: Nathaniel Mason Date: Mon, 18 Apr 2022 18:00:56 +0100 Subject: [PATCH 8/8] fix choose to optionally work with first line --- commands/choose.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/commands/choose.js b/commands/choose.js index 178ff5d..99e3aaf 100644 --- a/commands/choose.js +++ b/commands/choose.js @@ -4,13 +4,14 @@ module.exports = { description: "Give some lines of input, and get one back at random", async execute(client, message, _, config) { - var strarr = message.content.split(/\s*\n\s*/); - strarr[0] = strarr[0].slice(this.name.length + config.prefix.length); - const answer = strarr[Math.floor(Math.random() * strarr.length)]; - - if (answer === "") { + var [head, ...options] = message.content.split(/\s*\n\s*/); + head = head.slice(this.name.length + config.prefix.length); + if (head) options.push(head); + + if (!options.length) { await message.channel.send(client.generateErrorMessage("You need to provide some input!", message.author.displayAvatarURL())); } else { + const answer = options[Math.floor(Math.random() * options.length)]; await message.channel.send({embed: { "title": "I have made my decision:", "description": answer,