Skip to content

Commit

Permalink
clean some things up
Browse files Browse the repository at this point in the history
  • Loading branch information
brussell98 committed Jan 30, 2016
1 parent cd367c8 commit 8c691e0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
39 changes: 17 additions & 22 deletions BrussellBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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?*/ }
Expand All @@ -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);
}
}
});
Expand All @@ -242,24 +236,24 @@ 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");
delete require.cache[require.resolve("./bot/styles.js")];
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() {
Expand Down Expand Up @@ -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);
Expand All @@ -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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
26 changes: 13 additions & 13 deletions bot/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> [invite link] [-a (announce presence)]",
usage: "<invite link(s)> [-a (announce presence)]",
deleteCommand: true,
process: function(bot, msg, suffix) {
if (suffix) {
Expand All @@ -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?*/ }
Expand All @@ -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); }
}
});
Expand Down
2 changes: 1 addition & 1 deletion bot/games.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions bot/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 + "`");
}
Expand All @@ -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 + "`");
}
Expand Down

0 comments on commit 8c691e0

Please sign in to comment.