From 8c691e0b9d306dd0cdfe2ec9b5bbe96c01fcce96 Mon Sep 17 00:00:00 2001 From: Brandon Russell Date: Sat, 30 Jan 2016 15:15:19 -0600 Subject: [PATCH] clean some things up --- BrussellBot.js | 39 +++++++++++++++++---------------------- README.md | 4 +--- bot/commands.js | 26 +++++++++++++------------- bot/games.json | 2 +- bot/mod.js | 7 +++---- 5 files changed, 35 insertions(+), 43 deletions(-) diff --git a/BrussellBot.js b/BrussellBot.js index 51e6f02..5061f8d 100644 --- a/BrussellBot.js +++ b/BrussellBot.js @@ -25,7 +25,6 @@ bot.on("debug", function(m) { if (config.debug) { console.log(colors.cDebug(" DE bot.on("ready", function() { bot.setPlayingGame(games[Math.floor(Math.random() * (games.length))]); //set game to a random game from games.json - //bot.setPlayingGame("]help [command]"); console.log(colors.cGreen("BrussellBot is ready!") + " Listening to " + bot.channels.length + " channels on " + bot.servers.length + " servers"); versioncheck.checkForUpdate(function(resp) { if (resp !== null) { console.log(resp); } @@ -71,7 +70,7 @@ bot.on("message", function(msg) { var leTime = new Date(lastExecTime[cmd][id]); leTime.setSeconds(leTime.getSeconds() + commands[cmd].cooldown); if (cTime < leTime) { //if it is still on cooldown - var left = (leTime - cTime) / 1000; + var left = (leTime.valueOf() - cTime.valueOf()) / 1000; if (msg.author.id != config.admin_id) { //admin bypass bot.sendMessage(msg, msg.author.username + ", you can't use this command for " + Math.round(left) + " more seconds", function(erro, message) { bot.deleteMessage(message, {"wait": 6000}); }); return; @@ -100,7 +99,7 @@ bot.on("message", function(msg) { var leTime = new Date(lastExecTime[cmd][id]); leTime.setSeconds(leTime.getSeconds() + mod[cmd].cooldown); if (cTime < leTime) { //if it is still on cooldown - var left = (leTime - cTime) / 1000; + var left = (leTime.valueOf() - cTime.valueOf()) / 1000; if (msg.author.id != config.admin_id) { //admin bypass bot.sendMessage(msg, msg.author.username + ", you can't use this command for " + Math.round(left) + " more seconds", function(erro, message) { bot.deleteMessage(message, {"wait": 6000}); }); return; @@ -199,7 +198,7 @@ function carbonInvite(msg) { console.log(colors.cWarn(" WARN ") + err); } else if (!server || server.name == undefined || server.roles == undefined || server.channels == undefined || server.members == undefined) { //this problem is a pain in the ass console.log(colors.cWarn(" WARN ") + "Error joining server. Didn't receive all data."); - bot.sendMessage(msg, "Failed to receive all data, please try again in a few seconds."); + bot.sendMessage(msg, "Failed to receive all data, please try again."); try { bot.leaveServer(server); } catch (error) { /*how did it get here?*/ } @@ -211,29 +210,24 @@ function carbonInvite(msg) { if (process.env.banned_server_ids && process.env.banned_server_ids.indexOf(server.id) > -1) { console.log(colors.cRed("Joined server but it was on the ban list") + ": " + server.name); bot.sendMessage(msg, "This server is on the ban list"); - bot.leaveServer(server); - return; + bot.leaveServer(server); return; } } else { if (config.banned_server_ids && config.banned_server_ids.indexOf(server.id) > -1) { console.log(colors.cRed("Joined server but it was on the ban list") + ": " + server.name); bot.sendMessage(msg, "This server is on the ban list"); - bot.leaveServer(server); - return; + bot.leaveServer(server); return; } } console.log(colors.cGreen("Joined server: ") + " " + server.name); bot.sendMessage(msg, "Successfully joined " + server.name); - if (msg.author.id != 109338686889476096) { bot.sendMessage(msg, "It's not like I wanted you to use `" + config.command_prefix + "joins` or anything, b-baka!"); } if (shouldCarbonAnnounce) { - setTimeout(function() { - var msgArray = []; - msgArray.push("Hi! I'm **" + bot.user.username + "** and I was invited to this server through carbonitex.net."); - msgArray.push("You can use `" + config.command_prefix + "help` to see what I can do. Mods can use `" + config.mod_command_prefix + "help` for mod commands."); - msgArray.push("If I shouldn't be here someone with the `Kick Members` permission can use `" + config.mod_command_prefix + "leaves` to make me leave"); - msgArray.push("For help / feedback / bugs/ testing / info / changelogs / etc. go to **discord.gg/0kvLlwb7slG3XCCQ**"); - bot.sendMessage(server.defaultChannel, msgArray); - }, 2000); + var msgArray = []; + msgArray.push("Hi! I'm **" + bot.user.username + "** and I was invited to this server through carbonitex.net."); + msgArray.push("You can use `" + config.command_prefix + "help` to see what I can do. Mods can use `" + config.mod_command_prefix + "help` for mod commands."); + msgArray.push("If I shouldn't be here someone with the `Kick Members` permission can use `" + config.mod_command_prefix + "leaves` to make me leave"); + msgArray.push("For help / feedback / bugs/ testing / info / changelogs / etc. go to **discord.gg/0kvLlwb7slG3XCCQ**"); + bot.sendMessage(server.defaultChannel, msgArray); } } }); @@ -242,16 +236,16 @@ function carbonInvite(msg) { } function reload() { - delete require.cache[require.resolve("./bot/config.json")]; //delete cache or it won"t work + delete require.cache[require.resolve("./bot/config.json")]; config = require("./bot/config.json"); delete require.cache[require.resolve("./bot/games.json")]; games = require("./bot/games.json").games; delete require.cache[require.resolve("./bot/commands.js")]; try { commands = require("./bot/commands.js").commands; - } catch (err) { } + } catch (err) { console.log(colors.cError(" ERROR ") + "Problem loading commands.js: " + err); } delete require.cache[require.resolve("./bot/mod.js")]; try {mod = require("./bot/mod.js").commands; - } catch (err) { } + } catch (err) { console.log(colors.cError(" ERROR ") + "Problem loading mod.js: " + err); } delete require.cache[require.resolve("./bot/config.json")]; delete require.cache[require.resolve("./bot/versioncheck.js")]; versioncheck = require("./bot/versioncheck.js"); @@ -259,7 +253,7 @@ function reload() { colors = require("./bot/styles.js"); delete require.cache[require.resolve("./bot/cleverbot.js")]; cleverbot = require("./bot/cleverbot").cleverbot; - console.log(colors.BgGreen(" Reloaded modules ") + " success"); + console.log(colors.BgGreen(" Module Reload ") + " Success"); } function checkConfig() { @@ -288,7 +282,7 @@ function checkConfig() { function evaluateString(msg) { /*EXTREMELY DANGEROUS so lets check again*/if (msg.author.id != config.admin_id) { console.log(colors.cWarn(" WARN ") + "Somehow an unauthorized user got into eval!"); return; } - console.log(colors.cWarn(" WARN ") + "Running eval"); + console.log("Running eval"); var result = eval("try{" + msg.content.substring(7).replace(/\n/g, "") + "}catch(err){console.log(colors.cError(\" ERROR \")+err);bot.sendMessage(msg, \"```\"+err+\"```\");}"); if (typeof result !== "object") { bot.sendMessage(msg, result); @@ -299,4 +293,5 @@ function evaluateString(msg) { setInterval(function() { bot.setPlayingGame(games[Math.floor(Math.random() * (games.length))]); + if (config.debug) { console.log(colors.cDebug(" DEBUG ") + "Updated bot's game"); } }, 800000); //change playing game every 12 minutes diff --git a/README.md b/README.md index b72bfc2..fecf75e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# BrussellBot +# BrussellBot 1.2 A multipurpose bot for Discord using the [Discord.js](https://github.com/hydrabolt/discord.js/) unofficial API. @@ -27,5 +27,3 @@ A multipurpose bot for Discord using the [Discord.js](https://github.com/hydrabo - [ ] List of queues songs - [ ] Set playing to song name - [ ] Bot owner gets priority -- [ ] prune can remove user -- [x] Have `]info @user` get shared servers diff --git a/bot/commands.js b/bot/commands.js index 3535b5a..b47d56d 100644 --- a/bot/commands.js +++ b/bot/commands.js @@ -53,7 +53,7 @@ function generateUserRating(bot, msg, fullName) { var user = msg.channel.server.members.get("username", fullName); var score = generateRandomRating() - 1; var joined = new Date(msg.channel.server.detailsOfUser(user).joinedAt), now = new Date(); - if (now - joined >= 2592000000) { score += 1; } //if user has been on the server for at least one month +1 + if (now.valueOf() - joined.valueOf() >= 2592000000) { score += 1; } //if user has been on the server for at least one month +1 if (msg.channel.permissionsOf(user).hasPermission("manageServer")) { score += 1; } //admins get +1 ;) var count = 0; bot.servers.map(function(server) { if (server.members.get("id", user.id)) { count += 1; } }); //how many servers does the bot share with them @@ -137,16 +137,18 @@ var commands = { shouldDisplay: false, usage: "", process: function(bot, msg) { - var n = Math.floor(Math.random() * 4); + var n = Math.floor(Math.random() * 6); if (n === 0) { bot.sendMessage(msg, "pong"); } else if (n === 1) { bot.sendMessage(msg, "You thought I would say pong, didn't you?"); } else if (n === 2) { bot.sendMessage(msg, "pong!"); - } else if (n === 3) { bot.sendMessage(msg, "Yeah, I'm still here"); } + } else if (n === 3) { bot.sendMessage(msg, "Yeah, I'm still here"); + } else if (n === 4) { bot.sendMessage(msg, "..."); + } else if (n === 5) { bot.sendMessage(msg, config.command_prefix + "ping"); } } }, "joins": { desc: "Accepts an invite.", - usage: " [invite link] [-a (announce presence)]", + usage: " [-a (announce presence)]", deleteCommand: true, process: function(bot, msg, suffix) { if (suffix) { @@ -161,7 +163,7 @@ var commands = { console.log(colors.cWarn(" WARN ") + err); } else if (!server || server.name == undefined || server.roles == undefined || server.channels == undefined || server.members == undefined) { console.log(colors.cWarn(" WARN ") + "Error joining server. Didn't receive all data."); - bot.sendMessage(msg, "⚠ Failed to receive all data, please try again in a few seconds."); + bot.sendMessage(msg, "⚠ Failed to receive all data, please try again."); try { bot.leaveServer(server); } catch (error) { /*how did it get here?*/ } @@ -187,14 +189,12 @@ var commands = { console.log(colors.cGreen("Joined server: ") + server.name); bot.sendMessage(msg, "✅ Successfully joined ***" + server.name + "***"); if (suffix.indexOf("-a") != -1) { - setTimeout(function() { - var msgArray = []; - msgArray.push("Hi! I'm **" + bot.user.username + "** and I was invited to this server by " + msg.author + "."); - msgArray.push("Use `" + config.command_prefix + "help` to get a list of normal commands."); - msgArray.push("If I shouldn't be here someone with the `Kick Members` permission can use `" + config.mod_command_prefix + "leaves` to make me leave"); - msgArray.push("For help / feedback / bugs / testing / announcements / changelogs / etc. go to **discord.gg/0kvLlwb7slG3XCCQ**"); - bot.sendMessage(server.defaultChannel, msgArray); - }, 2000); + var msgArray = []; + msgArray.push("Hi! I'm **" + bot.user.username + "** and I was invited to this server by " + msg.author + "."); + msgArray.push("Use `" + config.command_prefix + "help` to get a list of normal commands."); + msgArray.push("If I shouldn't be here someone with the `Kick Members` permission can use `" + config.mod_command_prefix + "leaves` to make me leave"); + msgArray.push("For help / feedback / bugs / testing / announcements / changelogs / etc. go to **discord.gg/0kvLlwb7slG3XCCQ**"); + bot.sendMessage(server.defaultChannel, msgArray); } else { setTimeout(function() { bot.sendMessage(server.defaultChannel, "*Quietly walks in*"); }, 2000); } } }); diff --git a/bot/games.json b/bot/games.json index 3ff8e10..0a3bdbe 100644 --- a/bot/games.json +++ b/bot/games.json @@ -19,7 +19,7 @@ "Sakura Swim Club", "Sakura Spirit", "Akiba's Trip", - "Animaaayyyy lmao", + "Animaayyy lmao", "Ayyyy lmao", "Jet fuel can't melt dank memes", "with nekos", diff --git a/bot/mod.js b/bot/mod.js index 47ea655..10f1189 100644 --- a/bot/mod.js +++ b/bot/mod.js @@ -64,8 +64,7 @@ var commands = { var msgArray = []; msgArray.push("```"); msgArray.push("Uptime (may be inaccurate): " + (Math.round(bot.uptime / (1000 * 60 * 60))) + " hours, " + (Math.round(bot.uptime / (1000 * 60)) % 60) + " minutes, and " + (Math.round(bot.uptime / 1000) % 60) + " seconds."); - msgArray.push("Connected to " + bot.servers.length + " servers and " + bot.channels.length + " channels."); - msgArray.push("Serving " + bot.users.length + " users."); + msgArray.push("Connected to " + bot.servers.length + " servers, " + bot.channels.length + " channels, and " + bot.users.length + " users."); msgArray.push("Memory Usage: " + Math.round(process.memoryUsage().rss / 1024 / 1000) + "MB"); msgArray.push("Running BrussellBot v" + version); msgArray.push("Commands processed this session: " + commandsProcessed); @@ -210,7 +209,7 @@ var commands = { } } else { announceMessages.push(suffix); - var code = Math.floor(Math.random() * 999999999); + var code = Math.floor(Math.random() * 100000000); confirmCodes.push(Math.floor(code)); bot.sendMessage(msg, "⚠ This will send a private message to **all** of the servers I'm in. If you're sure you want to do this say `" + config.mod_command_prefix + "announce " + code + "`"); } @@ -232,7 +231,7 @@ var commands = { } } else { announceMessages.push(suffix); - var code = Math.floor(Math.random() * 999999999); + var code = Math.floor(Math.random() * 100000000); confirmCodes.push(Math.floor(code)); bot.sendMessage(msg, "⚠ This will send a private message to **all** members of this server. If you're sure you want to do this say `" + config.mod_command_prefix + "announce " + code + "`"); }