Skip to content

Commit

Permalink
0.5.0
Browse files Browse the repository at this point in the history
New Commands: Voting and ask
Fixed broken leaves permission logic
Added join date to info on users
Option to log presence
Option to disable event listeners
Per-server settings automatically generated (mod commands soon)
  • Loading branch information
brussell98 committed Dec 28, 2015
1 parent 7d8df35 commit f7032fa
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 41 deletions.
126 changes: 97 additions & 29 deletions BrussellBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ var commands = require("./bot/commands.js");
var config = require("./bot/config.json");
var games = require("./bot/games.json").games;
var perms = require("./bot/permissions.json");
var fs = require("fs");

var servers = getServers();

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

bot.on("ready", function(message) {
bot.on("ready", function (message) {
checkServers();
bot.setPlayingGame(games[Math.floor(Math.random() * (games.length))]);
//check to see if there is a new version of BrussellBot
console.log("BrussellBot is ready! Listening to " + bot.channels.length + " channels on " + bot.servers.length + " servers");
Expand Down Expand Up @@ -51,61 +55,125 @@ bot.on("message", function(message) {
});

//event listeners
bot.on('serverNewMember', function(objServer, objUser) {
consolelog('[info]', "New member on " + objServer.name + ": " + objUser.username);
bot.sendMessage(objServer.defaultChannel, "Welcome to " + objServer.name + " " + objUser.username);
bot.on('serverNewMember', function (objServer, objUser) {
if (servers[objServer.id].username_change == 1) {
consolelog('[info]', "New member on " + objServer.name + ": " + objUser.username);
bot.sendMessage(objServer.defaultChannel, "Welcome to " + objServer.name + " " + objUser.username);
}
});

bot.on('serverUpdated', function(objServer, objNewServer) {
console.log('[info]', "" + objServer.name + " is now " + objNewServer.name);
bot.on('serverUpdated', function (objServer, objNewServer) {
if (config.non_essential_event_listeners) {
console.log('[info]', "" + objServer.name + " is now " + objNewServer.name);
}
});

bot.on('channelCreated', function(objChannel) {
if (!objChannel.isPrivate){
console.log('[info]', "New channel created. Type: " + objChannel.type + ". Name: " + objChannel.name + ". Server: " + objChannel.server.name);
bot.on('channelCreated', function (objChannel) {
if (config.non_essential_event_listeners) {
if (!objChannel.isPrivate){
console.log('[info]', "New channel created. Type: " + objChannel.type + ". Name: " + objChannel.name + ". Server: " + objChannel.server.name);
}
}
});

bot.on('channelDeleted', function(objChannel) {
if (!objChannel.isPrivate){
console.log('[info]', "Channel deleted. Type: " + objChannel.type + ". Name: " + objChannel.name + ". Server: " + objChannel.server.name);
bot.on('channelDeleted', function (objChannel) {
if (config.non_essential_event_listeners) {
if (!objChannel.isPrivate) {
console.log('[info]', "Channel deleted. Type: " + objChannel.type + ". Name: " + objChannel.name + ". Server: " + objChannel.server.name);
}
}
});

bot.on('channelUpdated', function(objChannel) { //You could make this find the new channel by id to get new info
if (!objChannel.isPrivate){
if (objChannel.type == "text"){
console.log('[info]', "Channel updated. Was: Type: Text. Name: " + objChannel.name + ". Topic: " + objChannel.topic);
} else {
console.log('[info]', "Channel updated. Was: Type: Voice. Name: " + objChannel.name + ".");
bot.on('channelUpdated', function (objChannel) { //You could make this find the new channel by id to get new info
if (config.non_essential_event_listeners) {
if (!objChannel.isPrivate) {
if (objChannel.type == "text") {
console.log('[info]', "Channel updated. Was: Type: Text. Name: " + objChannel.name + ". Topic: " + objChannel.topic);
} else {
console.log('[info]', "Channel updated. Was: Type: Voice. Name: " + objChannel.name + ".");
}
}
}
});

bot.on('userBanned', function(objUser, objServer) {
console.log('[info]', "" + objUser.username + " banned on " + objServer.name);
bot.sendMessage(objServer.defaultChannel, "" + objUser.username + " was banned");
bot.sendMessage(objUser, "You were banned from " + objServer.name);
bot.on('userBanned', function (objUser, objServer) {
if (servers[objServer.id].ban_message == 1) {
console.log('[info]', "" + objUser.username + " banned on " + objServer.name);
bot.sendMessage(objServer.defaultChannel, "" + objUser.username + " was banned");
bot.sendMessage(objUser, "You were banned from " + objServer.name);
}
});

bot.on('userUnbanned', function(objServer, objUser) {
console.log('[info]', "" + objUser.username + " unbanned on " + objServer.name);
bot.on('userUnbanned', function (objServer, objUser) {
if (config.non_essential_event_listeners) {
console.log('[info]', "" + objUser.username + " unbanned on " + objServer.name);
}
});

bot.on('userUpdated', function(objUser, objNewUser) {
bot.on('userUpdated', function (objUser, objNewUser) {
if (objUser.username != objNewUser.username){
console.log('[info]', "" + objUser.username + " changed their name to " + objNewUser.username);
bot.servers.forEach(function(ser){
if (ser.members.get('id', objUser.id) != null){
if (ser.members.get('id', objUser.id) != null && servers[ser.id].username_change == 1){
bot.sendMessage(ser, "User in this server: `" + objUser.username + "`. changed their name to: `" + objNewUser.username + "`.");
}
});
}
if (config.non_essential_event_listeners) {
if (objUser.avatar != objNewUser.avatar) {
console.log('[info]', "" + objNewUser.username + " changed their avatar to: " + objNewUser.avatarUrl);
}
}
});

bot.on('presence', function(user, status, game) {
if (config.log_presence) {
console.log('[info]', "Presence: " + user.username + " is now " + status + " playing " + game);
}
if (objUser.avatar != objNewUser.avatar){
console.log('[info]', "" + objNewUser.username + " changed their avatar to: " + objNewUser.avatarUrl);
}
});

bot.on('serverCreated', function (objServer) {
addServer(objServer);
});

//login
bot.login(config.email, config.password);
console.log("Logging in...");

function updateServers() {
fs.writeFile("./bot/servers.json", JSON.stringify(servers, null, '\t'), null);
servers = getServers();
console.log('[info]', "Updated servers.json");
}

function getServers() {
var svrs = require("./bot/servers.json");
return svrs;
}

function addServer(svr) {
var log_m = 1;
if (svr.members.length < 101) { var user_c = 1; var s_g = 1; }
else { var user_c = 0; var s_g = 0; }
if (svr.members.length < 301) { var ban_m = 1; }
else { var ban_m = 0; }
var setngs = {
"log_messages": log_m,
"username_change": user_c,
"server_greeting": s_g,
"ban_message": ban_m
}
servers[svr.id] = setngs;
updateServers();
}

function checkServers() {
bot.servers.forEach(function (ser) {
if (servers.hasOwnProperty(ser.id)) {
//found server in config
} else {
console.log('[info]', "Found new server");
addServer(ser);
}
});
}
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ A ping-pong and music bot for Discord using the [Discord.js](https://github.com/

[Wiki](https://github.com/brussell98/BrussellBot/wiki)

[Setup Guide](https://github.com/brussell98/BrussellBot/wiki/Setup-Guide)

[Making new commands](https://github.com/brussell98/BrussellBot/wiki/New-Command-Guide)

[Discord.js Documentation](http://discordjs.readthedocs.org/en/latest/)

---

### Features
*Comming soon!*
*Coming soon!*

---

Expand All @@ -34,11 +38,13 @@ A ping-pong and music bot for Discord using the [Discord.js](https://github.com/

- [x] Test current version
- [ ] Cooldown for commands
- [ ] Option to disable non-essential event listeners
- [ ] per server
- [x] Per-server settings JSON
- [x] Add new servers to JSON on join / startup
- [ ] Server settings commands
- [x] Wiki page for adding commands
- [ ] Add more dank memes to `games.json`
- [ ] Semi-idiot-proof the code
- [ ] And add comments so people can understand what this stuff does
- [x] Fully check if user has permission to execute a command in the message interpreter
- [x] Debug messages toggle
- [ ] Commands
Expand All @@ -65,18 +71,23 @@ A ping-pong and music bot for Discord using the [Discord.js](https://github.com/
- [x] Server info
- [x] User info
- [ ] Get past usernames from log
- [x] Get joinedAt from detailsOfUser
- [x] Ask if anyone wants to play a game
- [x] Announce
- [x] To users in the server
- [x] To servers
- [x] Dice roll
- [ ] 8ball
- [x] 8ball
- [x] Choose for me
- [x] Clean bot messages
- [ ] Fancy quote a message
- [ ] Vote
- [ ] Logging
- [x] Vote (Credit: [BlackHayate](https://github.com/BlackHayate))
- [ ] Logging (w/ Winston because I really liked DougleyBot's log)
- [ ] Event logs
- [ ] Chat logs
- [ ] Console output log
- [ ] Fix `info`'s roles and playing game reporting
- [ ] Presence changes
- [ ] Commands processed
- [ ] Fix `info`'s playing game reporting
- [ ] Version checker
- [ ] Optimize code
64 changes: 63 additions & 1 deletion bot/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ var version = require("../package.json").version;

var request = require('request');

//voting vars
var topicstring = "";
var voter = [];
var upvote = 0;
var downvote = 0;
var votebool = false;

/*
====================
Functions
Expand Down Expand Up @@ -92,7 +99,7 @@ var commands = {
},
"leaves": {
desc: "Leaves the server.",
permLevel: 2,
permLevel: 0,
process: function(bot, msg, suffix) {
if (msg.channel.server) {
if (msg.channel.permissionsOf(msg.author).hasPermission("kickMembers")) {
Expand Down Expand Up @@ -231,6 +238,8 @@ var commands = {
msgArray.push("User ID: `" + usr.id + "`");
if (usr.gameID != null) { msgArray.push("Staus: `" + usr.status + "` playing `" + usr.gameID + "`"); }
else { msgArray.push("Staus: `" + usr.status + "`"); }
var myDate = new Date(msg.channel.server.detailsOfUser(usr).joinedAt);
msgArray.push("Joined this server on: " + myDate.toUTCString());
msgArray.push("Roles: " + msg.channel.server.rolesOfUser(usr));
if (usr.avatarURL != null) { msgArray.push("Avatar: " + usr.avatarURL); }
bot.sendMessage(msg, msgArray);
Expand Down Expand Up @@ -264,6 +273,59 @@ var commands = {
bot.sendMessage(msg, "I picked " + choices[choice]);
}
}
},
"newvote": {
desc: "Create a new vote.",
permLevel: 1,
usage: "<topic>",
process: function (bot, msg, suffix) {
if (!suffix) { bot.sendMessage(msg, correctUsage("newvote")); return; }
if (votebool == true) { bot.sendMessage(msg, "Theres already a vote pending!"); return; }
topicstring = suffix;
bot.sendMessage(msg, "New Vote started: `" + suffix + "`\nTo vote say `" + config.command_prefix + "vote +/-`");
votebool = true;
}
},
"vote": {
desc: "Vote.",
permLevel: 0,
usage: "<+/->",
process: function (bot, msg, suffix) {
if (!suffix) { bot.sendMessage(msg, correctUsage("vote")); return; }
if (votebool == false) { bot.sendMessage(msg, "There isn't a topic being voted on right now!"); return; }
if (voter.indexOf(msg.author) != -1) { return; }
voter.push(msg.author);
var vote = suffix.split(" ")[0]
if (vote == "+") { upvote += 1; }
if (vote == "-") { downvote += 1; }
}
},
"endvote": {
desc: "End current vote.",
permLevel: 1,
process: function (bot, msg, suffix) {
bot.sendMessage(msg, "**Results of last vote:**\nTopic: `" + topicstring + "`\nUpvotes: `" + upvote + "`\nDownvotes: `" + downvote + "`");
upvote = 0;
downvote = 0;
voter = [];
votebool = false;
topicstring = "";
}
},
"ask": {
desc: "Ask the bot a question (8ball).",
permLevel: 0,
usage: "",
process: function (bot, msg) {
request('https://8ball.delegator.com/magic/JSON/0', function (error, response, body) {
if (!error && response.statusCode == 200) {
var answr = JSON.parse(body);
bot.sendMessage(msg.channel, answr.magic.answer);
} else {
console.log('[warn]', "8ball error: ", error, ", status code: ", response.statusCode);
}
});
}
}
};

Expand Down
6 changes: 4 additions & 2 deletions bot/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"email": "",
"password": "",
"command_prefix": "/",
"log_messages": true,
"settings_command_prefix": "$",
"log_messages": false,
"log_events": false,
"non_essential_event_listeners": true,
"non_essential_event_listeners": false,
"log_presence": false,
"debug": 0
}
3 changes: 3 additions & 0 deletions bot/servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brussellbot",
"version": "0.4.0",
"version": "0.5.0",
"description": "A Discord ping pong and music bot using discord.js",
"author": "brussell98",
"main": "BrussellBot.js",
Expand All @@ -20,6 +20,7 @@
"url": "*",
"feedparser": "*",
"path": "*",
"request": "*"
"request": "*",
"winston": "*"
}
}

0 comments on commit f7032fa

Please sign in to comment.