Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco authored and Remco committed Feb 18, 2016
1 parent 68778ad commit 4902651
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Gamma phase
(Gamma is a real thing in software development by the way, it's a synonym for RC (Release Candidate))
## 2.0.0-gamma.4
Revamped music streaming permissions due to the way the normal permissions handle.
Added some extra commands.
Hopefully improved the reliability of `stop` for music streaming.
Made preparations for a future update.

## 2.0.0-gamma.3
*This is a relative small update.*
Added YouTube streaming.
Expand Down
51 changes: 43 additions & 8 deletions DougBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var Discord = require("discord.js"),
Debug = require("./runtime/debugging.js"),
ChatLogger = require("./runtime/logger.js").ChatLog,
Commands = require("./runtime/commands.js").Commands,
DJ = require("./runtime/djlogic.js"),
Permissions = require("./runtime/permissions.js"),
VersionChecker = require("./runtime/versionchecker.js"),
aliases,
Expand Down Expand Up @@ -46,6 +47,17 @@ bot.on("error", function(error) {
Debug.debuglogSomething("Discord.js", "Encountered an error with discord.js most likely, got error: " + error, "error");
});

// Warning logger
bot.on('warn', function(warn) {
Logger.warn("Something went wrong internally, if this problem persists, report this to the author of the bot.");
Debug.debuglogSomething('Discord.js', "Encountered a Discord.js warn: " + warn, "warn");
});

// Debug stuff
bot.on('debug', function(debug) {
Debug.debuglogSomething('Discord.js', "Debug message: " + debug, "debug");
});

// Ready announcment
bot.on("ready", function() {
Debug.debuglogSomething("Discord", "Ready event fired.", "info");
Expand Down Expand Up @@ -114,7 +126,7 @@ bot.on("message", function(msg) {
if (msg.author.equals(bot.user)) {
return;
}
if (msg.channel.isPrivate && msg.content.indexOf("https://discord.gg") === 0) {
if (msg.channel.isPrivate && msg.content.indexOf("https://discord.gg") === 0) { // TODO: This needs cleanup.
bot.joinServer(msg.content, function(err, server) {
if (err) {
Debug.debuglogSomething("DougBot", "Failed to join a server on DM request.", "warn");
Expand All @@ -125,10 +137,17 @@ bot.on("message", function(msg) {
msgArray.push("Yo! I'm **" + bot.user.username + "**, " + msg.author + " invited me to this server.");
msgArray.push("If I'm intended to be in this server, you may use **" + ConfigFile.bot_settings.cmd_prefix + "help** to see what I can do!");
msgArray.push("If you don't want me here, you may use **" + ConfigFile.bot_settings.cmd_prefix + "leave** to ask me to leave.");
msgArray.push("By the way, to give " + server.owner + " administrative permissions over me, use **" + ConfigFile.bot_settings.cmd_prefix + "setowner**");
Permissions.SetLevel((server.id + server.owner.id), 4, function(err, level) {
if (err) {
msgArray.push("An error occured while auto-setting " + server.owner + " to level 4, try running `setowner` a bit later.");
}
if (level === 4) {
msgArray.push("I have detected " + server.owner + " as the server owner and made him/her an admin over me.");
}
});
bot.sendMessage(server.defaultChannel, msgArray);
msgArray = [];
msgArray.push("Hey " + server.owner.username + ", I've joined a server in which you're the founder.");
msgArray.push("Hey " + server.owner.username + ", I've joined " + server.name + " in which you're the founder.");
msgArray.push("I'm " + bot.user.username + " by the way, a Discord bot, meaning that all of the things I do are mostly automated.");
msgArray.push("If you are not keen on having me in your server, you may use `" + ConfigFile.bot_settings.cmd_prefix + "leave` in the server I'm not welcome in.");
msgArray.push("If you do want me, use `" + ConfigFile.bot_settings.cmd_prefix + "help` to see what I can do.");
Expand Down Expand Up @@ -163,7 +182,25 @@ bot.on("message", function(msg) {
}
if (Commands[command]) {
Debug.debuglogSomething("DougBot", "Command detected, trying to execute.", "info");
if (msg.channel.server) {
if (Commands[command].music && msg.channel.server) {
Debug.debuglogSomething("DougBot", "Musical command detected, checking for user role.", "info");
DJ.checkPerms(msg.channel.server, msg.author, function(err, reply) {
if (reply === 1 && !err) {
Commands[command].fn(bot, msg, suffix);
} else if (reply === 0 && !err) {
bot.reply(msg, "you need a role called `Radio Master` to use music related commands, even if you're the server owner.");
return;
} else if (err) {
bot.sendMessage(msg.channel, "Something went wrong, try again later.");
return;
}
});
} else if (Commands[command].music && !msg.channel.server) {
Debug.debuglogSomething("DougBot", "Musical command detected, but was excuted in a DM.", "info");
bot.sendMessage(msg.channel, "You cannot use music commands in a DM, dummy!");
return;
}
if (msg.channel.server && !Commands[command].music) {
Permissions.GetLevel((msg.channel.server.id + msg.author.id), msg.author.id, function(err, level) {
if (err) {
Debug.debuglogSomething("LevelDB", "GetLevel failed, got error: " + err, "error");
Expand Down Expand Up @@ -217,7 +254,7 @@ bot.on("message", function(msg) {
return;
}
});
} else {
} else if (!msg.channel.server) {
Permissions.GetLevel(0, msg.author.id, function(err, level) { // Value of 0 is acting as a placeholder, because in DM's only global permissions apply.
Debug.debuglogSomething("DougBot", "DM command detected, getting global perms.", "info");
if (err) {
Expand Down Expand Up @@ -247,9 +284,7 @@ function init(token) {
VersionChecker.getStatus(function(err, status) {
if (err) {
Logger.error(err);
if (DebugMode === true) {
Debug.debuglogSomething("VersionChecker", "Version checking failed, got error: " + err, "error");
}
Debug.debuglogSomething("VersionChecker", "Version checking failed, got error: " + err, "error");
} // error handle
if (status && status !== "failed") {
Logger.info(status);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WildBeast gamma
##### (Previously DougleyBot 2.0)
[![Version](https://img.shields.io/badge/Version-2.0.0--gamma.2-green.svg?style=flat-square)](https://github.com/SteamingMutt/WildBeast/releases)
[![Version](https://img.shields.io/badge/Version-2.0.0--gamma.4-green.svg?style=flat-square)](https://github.com/SteamingMutt/WildBeast/releases)
[![Status](https://img.shields.io/badge/Status-Pre--release-orange.svg?style=flat-square)]()
[![Node](https://img.shields.io/badge/Node-5.5.0-blue.svg?style=flat-square)](http://nodejs.org)
[![NPM](https://img.shields.io/badge/NPM-3.5.3-blue.svg?style=flat-square)](http://nodejs.org)
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": "WildBeast",
"version": "2.0.0-gamma.3",
"version": "2.0.0-gamma.4",
"description": "A Discord bot",
"readme": "README.md",
"maintainers": [
Expand Down
56 changes: 56 additions & 0 deletions runtime/beastbank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var LevelUP = require("levelup"),
Logger = require("./logger.js").Logger;

var db = LevelUP('./runtime/databases/beastbank');
// 1 general error
// 2 low on cash
// 3 already exists
// 4 not found

fetchSaldo = function(user, callback) {
db.get(user, function(err, reply) {
if (err) {
if (err.notFound) {
return callback(4, null);
} else {
return callback(err, null);
}
}
if (reply && !err) {
return callback(null, reply);
}
});
};

exports.credit = function(user, cash, callback) {
fetchSaldo(user, function(err, reply) {
if (reply) {
// TODO: Do some DB shit here.
return callback(null, Math.round(reply + cash));
}
if (err) return callback(err, null);
});
};

exports.debit = function(user, cash, callback) {
fetchSaldo(user, function(err, reply) {
if (err) return callback(err, null);
if (reply < cash) {
return callback(2, null);
} else if (reply > cash) {
return callback(null, Math.round(reply - cash));
}
});
};

exports.register = function(user, callback) {
fetchSaldo(user, function(err, reply) {
if (reply && !err) return callback(3, null);
if (err === 4) {
db.put(user + ':500', function(err) {
if (!err) return callback(0, 500);
if (err) return callback(1, null);
});
}
});
};
127 changes: 116 additions & 11 deletions runtime/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ Commands["join-voice"] = {
name: "join-voice",
help: "I'll join a voice channel!",
usage: "[voice-channel-name]",
level: 3,
level: 0,
music: true,
fn: function(bot, msg) {
DJ.joinVoice(bot, msg);
}
Expand All @@ -122,7 +123,8 @@ Commands.play = {
name: "play",
help: "I'll play a weblink containing music!",
usage: "<web-url>",
level: 2,
level: 0,
music: true,
fn: function(bot, msg) {
DJ.playMusicURL(bot, msg);
}
Expand All @@ -132,7 +134,8 @@ Commands['yt-play'] = {
name: "yt-play",
help: "I'll play a YouTube video over voice!",
usage: "<video-id> If the youtube link is https://www.youtube.com/watch?v=duqZrupkuQA, duqZrupkuQA is the video-id",
level: 1,
level: 0,
music: true,
fn: function(bot, msg, suffix) {
DJ.playYouTube(bot, msg, suffix);
}
Expand All @@ -141,7 +144,8 @@ Commands['yt-play'] = {
Commands.stop = {
name: "stop",
help: "I'll stop playing music.",
level: 3,
level: 0,
music: true,
fn: function(bot, msg) {
DJ.stopPlaying(msg);
}
Expand All @@ -150,7 +154,8 @@ Commands.stop = {
Commands["leave-voice"] = {
name: "leave-voice",
help: "I'll leave the current voice channel.",
level: 3,
level: 0,
music: true,
fn: function(bot, msg) {
DJ.leaveVoice(bot, msg);
}
Expand Down Expand Up @@ -237,8 +242,8 @@ Commands.info = {
fn: function(bot, msg) {
var msgArray = [];
msgArray.push("**WildBeast version " + version + "**");
msgArray.push("Using latest 5.x.x *Discord.js* version by *hydrabolt*.");
msgArray.push("Made by <@107904023901777920>, <@108125505714139136> and <@110147170740494336>.");
msgArray.push("Using latest 6.x.x *Discord.js* version by *hydrabolt*.");
msgArray.push("Made primarily by Dougley, Mirrow and Perpetucake.");
bot.sendMessage(msg.channel, msgArray);
}
};
Expand All @@ -261,7 +266,7 @@ Commands.cleverbot = {

Commands.leave = {
name: "leave",
help: "I'll leave the server in which the command is executed, you'll need the *Manage server* permission in your role to use this command.",
help: "I'll leave the server in which the command is executed.",
level: 3,
fn: function(bot, msg, suffix) {
if (msg.channel.server) {
Expand All @@ -282,7 +287,7 @@ Commands.say = {
usage: "<text>",
level: 0,
fn: function(bot, msg, suffix) {
if (suffix.search("!say") === -1) {
if (suffix.search(ConfigFile.bot_settings.cmd_prefix + "say") === -1) {
bot.sendMessage(msg.channel, suffix);
if (msg.channel.server) {
var bot_permissions = msg.channel.permissionsOf(bot.user);
Expand Down Expand Up @@ -840,6 +845,100 @@ Commands.iff = {
}
};

Commands.ban = {
name: "ban",
help: "Swing the banhammer on someone!",
usage: "<user-mention>",
level: 2,
fn: function(bot, msg) {
if (!msg.channel.permissionsOf(msg.sender).hasPermission("banMembers")) {
bot.sendMessage(msg.channel, "Sorry, your role in this server does not have enough permissions.");
return;
}
if (!msg.channel.permissionsOf(bot.user).hasPermission("banMembers")) {
bot.sendMessage(msg.channel, "I don't have enough permissions to do this!");
return;
}
if (msg.mentions.length === 0) {
bot.sendMessage(msg.channel, "Please mention the user(s) you want to ban.");
return;
}
msg.mentions.map(function(user) {
bot.banMember(user.id, msg.channel.server.id, function(error) {
if (error) {
bot.sendMessage(msg.channel, "Failed to ban " + user);
} else if (!error) {
bot.sendMessage(msg.channel, "Banned " + user);
}
});
});
}
};

Commands.purgeban = {
name: "purgeban",
help: "Swing the banhammer and delete messages at the same time!",
usage: "<days-to-delete> <user-mention>",
level: 2,
fn: function(bot, msg, suffix) {
if (!msg.channel.permissionsOf(msg.sender).hasPermission("banMembers")) {
bot.sendMessage(msg.channel, "Sorry, your role in this server does not have enough permissions.");
return;
}
if (!msg.channel.permissionsOf(bot.user).hasPermission("banMembers")) {
bot.sendMessage(msg.channel, "I don't have enough permissions to do this!");
return;
}
if (msg.mentions.length === 0) {
bot.sendMessage(msg.channel, "Please mention the user(s) you want to ban.");
return;
}
if (isNaN(suffix[0])) {
bot.sendMessage(msg.channel, "Your first parameter is not a number, use `ban` to ban without deleting messages.");
return;
}
msg.mentions.map(function(user) {
bot.banMember(user.id, msg.channel.server.id, suffix[0], function(error) {
if (error) {
bot.sendMessage(msg.channel, "Failed to ban " + user);
} else if (!error) {
bot.sendMessage(msg.channel, "Banned " + user + " and deleted " + suffix[0] + " days worth of messages.");
}
});
});
}
};

Commands.kick = {
name: "kick",
help: "Kick an user out of the server!",
usage: "<user-mention>",
level: 1,
fn: function(bot, msg) {
if (!msg.channel.permissionsOf(msg.sender).hasPermission("kickMembers")) {
bot.sendMessage(msg.channel, "Sorry, your role in this server does not have enough permissions.");
return;
}
if (!msg.channel.permissionsOf(bot.user).hasPermission("kickMembers")) {
bot.sendMessage(msg.channel, "I don't have enough permissions to do this!");
return;
}
if (msg.mentions.length === 0) {
bot.sendMessage(msg.channel, "Please mention the user(s) you want to kick.");
return;
}
msg.mentions.map(function(user) {
bot.kickMember(user.id, msg.channel.server.id, function(error) {
if (error) {
bot.sendMessage(msg.channel, "Failed to kick " + user);
} else if (!error) {
bot.sendMessage(msg.channel, "Kicked " + user);
}
});
});
}
};

Commands.gif = {
name: "gif",
help: "I will search Giphy for a gif matching your tags.",
Expand Down Expand Up @@ -1055,6 +1154,7 @@ Commands.csgoprice = {
fn: function(bot, msg, suffix) {
skinInfo = suffix.split('"');
var csgomarket = require('csgo-market');
csgomarket.strictNameMode = false;
csgomarket.getSinglePrice(skinInfo[1], skinInfo[3], skinInfo[5], skinInfo[7], function(err, skinData) {
if (err) {
Logger.log('error', err);
Expand Down Expand Up @@ -1151,7 +1251,7 @@ Commands.imdb = {
}
});
} else {
bot.sendMessage(msg.channel, "Usage: !imdb [title]");
bot.sendMessage(msg.channel, "Usage: `imdb [title]`");
}
}
};
Expand Down Expand Up @@ -1239,7 +1339,12 @@ Commands.help = {
if (commando.hasOwnProperty("timeout")) { // Push special message if command has a cooldown
msgArray.push("**This command has a cooldown of " + commando.timeout + " seconds.**");
}
msgArray.push("**Needed access level:** " + commando.level); // Push the needed access level to the array
if (commando.hasOwnProperty('level')) {
msgArray.push("**Needed access level:** " + commando.level); // Push the needed access level to the array
}
if (commando.hasOwnProperty('music')) { // Push music message if command is musical.
msgArray.push("**This is a music related command, you'll need a role called** `Radio Master` **to use this command.**");
}
if (suffix == "meme") { // If command requested is meme, print avalible meme's
msgArray.push("");
var str = "**Currently available memes:\n**";
Expand Down
Loading

0 comments on commit 4902651

Please sign in to comment.