Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
/letsplay and /dice, plus silent option on /joins
improved message interpreter
debug messages toggle
  • Loading branch information
brussell98 committed Dec 27, 2015
1 parent ee22c2c commit 76086b5
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 55 deletions.
17 changes: 15 additions & 2 deletions BrussellBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var perms = require("./bot/permissions.json");

var bot = new discord.Client();
bot.on('warn', (m) => console.log('[warn]', m));
bot.on('debug', (m) => console.log('[debug]', m));
bot.on('debug', function(m){
if (config.debug == 1) { console.log('[debug]', m) }
});

bot.on("ready", function(message) {
bot.setPlayingGame(games[Math.floor(Math.random() * (games.length - 1))]);
Expand All @@ -34,7 +36,18 @@ bot.on("message", function(message) {
var suffix = message.content.substring( cmd.length + 2 );
var permLvl = 0;
if (perms.hasOwnProperty(message.author.id)) { permLvl = perms[message.author.id].level; }
if (commands.commands.hasOwnProperty(cmd)) { commands.commands[cmd].process(bot, message, suffix, permLvl); }
if (commands.commands.hasOwnProperty(cmd)) {
try {
if (commands.commands[cmd].permLevel <= permLvl) { commands.commands[cmd].process(bot, message, suffix); }
else {
bot.sendMessage(message, "You need permission level " + commands.commands[cmd].permLevel + " to do that.");
console.log('[info]', "Insufficient permissions");
}
} catch(err) {
console.log('[warn]', "This command lacks a permLevel property");
commands.commands[cmd].process(bot, message, suffix);
}
}
});

//event listeners
Expand Down
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

A ping-pong and music bot for Discord using the [Discord.js](https://github.com/hydrabolt/discord.js/) unoffficial API.

[Wiki](https://github.com/brussell98/BrussellBot/wiki)
[Discord.js Documentation](http://discordjs.readthedocs.org/en/latest/)

---

### Features
*Write text here when the bot works and has features*
*Comming soon!*

---

Expand All @@ -29,15 +32,17 @@ A ping-pong and music bot for Discord using the [Discord.js](https://github.com/
### TODO

- [x] Test current version
- [ ] Timeout for commands
- [ ] Cooldown for commands
- [ ] Option to disable non-essential event listeners
- [ ] Wiki page for adding commands
- [ ] per server
- [x] Wiki page for adding commands
- [ ] Add more dank memes to `games.json`
- [ ] Semi-idiot-proof the code
- [ ] Fully check if user has permission to execute a command in the message interpreter
- [x] Fully check if user has permission to execute a command in the message interpreter
- [x] Debug messages toggle
- [ ] Commands
- [x] Join server
- [ ] Have option for silent joining of servers
- [x] Have option for silent joining of servers
- [x] Leave Server
- [x] Leave server restricted by roles or perm level
- [x] Help
Expand All @@ -52,17 +57,22 @@ A ping-pong and music bot for Discord using the [Discord.js](https://github.com/
- [ ] Queue from a playlist
- [ ] Bind music messages to a channel
- [ ] List of queues songs
- [ ] Cleverbot command
- [ ] Cleverbot module activated with mention
- [x] Set playing status
- [ ] Info commands
- [ ] Server info
- [ ] User info
- [ ] Ask if anyone wants to play a game
- [ ] Get past usernames from log
- [x] Ask if anyone wants to play a game
- [ ] Announce
- [ ] To users
- [ ] To servers
- [ ] Dice roll
- [x] Dice roll
- [ ] 8ball
- [ ] Choose for me
- [x] Clean bot messages
- [ ] Fancy quote a message
- [ ] Logging
- [ ] Event logs
- [ ] Chat logs
- [ ] Console output log
113 changes: 69 additions & 44 deletions bot/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var games = require("./games.json").games;
var perms = require("./permissions.json");
var version = require("../package.json").version;

var request = require('request');

/*
====================
Functions
Expand Down Expand Up @@ -57,40 +59,43 @@ var commands = {
},
"joins": {
desc: "Accepts the invite sent to it.",
usage: "<invite link>",
usage: "<invite link> [-s (silent join)]",
permLevel: 0,
process: function (bot, msg, suffix) {
if (suffix) {
bot.joinServer(suffix, function (err, server) {
var invite = suffix.split(" ")[0];
bot.joinServer(invite, function (err, server) {
if (err) {
bot.sendMessage(msg, "Failed to join: " + err);
console.log('[warn]', err);
} else {
console.log('[info]', "Joined server: " + server);
bot.sendMessage(msg, "Successfully joined ***" + server + "***");
//add an option to -s this spam
var msgArray = [];
msgArray.push("Hi! I'm **" + bot.user.username + "** and I was invited to this server by " + msg.author + ".");
msgArray.push("You can use `" + config.command_prefix + "help` to see what I can do.");
msgArray.push("If I shouldn't be here someone with the `Kick Members` permission can use `" + config.command_prefix + "leaves` to make me leave");
bot.sendMessage(server.defaultChannel, msgArray);
msgArray = [];
msgArray.push("Hey " + server.owner.username + ", I've joined a server that you own.");
msgArray.push("I'm " + bot.user.username + " by the way, a \"ping-pong\" bot / music bot designed to make your life easier.");
msgArray.push("If you don't want me in your server, you may use `" + ConfigFile.command_prefix + "leaves` in the server I'm not welcome in.");
msgArray.push("If you do want me, use `" + ConfigFile.command_prefix + "help` to see what I can do.");
bot.sendMessage(server.owner, msgArray);
if (suffix.split(" ")[1] != "-s") {
var msgArray = [];
msgArray.push("Hi! I'm **" + bot.user.username + "** and I was invited to this server by " + msg.author + ".");
msgArray.push("You can use `" + config.command_prefix + "help` to see what I can do.");
msgArray.push("If I shouldn't be here someone with the `Kick Members` permission can use `" + config.command_prefix + "leaves` to make me leave");
bot.sendMessage(server.defaultChannel, msgArray);
msgArray = [];
msgArray.push("Hey " + server.owner.username + ", I've joined a server that you own.");
msgArray.push("I'm " + bot.user.username + " by the way, a \"ping-pong\" bot / music bot designed to make your life easier.");
msgArray.push("If you don't want me in your server, you may use `" + ConfigFile.command_prefix + "leaves` in the server I'm not welcome in.");
msgArray.push("If you do want me, use `" + ConfigFile.command_prefix + "help` to see what I can do.");
bot.sendMessage(server.owner, msgArray);
}
}
});
} else { bot.sendMessage(msg, correctUsage("help")); }

}
},
"leaves": {
desc: "Leaves the server.",
permLevel: 2,
process: function(bot, msg, suffix, pL) {
process: function(bot, msg, suffix) {
if (msg.channel.server) {
if (msg.channel.permissionsOf(msg.author).hasPermission("kickMembers") || pL >= this.permLevel) {
if (msg.channel.permissionsOf(msg.author).hasPermission("kickMembers")) {
bot.sendMessage(msg, "Alright, see ya!");
bot.leaveServer(msg.channel.server);
console.log('[info]', "I've left a server on request of " + msg.sender.username + ". I'm only in " + bot.servers.length + " servers now.");
Expand Down Expand Up @@ -135,42 +140,62 @@ var commands = {
permLevel: 1,
usage: "[game]",
process: function (bot, msg, suffix, pL) {
if (pL >= this.permLevel) {
!suffix ? bot.setPlayingGame(games[Math.floor(Math.random() * (games.length - 1))]) : bot.setPlayingGame(suffix);
console.log('[info]', "" + msg.author.username + " set the playing status to: " + bot.user.game);
} else { bot.sendMessage(msg, "Permission level " + this.permLevel + " required."); }
!suffix ? bot.setPlayingGame(games[Math.floor(Math.random() * (games.length - 1))]) : bot.setPlayingGame(suffix);
console.log('[info]', "" + msg.author.username + " set the playing status to: " + bot.user.game);
}
},
"clean": {
desc: "Cleans the specified number of bot messages from the channel.",
permLevel: 1,
usage: "<number of bot messages>",
process: function (bot, msg, suffix, pL) {
if (pL >= this.permLevel) {
if (suffix) {
bot.getChannelLogs(msg.channel, 100, function (error, messages) {
if (error) {
console.log('[warn]', "Something went wrong while fetching logs.");
return;
} else {
console.log("Cleaning bot messages...");
var todo = suffix,
delcount = 0;
for (msg1 of messages) {
if (msg1.author === bot.user) {
bot.deleteMessage(msg1);
delcount++;
todo--;
}
if (todo == 0) {
console.log("Done! Deleted " + delcount + " messages.");
return;
}
process: function (bot, msg, suffix) {
if (suffix) {
bot.getChannelLogs(msg.channel, 100, function (error, messages) {
if (error) {
console.log('[warn]', "Something went wrong while fetching logs.");
return;
} else {
console.log("Cleaning bot messages...");
var todo = suffix,
delcount = 0;
for (msg1 of messages) {
if (msg1.author === bot.user) {
bot.deleteMessage(msg1);
delcount++;
todo--;
}
if (todo == 0) {
console.log("Done! Deleted " + delcount + " messages.");
return;
}
}
});
} else { bot.sendMessage(msg, correctUsage("clean")); }
} else { bot.sendMessage(msg, "Permission level " + this.permLevel + " required."); }
}
});
} else { bot.sendMessage(msg, correctUsage("clean")); }
}
},
"letsplay": {
desc: "Ask if anyone wants to play a game",
permLevel: 0,
usage: "[game name]",
process: function(bot, msg, suffix) {
if (suffix) { bot.sendMessage(msg, "@everyone, " + msg.author + " would like to know if anyone wants to play **" + suffix + "**."); }
else { bot.sendMessage(msg, "@everyone, " + msg.author + " would like to know if anyone wants to play a game"); }
}
},
"roll": {
desc: "Rolls a die",
permLevel: 0,
usage: "[(rolls)d(sides)]",
process: function(bot, msg, suffix) {
var dice = "1d6";
if (suffix) { dice = suffix; }
request('https://rolz.org/api/?' + dice + '.json', function(err, response, body) {
if (!err && response.statusCode == 200) {
var roll = JSON.parse(body);
bot.sendMessage(msg, "Your " + roll.input + " resulted in " + roll.result + " " + roll.details);
} else { console.log('[warn]', "Got an error: ", error, ", status code: ", response.statusCode); }
});
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brussellbot",
"version": "0.2.2",
"version": "0.3.0",
"description": "A Discord ping pong and music bot using discord.js",
"author": "brussell98",
"main": "BrussellBot.js",
Expand Down

0 comments on commit 76086b5

Please sign in to comment.