Skip to content

Commit

Permalink
1.3.1
Browse files Browse the repository at this point in the history
Remove unused fs module
minor changes to some response formats
everyoneMentioned checks
better game detection in info command
fixed osu sig command
added returns to catfacts fails
changed node engine to >=5.5.0 in package.json
  • Loading branch information
brussell98 committed Feb 9, 2016
1 parent 9490418 commit a143a48
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 80 deletions.
9 changes: 4 additions & 5 deletions BrussellBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var mod = require("./bot/mod.js");
var config = require("./bot/config.json");
var games = require("./bot/games.json").games;
var versioncheck = require("./bot/versioncheck.js");
var fs = require("fs");
var discord = require("discord.js");
var cleverbot = require("./bot/cleverbot.js").cleverbot;
var colors = require("./bot/styles.js");
Expand Down Expand Up @@ -88,7 +87,7 @@ function execCommand(msg, cmd, suffix, type) {
if (cTime < leTime) { //if it is still on cooldown
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 years. Get rekt son.", function(erro, message) { bot.deleteMessage(message, {"wait": 6000}); });
bot.sendMessage(msg, msg.author.username + ", need to *cooldown* (" + Math.round(left) + " seconds)", function(erro, message) { bot.deleteMessage(message, {"wait": 6000}); });
return;
}
} else { lastExecTime[cmd][id] = cTime; }
Expand All @@ -97,7 +96,7 @@ function execCommand(msg, cmd, suffix, type) {
}
commands.commands[cmd].process(bot, msg, suffix);
if (commands.commands[cmd].hasOwnProperty("deleteCommand")) {
if (commands.commands[cmd].deleteCommand === true) { bot.deleteMessage(msg, {"wait": 8000}); }
if (commands.commands[cmd].deleteCommand === true) { bot.deleteMessage(msg, {"wait": 10000}); }
}
} else if (type == "mod") {
if (mod.commands[cmd].hasOwnProperty("cooldown")) {
Expand All @@ -110,7 +109,7 @@ function execCommand(msg, cmd, suffix, type) {
if (cTime < leTime) { //if it is still on cooldown
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}); });
bot.sendMessage(msg, msg.author.username + ", need to *cooldown* (" + Math.round(left) + " seconds)", function(erro, message) { bot.deleteMessage(message, {"wait": 6000}); });
return;
}
} else { lastExecTime[cmd][id] = cTime; }
Expand All @@ -119,7 +118,7 @@ function execCommand(msg, cmd, suffix, type) {
}
mod.commands[cmd].process(bot, msg, suffix, commandsProcessed, talkedToTimes);
if (mod.commands[cmd].hasOwnProperty("deleteCommand")) {
if (mod.commands[cmd].deleteCommand === true) { bot.deleteMessage(msg, {"wait": 8000}); }
if (mod.commands[cmd].deleteCommand === true) { bot.deleteMessage(msg, {"wait": 10000}); }
}
} else { return; }
} catch (err) { console.log(err.stack); }
Expand Down
57 changes: 28 additions & 29 deletions bot/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var version = require("../package.json").version;
var colors = require("./styles.js");
var request = require("request");
var xml2js = require("xml2js");
var fs = require("fs");
var osuapi = require("osu-api");
var ent = require("entities");
var waifus = require("./waifus.json");
Expand Down Expand Up @@ -51,7 +50,7 @@ function generateRandomRating(fullName, storeRating) {

function generateUserRating(bot, msg, fullName) {
var user = msg.channel.server.members.get("username", fullName);
var score = generateRandomRating();
var score = generateRandomRating() - 1;
var joined = new Date(msg.channel.server.detailsOfUser(user).joinedAt), now = new Date();
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 ;)
Expand Down Expand Up @@ -133,10 +132,10 @@ var commands = {
bot.sendMessage(msg.author, helpPart2);
} else {
if (commands.hasOwnProperty(suffix)) {
msgArray.push("**" + config.command_prefix + "" + suffix + ": **" + commands[suffix].desc);
msgArray.push("**" + config.command_prefix + "" + suffix + ":** " + commands[suffix].desc);
if (commands[suffix].hasOwnProperty("usage")) { msgArray.push("**Usage:** `" + config.command_prefix + "" + suffix + " " + commands[suffix].usage + "`"); }
if (commands[suffix].hasOwnProperty("cooldown")) { msgArray.push("**Cooldown:** " + commands[suffix].cooldown + " seconds"); }
if (commands[suffix].hasOwnProperty("deleteCommand")) { msgArray.push("*This command will delete the message that activates it*"); }
if (commands[suffix].hasOwnProperty("deleteCommand")) { msgArray.push("*Delete Command: true*"); }
bot.sendMessage(msg, msgArray);
} else { bot.sendMessage(msg, "Command `" + suffix + "` not found.", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); }
}
Expand Down Expand Up @@ -230,10 +229,7 @@ var commands = {
desc: "About me",
deleteCommand: true, cooldown: 10, usage: "",
process: function(bot, msg, suffix) {
var msgArray = [];
msgArray.push("I'm " + bot.user.username + " and ~~I was made by brussell98.~~ I'm a strong independent bot who don't need no creator.");
msgArray.push("I run on `discord.js` and my website is **brussell98.github.io/BrussellBot/**");
bot.sendMessage(msg, msgArray);
bot.sendMessage(msg, "I'm " + bot.user.username + " and I'm based on BrussellBot made by brussell98.\nI run on `discord.js` and my website is **brussell98.github.io/BrussellBot/**");
}
},
"letsplay": {
Expand Down Expand Up @@ -295,22 +291,23 @@ var commands = {
if (msg.mentions.length > 4) { bot.sendMessage(msg, "Limit of 4 users", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); return; }
msg.mentions.map(function(usr) {
var msgArray = [], count = 0;
msgArray.push("ℹ **Info on** " + usr.username);
msgArray.push("**User ID:** " + usr.id);
if (usr.game != null) { msgArray.push("**Status:** " + usr.status + " **last playing** " + usr.game.name);
msgArray.push("ℹ **Info on** " + usr.username + " (" + usr.discriminator + ")");
msgArray.push("**ID:** " + usr.id);
if (usr.game && usr.game !== undefined && usr.game !== null && usr.game !== "null") { msgArray.push("**Status:** " + usr.status + " **last playing** " + usr.game.name);
} else { msgArray.push("**Status:** " + usr.status); }
var jDate = new Date(msg.channel.server.detailsOfUser(usr).joinedAt);
msgArray.push("**Joined this server on:** " + jDate.toUTCString());
var roles = msg.channel.server.rolesOfUser(usr.id).map(function(role) { return role.name; });
roles = roles.join(", ").replace("@", "");
if (roles.length <= 1500) { msgArray.push("**Roles:** " + roles); } else { msgArray.push("**Roles:** Too many to display"); }
if (roles.length <= 1500) { msgArray.push("**Roles:** `" + roles + "`"); } else { msgArray.push("**Roles:** `Too many to display`"); }
bot.servers.map(function(server) { if (server.members.indexOf(usr) > -1) { count += 1; } });
if (count > 1) { msgArray.push("**Shared servers:** " + count); }
if (usr.avatarURL != null) { msgArray.push("**Avatar URL:** `" + usr.avatarURL + "`"); }
bot.sendMessage(msg, msgArray);
if (config.debug) { console.log(colors.cDebug(" DEBUG ") + "Got info on " + usr.username); }
});
} else {
if (msg.everyoneMentioned) { bot.sendMessage(msg, "Hey, " + msg.author.username + ", don't do that ok?", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); return; }
var users = suffix.split(/, ?/);
if (users.length > 4) { bot.sendMessage(msg, "Limit of 4 users", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); return; }
users.map(function(user) {
Expand All @@ -319,15 +316,15 @@ var commands = {
if (!usr) { usr = msg.channel.server.members.find((member) => { return member.username.toLowerCase().indexOf(user.toLowerCase()) > -1 }); }
if (usr) {
var msgArray = [], count = 0;
msgArray.push("ℹ **Info on** " + usr.username);
msgArray.push("**User ID:** " + usr.id);
if (usr.game != null) { msgArray.push("**Status:** " + usr.status + " **last playing** " + usr.game.name);
msgArray.push("ℹ **Info on** " + usr.username + " (" + usr.discriminator + ")");
msgArray.push("**ID:** " + usr.id);
if (usr.game && usr.game !== undefined && usr.game !== null && usr.game !== "null") { msgArray.push("**Status:** " + usr.status + " **last playing** " + usr.game.name);
} else { msgArray.push("**Status:** " + usr.status); }
var jDate = new Date(msg.channel.server.detailsOfUser(usr).joinedAt);
msgArray.push("**Joined this server on:** " + jDate.toUTCString());
var roles = msg.channel.server.rolesOfUser(usr.id).map((role) => { return role.name; });
roles = roles.join(", ").replace("@", "");
if (roles.length <= 1500) { msgArray.push("**Roles:** " + roles); } else { msgArray.push("**Roles:** Too many to display"); }
if (roles.length <= 1500) { msgArray.push("**Roles:** `" + roles + "`"); } else { msgArray.push("**Roles:** `Too many to display`"); }
bot.servers.map(function(server) { if (server.members.indexOf(usr) > -1) { count += 1; } });
if (count > 1) { msgArray.push("**Shared servers:** " + count); }
if (usr.avatarURL != null) { msgArray.push("**Avatar URL:** `" + usr.avatarURL + "`"); }
Expand Down Expand Up @@ -374,6 +371,7 @@ var commands = {
(usr.avatarURL != null) ? bot.sendMessage(msg, "**" + usr.username + "**'s avatar is: " + usr.avatarURL + "") : bot.sendMessage(msg, "**" + usr.username + "** has no avatar", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); });
});
} else {
if (msg.everyoneMentioned) { bot.sendMessage(msg, "Hey, " + msg.author.username + ", don't do that ok?", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); return; }
var users = suffix.split(/, ?/);
if (users.length > 6) { bot.sendMessage(msg, "Limit of 6 users", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); return; }
users.map(function(user) {
Expand Down Expand Up @@ -672,17 +670,18 @@ var commands = {

var color = "ff66aa",
username = msg.author.username;
suffix = suffix.split(" ");
if (suffix.length >= 2) {
if (/sig (.*) #?[A-Fa-f0-9]{6}$/.test(suffix.join(" "))) {
username = suffix.join("%20").substring(6, suffix.join("%20").lastIndexOf("%20"));
suffix = suffix.trim().split(" ");
suffix.shift();
if (suffix && suffix.length >= 1) {
if (/(.*) #?[A-Fa-f0-9]{6}$/.test(suffix.join(" "))) {
username = suffix.join("%20").substring(0, suffix.join("%20").lastIndexOf("%20"));
if (suffix[suffix.length - 1].length == 6) { color = suffix[suffix.length - 1];
} else if (suffix[suffix.length - 1].length == 7) { color = suffix[suffix.length - 1].substring(1); }
} else if (/sig #?[A-Fa-f0-9]{6}$/.test(suffix.join(" "))) {
} else if (/#?[A-Fa-f0-9]{6}$/.test(suffix.join(" "))) {
username = msg.author.username;
if (suffix[1].length == 6) { color = suffix[1];
} else if (suffix[1].length == 7) { color = suffix[1].substring(1); }
}
if (suffix[0].length == 6) { color = suffix[0];
} else if (suffix[0].length == 7) { color = suffix[0].substring(1); }
} else { username = suffix.join("%20"); }
}
request({url: "https://lemmmy.pw/osusig/sig.php?colour=hex" + color + "&uname=" + username + "&pp=2&flagshadow&xpbar&xpbarhex&darktriangles", encoding: null}, function(err, response, body) {
if (err) { bot.sendMessage(msg, "⚠ Error: " + err, function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); return; }
Expand Down Expand Up @@ -812,9 +811,9 @@ var commands = {
desc: "Let me Google that for you",
deleteCommand: true,
usage: "<search>",
cooldown: 4,
cooldown: 3,
process: function(bot, msg, suffix) {
if (!suffix) { bot.sendMessage(msg, "**http://www.lmgtfy.com/?q=brussellbot+commands**"); return; }
if (!suffix) { bot.sendMessage(msg, "**http://www.lmgtfy.com/?q=lmgtfy**"); return; }
suffix = suffix.split(" ");
for (var i = 0; i < suffix.length; i++) { suffix[i] = encodeURIComponent(suffix[i]); }
bot.sendMessage(msg, "🔍 **http://www.lmgtfy.com/?q=" + suffix.join("+") + "**");
Expand Down Expand Up @@ -845,8 +844,8 @@ var commands = {
cooldown: 2,
process: function(bot, msg, suffix) {
request("http://catfacts-api.appspot.com/api/facts", function(error, response, body) {
if (error) { bot.sendMessage(msg, "Error: " + error, function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 10000}); }); }
if (response.statusCode != 200) { bot.sendMessage(msg, "Got status code " + response.statusCode, function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 10000}); }); }
if (error) { bot.sendMessage(msg, "Error: " + error, function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 10000}); }); return; }
if (response.statusCode != 200) { bot.sendMessage(msg, "Got status code " + response.statusCode, function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 10000}); }); return; }
if (!error && response.statusCode == 200) {
body = JSON.parse(body);
bot.sendMessage(msg, "🐱 **" + msg.author.username + "**, did you know that " + body.facts[0]);
Expand All @@ -858,7 +857,7 @@ var commands = {
desc: "I'll rate your waifu",
usage: "<name>",
deleteCommand: false,
cooldown: 5,
cooldown: 4,
process: function(bot, msg, suffix) {
if (!suffix) { bot.sendMessage(msg, correctUsage("ratewaifu"), function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 10000}); }); return; }
if (msg.everyoneMentioned) { bot.sendMessage(msg, "Hey, " + msg.author.username + ", don't do that ok?", function(erro, wMessage) { bot.deleteMessage(wMessage, {"wait": 8000}); }); return; }
Expand Down
Loading

0 comments on commit a143a48

Please sign in to comment.