Skip to content

Commit 02786ae

Browse files
committed
2.0.0 Release
Improved cleverbot fail detection Tons of very small optimizations Added the fortune command Re-wrote ]help pagination Added extended help for some commands Track if servers are actually using the bot Improved choose Allow unicode through ]anime and ]manga Added title to ]image (ignore the base for remind) Added whitelist for inactivity removal Added a config option to let users set the game Always send kick/ban message Added help option to }settings Re-wrote cooldown Updated config checks Updated eval
1 parent 1fb3c0e commit 02786ae

File tree

8 files changed

+256
-121
lines changed

8 files changed

+256
-121
lines changed

BrussellBot.js

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bot.on("ready", () => {
2727
versioncheck.checkForUpdate(resp => {
2828
if (resp !== null) console.log(resp);
2929
});
30+
db.checkServers(bot);
3031
});
3132

3233
bot.on("disconnected", () => {
@@ -47,8 +48,8 @@ bot.on("message", msg => {
4748
if (msg.mentions.length !== 0 && !msg.channel.isPrivate) {
4849
if (msg.isMentioned(bot.user) && msg.content.startsWith("<@" + bot.user.id + ">")) {
4950
if (ServerSettings.hasOwnProperty(msg.channel.server.id)) { if (ServerSettings[msg.channel.server.id].ignore.indexOf(msg.channel.id) === -1) {
50-
cleverbot(bot, msg); talkedToTimes += 1;
51-
}} else { cleverbot(bot, msg); talkedToTimes += 1; }
51+
cleverbot(bot, msg); talkedToTimes += 1; db.updateTimestamp(msg.channel.server);
52+
}} else { cleverbot(bot, msg); talkedToTimes += 1; db.updateTimestamp(msg.channel.server); }
5253
}
5354
if (msg.content.indexOf("<@" + config.admin_id + ">") > -1) {
5455
if (config.send_mentions) {
@@ -68,13 +69,15 @@ bot.on("message", msg => {
6869
if (msg.content.startsWith(config.command_prefix)) {
6970
if (commands.commands.hasOwnProperty(cmd)) execCommand(msg, cmd, suffix, "normal");
7071
else if (commands.aliases.hasOwnProperty(cmd)) {
72+
if (!msg.channel.isPrivate) db.updateTimestamp(msg.channel.server);
7173
msg.content = msg.content.replace(/[^ ]+ /, config.command_prefix + commands.aliases[cmd] + " ");
7274
execCommand(msg, commands.aliases[cmd], suffix, "normal");
7375
}
7476
} else if (msg.content.startsWith(config.mod_command_prefix)) {
7577
if (cmd == "reload" && msg.author.id == config.admin_id) { reload(); bot.deleteMessage(msg); return; }
7678
if (mod.commands.hasOwnProperty(cmd)) execCommand(msg, cmd, suffix, "mod");
7779
else if (mod.aliases.hasOwnProperty(cmd)) {
80+
if (!msg.channel.isPrivate) db.updateTimestamp(msg.channel.server);
7881
msg.content = msg.content.replace(/[^ ]+ /, config.mod_command_prefix + mod.aliases[cmd] + " ");
7982
execCommand(msg, mod.aliases[cmd], suffix, "mod");
8083
}
@@ -86,23 +89,17 @@ function execCommand(msg, cmd, suffix, type) {
8689
commandsProcessed += 1;
8790
if (type == "normal") {
8891
if (!msg.channel.isPrivate) console.log(colors.cServer(msg.channel.server.name) + " > " + colors.cGreen(msg.author.username) + " > " + msg.cleanContent.replace(/\n/g, " ")); else console.log(colors.cGreen(msg.author.username) + " > " + msg.cleanContent.replace(/\n/g, " "));
89-
if (commands.commands[cmd].hasOwnProperty("cooldown")) {
90-
if (lastExecTime.hasOwnProperty(cmd)) {
91-
var id = msg.author.id;
92-
if (lastExecTime[cmd][id] != undefined) {
93-
var cTime = new Date();
94-
var leTime = new Date(lastExecTime[cmd][id]);
95-
leTime.setSeconds(leTime.getSeconds() + commands.commands[cmd].cooldown);
96-
if (cTime < leTime) { //if it is still on cooldow
97-
var left = (leTime.valueOf() - cTime.valueOf()) / 1000;
98-
if (msg.author.id != config.admin_id) { //admin bypass
99-
bot.sendMessage(msg, msg.author.username + ", you need to *cooldown* (" + Math.round(left) + " seconds)", function(erro, message) { bot.deleteMessage(message, {"wait": 6000}); });
100-
if (!msg.channel.isPrivate) bot.deleteMessage(msg, {"wait": 10000});
101-
return;
102-
}
103-
} else lastExecTime[cmd][id] = cTime;
104-
} else lastExecTime[cmd][id] = new Date();
105-
} else lastExecTime[cmd] = {};
92+
if (msg.author.id != config.admin_id && commands.commands[cmd].hasOwnProperty("cooldown")) {
93+
if (!lastExecTime.hasOwnProperty(cmd)) lastExecTime[cmd] = {};
94+
if (!lastExecTime[cmd].hasOwnProperty(msg.author.id)) lastExecTime[cmd][msg.author.id] = new Date().valueOf();
95+
else {
96+
var now = new Date().valueOf();
97+
if (now < lastExecTime[cmd][msg.author.id] + (commands.commands[cmd].cooldown * 1000)) {
98+
bot.sendMessage(msg, msg.author.username.replace(/@/g, '@\u200b') + ", you need to *cooldown* (" + Math.round(((lastExecTime[cmd][msg.author.id] + commands.commands[cmd].cooldown * 1000) - now) / 1000) + " seconds)", (e, m)=>{ bot.deleteMessage(m, {"wait": 6000}); });
99+
if (!msg.channel.isPrivate) bot.deleteMessage(msg, {"wait": 10000});
100+
return;
101+
} lastExecTime[cmd][msg.author.id] = now;
102+
}
106103
}
107104
commands.commands[cmd].process(bot, msg, suffix);
108105
if (!msg.channel.isPrivate && commands.commands[cmd].hasOwnProperty("deleteCommand")) {
@@ -112,23 +109,17 @@ function execCommand(msg, cmd, suffix, type) {
112109
if (!msg.channel.isPrivate)
113110
console.log(colors.cServer(msg.channel.server.name) + " > " + colors.cGreen(msg.author.username) + " > " + colors.cBlue(msg.cleanContent.replace(/\n/g, " ").split(" ")[0]) + msg.cleanContent.replace(/\n/g, " ").substr(msg.cleanContent.replace(/\n/g, " ").split(" ")[0].length));
114111
else console.log(colors.cGreen(msg.author.username) + " > " + colors.cBlue(msg.cleanContent.replace(/\n/g, " ").split(" ")[0]) + msg.cleanContent.replace(/\n/g, " ").substr(msg.cleanContent.replace(/\n/g, " ").split(" ")[0].length));
115-
if (mod.commands[cmd].hasOwnProperty("cooldown")) {
116-
if (lastExecTime.hasOwnProperty(cmd)) {
117-
var id = msg.author.id;
118-
if (lastExecTime[cmd][id] != undefined) {
119-
var cTime = new Date();
120-
var leTime = new Date(lastExecTime[cmd][id]);
121-
leTime.setSeconds(leTime.getSeconds() + mod.commands[cmd].cooldown);
122-
if (cTime < leTime) { //if it is still on cooldown
123-
var left = (leTime.valueOf() - cTime.valueOf()) / 1000;
124-
if (msg.author.id != config.admin_id) { //admin bypass
125-
bot.sendMessage(msg, msg.author.username + ", you need to *cooldown* (" + Math.round(left) + " seconds)", function(erro, message) { bot.deleteMessage(message, {"wait": 6000}); });
126-
if (!msg.channel.isPrivate) bot.deleteMessage(msg, {"wait": 10000});
127-
return;
128-
}
129-
} else lastExecTime[cmd][id] = cTime;
130-
} else lastExecTime[cmd][id] = new Date();
131-
} else lastExecTime[cmd] = {};
112+
if (msg.author.id != config.admin_id && mod.commands[cmd].hasOwnProperty("cooldown")) {
113+
if (!lastExecTime.hasOwnProperty(cmd)) lastExecTime[cmd] = {};
114+
if (!lastExecTime[cmd].hasOwnProperty(msg.author.id)) lastExecTime[cmd][msg.author.id] = new Date().valueOf();
115+
else {
116+
var now = new Date().valueOf();
117+
if (now < lastExecTime[cmd][msg.author.id] + (mod.commands[cmd].cooldown * 1000)) {
118+
bot.sendMessage(msg, msg.author.username.replace(/@/g, '@\u200b') + ", you need to *cooldown* (" + Math.round(((lastExecTime[cmd][msg.author.id] + mod.commands[cmd].cooldown * 1000) - now) / 1000) + " seconds)", (e, m)=>{ bot.deleteMessage(m, {"wait": 6000}); });
119+
if (!msg.channel.isPrivate) bot.deleteMessage(msg, {"wait": 10000});
120+
return;
121+
} lastExecTime[cmd][msg.author.id] = now;
122+
}
132123
}
133124
mod.commands[cmd].process(bot, msg, suffix);
134125
if (!msg.channel.isPrivate && mod.commands[cmd].hasOwnProperty("deleteCommand")) {
@@ -176,6 +167,7 @@ bot.on("presence", (userOld, userNew) => {
176167
} else if (userNew.status != userOld.status) { console.log(colors.cDebug(" PRESENCE ") + userNew.username + " is now " + userNew.status + " playing " + userNew.game.name); }
177168
}
178169
if (config.non_essential_event_listeners) {
170+
if (userOld.username == undefined || userNew.username == undefined) return;
179171
if (userOld.username != userNew.username) {
180172
bot.servers.map((ser) => {
181173
if (ser.members.get("id", userOld.id) && ServerSettings.hasOwnProperty(ser.id) && ServerSettings[ser.id].nameChanges == true) {
@@ -189,6 +181,7 @@ bot.on("presence", (userOld, userNew) => {
189181

190182
bot.on("serverDeleted", objServer => {
191183
console.log(colors.cUYellow("Left server") + " " + objServer.name);
184+
db.handleLeave(objServer);
192185
});
193186

194187
/* Login */
@@ -226,6 +219,7 @@ function carbonInvite(msg) {
226219
toSend.push("For help / feedback / bugs/ testing / info / changelogs / etc. go to **https://discord.gg/0kvLlwb7slG3XCCQ**");
227220
bot.sendMessage(server.defaultChannel, toSend);
228221
db.addServer(server);
222+
db.addServerToTimes(server);
229223
}
230224
});
231225
}
@@ -254,29 +248,30 @@ function reload() {
254248
}
255249

256250
function checkConfig() {
257-
if (config.email === null) { console.log(colors.cWarn(" WARN ") + "Email not defined"); }
258-
if (config.password === null) { console.log(colors.cWarn(" WARN ") + "Password not defined"); }
259-
if (config.command_prefix === null || config.command_prefix.length !== 1) { console.log(colors.cWarn(" WARN ") + "Prefix either not defined or more than one character"); }
260-
if (config.mod_command_prefix === null || config.mod_command_prefix.length !== 1) { console.log(colors.cWarn(" WARN ") + "Mod prefix either not defined or more than one character"); }
261-
if (config.admin_id === null) { console.log(colors.cYellow("Admin user's id not defined") + " in config"); }
262-
if (config.mal_user === null) { console.log(colors.cYellow("MAL username not defined") + " in config"); }
263-
if (config.mal_pass === null) { console.log(colors.cYellow("MAL password not defined") + " in config"); }
264-
if (config.weather_api_key === null) { console.log(colors.cYellow("OpenWeatherMap API key not defined") + " in config"); }
265-
if (config.osu_api_key === null) { console.log(colors.cYellow("Osu API key not defined") + " in config"); }
251+
if (!config.email) { console.log(colors.cWarn(" WARN ") + "Email not defined"); }
252+
if (!config.password) { console.log(colors.cWarn(" WARN ") + "Password not defined"); }
253+
if (!config.command_prefix || config.command_prefix.length !== 1) { console.log(colors.cWarn(" WARN ") + "Prefix either not defined or more than one character"); }
254+
if (!config.mod_command_prefix || config.mod_command_prefix.length !== 1) { console.log(colors.cWarn(" WARN ") + "Mod prefix either not defined or more than one character"); }
255+
if (!config.admin_id) { console.log(colors.cYellow("Admin user's id") + " not defined in config"); }
256+
if (!config.mal_user) { console.log(colors.cYellow("MAL username") + " not defined in config"); }
257+
if (!config.mal_pass) { console.log(colors.cYellow("MAL password") + " not defined in config"); }
258+
if (!config.weather_api_key) { console.log(colors.cYellow("OpenWeatherMap API key") + " not defined in config"); }
259+
if (!config.osu_api_key) { console.log(colors.cYellow("Osu API key") + " not defined in config"); }
260+
if (!config.imgur_client_id) { console.log(colors.cYellow("Imgur client id") + " not defined in config"); }
266261
}
267262

268263
function evaluateString(msg) {
269264
if (msg.author.id != config.admin_id) { console.log(colors.cWarn(" WARN ") + "Somehow an unauthorized user got into eval!"); return; }
270-
var timeTaken = new Date();
265+
var timeTaken = new Date(), result;
271266
console.log("Running eval");
272-
var result;
273-
try { result = eval("try{" + msg.content.substring(7).replace(/\n/g, "") + "}catch(err){console.log(colors.cError(\" ERROR \")+err);bot.sendMessage(msg, \"```\"+err+\"```\");}");
274-
} catch (e) { console.log(colors.cError(" ERROR ") + e); bot.sendMessage(msg, "```" + e + "```"); }
275-
if (result && typeof result !== "object") {
276-
bot.sendMessage(msg, "`Time taken: " + (timeTaken - msg.timestamp) + "ms`\n" + result);
277-
console.log("Result: " + result);
267+
try { result = eval(msg.content.substring(7).replace(/\n/g, ""));
268+
} catch (e) { console.log(colors.cError(" ERROR ") + e); bot.sendMessage(msg, "```diff\n- " + e + "```"); }
269+
if (result) {
270+
if (typeof result === 'object') {
271+
if (JSON.stringify(result) !== '{}') bot.sendMessage(msg, "`Compute time: " + (timeTaken - msg.timestamp) + "ms`\n" + JSON.stringify(result));
272+
} else bot.sendMessage(msg, "`Compute time: " + (timeTaken - msg.timestamp) + "ms`\n" + result);
278273
}
279-
274+
console.log("Result: " + result);
280275
}
281276

282277
setInterval(() => {

bot/cleverbot.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ exports.cleverbot = function(bot, msg) {
2525
return String.fromCharCode(parseInt(grp, 16));
2626
});
2727
}
28-
bot.sendMessage(msg, '💬 ' + ent.decodeHTML(resp.message));
2928
if (!resp.message || !ent.decodeHTML(resp.message)) {
29+
bot.sendMessage(msg, '⚠ Nothing was returned! Resetting cleverbot...');
3030
delete require.cache[require.resolve("cleverbot-node")];
3131
Cleverbot = require('cleverbot-node');
3232
Slave = new Cleverbot();
33-
console.log(colors.cWarn(" WARN ") + "Cleverbot returned nothing"); }
33+
console.log(colors.cWarn(" WARN ") + "Cleverbot returned nothing");
34+
} else bot.sendMessage(msg, '💬 ' + ent.decodeHTML(resp.message));
3435
});
3536
} catch (error) { bot.sendMessage(msg, '⚠ There was an error', (erro, wMessage) => { bot.deleteMessage(wMessage, {'wait': 10000}); }); }
3637
});

0 commit comments

Comments
 (0)