Skip to content

Commit

Permalink
Getting ready for gamma 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco authored and Remco committed Jan 17, 2016
1 parent 4e00864 commit 0b50786
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ npm-debug.log*
config.json
music
images
runtime/databases

# Runtime data
pids
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 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.1
Added a timeout feature.
**GET HYPED FOR MUSIC STREAMING!**
Changed `versionchecker.js` ability to check for beta versions to gamma version checking.
Moved to LevelDB instead of Redis for handling permission storage and handling timeouts.

# Beta phase
## 2.0.0-beta.5
Fixes several problems caused by 2.0.0-beta.4
Added an *incomplete* server defaulting system.
Expand Down Expand Up @@ -27,3 +36,6 @@ Bot is also compliant with the [Discord bot best practises](https://github.com/m

## 2.0.0-beta.1
Initial release of DougBot 2.0, featuring new permission system and stability improvements.

# Alpha phase
Nothing too interesting lol.
15 changes: 14 additions & 1 deletion DougBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var forever = require("forever");
var DebugMode;
var VerboseLog;
var Defaulting = require("./runtime/serverdefaulting.js");
var TimeOut = require("./runtime/timingout.js");

// Declare if debug mode or verbose logging is needed
if (ConfigFile.bot_settings.debug_mode === true){
Expand Down Expand Up @@ -134,11 +135,23 @@ bot.on("message", function(msg) {
if (DebugMode === true){
DebugLogger.debug("DEBUG MODE LOG: Execution of command allowed.");
}
if (Commands[command].timeout){
TimeOut.timeoutCheck(command, msg.channel.server.id, function(reply){
if (reply === "yes"){
bot.sendMessage(msg.channel, "Sorry, this command is on cooldown.");
return;
}});}
if (!Commands[command].nsfw){
if (DebugMode === true){
DebugLogger.debug("DEBUG MODE LOG: Safe for work command executed.");
}
Commands[command].fn(bot, msg, suffix);
if (Commands[command].timeout){
TimeOut.timeoutSet(command, msg.channel.server.id, Commands[command].timeout, function(reply, err){
if (err){
Logger.error("Resetting timeout failed!");
}
});}
return;
} else {
Permissions.GetNSFW(msg.channel, function (err, reply){
Expand Down Expand Up @@ -173,7 +186,7 @@ bot.on("message", function(msg) {
return;
}
});
} else {
} else {
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.
if (DebugMode === true){
DebugLogger.debug("DEBUG MODE LOG: DM command detected, getting global perms.");
Expand Down
4 changes: 1 addition & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Reintroduce a timeout feature, but better. *(RC 1)*
Music streaming, maybe rewrite to discord.io or discordie to make this easier. *(Proposed)*
Move to MongoDB instead of Redis. *(RC 1)*
Make command prefixes dynamic in their length requirement. *(Beta 5)*
~~Move to MongoDB instead of Redis.~~ **(Scrapped)**
Make `memes.json` update automatically with new memes from Imgflip. *(RC 2)*
`++remindme`. *(RC 1)*
OOTB experience improvements. *(Beta 5)*
???
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
{
"name": "DougleyBot",
"version": "2.0.0-beta.5",
"version": "2.0.0-gamma-1",
"description": "A Discord bot",
"readme": "README.md",
"maintainers": ["Perpetucake"],
"maintainers": [
"Perpetucake"
],
"author": "Remco Jongschaap (SteamingMutt@users.noreply.github.com)",
"repository": {
"type": "git",
"url": "git+https://github.com/SteamingMutt/DougleyBot2.0.git"
},
"license": "GPL-3.0",
"dependencies": {
"discord.js": "^5.0.0",
"winston": "^1.1.1",
"cleverbot-node": "0.2.x",
"request": "^2.61.0",
"xml2js": "*",
"leetspeak": "*",
"imgflipper": "*",
"csgo-market": "*",
"unirest": "*",
"youtube-node": "1.2.x",
"discord.js": "hydrabolt/discord.js#0921484ef6775691f0b5fcd17623f6b08837c0a9",
"forever": "*",
"redis": "*"
"imgflipper": "*",
"leetspeak": "*",
"leveldown": "^1.4.3",
"levelup": "^1.3.1",
"request": "^2.61.0",
"unirest": "*",
"winston": "^1.1.1",
"xml2js": "*",
"youtube-node": "1.2.x"
},
"main": "DougBot.js"
}
52 changes: 50 additions & 2 deletions runtime/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var ConfigFile = require("../config.json"),
VerboseLog,
DebugLogger = require("./logger.js").DebugModeLog,
Defaulting = require("./serverdefaulting.js"),
VerboseLogger = require("./logger.js").VerboseModeLog;
VerboseLogger = require("./logger.js").VerboseModeLog,
DJ = require("./djlogic.js");

if (ConfigFile.bot_settings.verbose_logging === true){
VerboseLog = true;
Expand All @@ -27,13 +28,59 @@ Commands.ping = {
name: "ping",
help: "I'll reply to you with pong!",
level: 0,
timeout: 10,
fn: function(bot, msg){
if (VerboseLog === true) {
VerboseLogger.debug("VERBOSE LOG: Ping is being executed.");
}
bot.sendMessage(msg.channel, "Pong!");
}};

Commands["join-voice"] = {
name: "join-voice",
help: "I'll join a voice channel!",
level: 3,
fn: function(bot, msg){
if (VerboseLog === true) {
VerboseLogger.debug("VERBOSE LOG: JoinVoice is being executed.");
}
DJ.joinVoice(bot, msg);
}};

Commands.play = {
name: "play",
help: "I'll play a weblink containing music!",
usage: "<web-url>",
level: 2,
fn: function(bot, msg){
if (VerboseLog === true) {
VerboseLogger.debug("VERBOSE LOG: Play is being executed.");
}
DJ.playMusicURL(bot, msg);
}};

Commands.stop = {
name: "stop",
help: "I'll stop playing music.",
level: 3,
fn: function(bot, msg){
if (VerboseLog === true) {
VerboseLogger.debug("VERBOSE LOG: Stop is being executed.");
}
DJ.stopPlaying(msg);
}};

Commands["leave-voice"] = {
name: "stop",

This comment has been minimized.

Copy link
@Dougley

Dougley Jan 18, 2016

Member

Lol good attention span Dougley

help: "I'll stop playing music.",
level: 3,
fn: function(bot, msg){
if (VerboseLog === true) {
VerboseLogger.debug("VERBOSE LOG: LeaveVoice is being executed.");
}
DJ.leaveVoice(bot, msg);
}};

Commands.setstatus = {
name: "setstatus",
help: "This will change my current status to something else",
Expand Down Expand Up @@ -777,8 +824,9 @@ Commands.imglist = {
}
var fs = require("fs");
var path = require("path");
var ext = [".jpg", ".jpeg", ".gif", ".png"];
var imgArray = [];
fs.readdir(imgDirectory, function(err, dirContents) {
fs.readdir("./images", function(err, dirContents) {
for (var i = 0; i < dirContents.length; i++) {
for (var o = 0; o < ext.length; o++) {
if (path.extname(dirContents[i]) === ext[o]) {
Expand Down
62 changes: 62 additions & 0 deletions runtime/djlogic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var Discord = require("discord.js"),
bot = new Discord.Client(),
request = require("request"),
boundChannel = false,
stream = false,
vol = 0.25;

exports.joinVoice = function(bot, message){
if (boundChannel) return;
var channelToJoin = spliceArguments(message.content)[1];
for (var channel of message.channel.server.channels) {
if (channel instanceof Discord.VoiceChannel) {
if (!channelToJoin || channel.name === channelToJoin) {
boundChannel = message.channel;
bot.reply(message, `Binding to text channel <#${boundChannel.id}> and voice channel **${channel.name}** \`(${channel.id})\``);
bot.joinVoiceChannel(channel);
break;
}
}
}
};

exports.playMusicURL = function(bot, message){
var url = message.content.split(" ")[1];
bot.voiceConnection.playFile(url,{
volume : 0.25,
stereo : true
});
bot.reply(message, "Now playing " + url);
bot.voiceConnection.emit("end");
bot.sendMessage("Stream has ended");
};

exports.stopPlaying = function(message){
if (!message.channel.equals(boundChannel)) return;
stopped();
stream = false;
};

exports.leaveVoice = function(bot, message){
if (!message.channel.equals(boundChannel)) return;
if (!boundChannel)
bot.sendMessage(message, "Can't leave what I'm not in!");
if (!boundChannel) return;
bot.reply(message, `Unbinding from <#${boundChannel.id}> and destroying voice connection`);
bot.leaveVoiceChannel();
boundChannel = false;
stream = false;
return;
};

function spliceArguments(message, after) {
after = after || 1;
var rest = message.split(' ');
var removed = rest.splice(0, after);
return [removed.join(' '), rest.join(' ')];
}

function stopped(){
if (bot.internal.voiceConnection) bot.internal.voiceConnection.stopPlaying();
boundChannel.sendMessage("Stream has ended");
}
4 changes: 3 additions & 1 deletion runtime/dummychecking.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
//TODO: Actually make functions here, lmao
exports.checkConfig = function(){
// TODO: Finish this function :)
};
62 changes: 31 additions & 31 deletions runtime/permissions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
var ConfigFile = require("../config.json");
var Redis = require("redis");
var Logger = require("./logger.js").Logger;
var ConfigFile = require("../config.json"),
LevelUP = require("levelup"),
Logger = require("./logger.js").Logger;

if (ConfigFile.redis.url && !ConfigFile.redis.host) {
var RedisServer = Redis.createClient(ConfigFile.redis.url);
} else {
var RedisServer = Redis.createClient(ConfigFile.redis.port, ConfigFile.redis.host);
}
var db = LevelUP('./runtime/databases/discord_permissions');

exports.GetLevel = function(sum, user, callback){
if (user === ConfigFile.permissions.masterUser){
Expand All @@ -21,54 +17,58 @@ exports.GetLevel = function(sum, user, callback){
if (user == ConfigFile.permissions.level3){
return callback (null, 3); // Hardcoded reply if user has a global permission
}
// Else, connect to the Redis server and fetch the user level
RedisServer.get("auth_level:" + sum, function(err, reply) {
// Else, connect to LevelUP and fetch the user level
db.get("auth_level:" + sum, function(err, value) {
if (err) {
return callback(err, -1);
}
if (reply) {
return callback(null, parseInt(reply));
} else {
callback(null, 0); // Return 0 if no value present in Redis
if (err.notFound) {
callback(null, 0); // Return 0 if no value present in LevelUP
return;
} else {
Logger.error("LevelUP error! " + err);
callback(err, -1);
}}
if (value) {
return callback(null, parseInt(value));
}
});
};

exports.GetNSFW = function(channel, callback){
RedisServer.get("auth_nsfw:" + channel, function(err, reply) {
db.get("auth_nsfw:" + channel, function(err, value) {
if (err) {
return callback(err, -1);
}
if (reply) {
return callback(null, reply);
if (err.notFound) {
callback(null, "off"); // Return 0 if no value present in LevelUP
return;
} else {
callback(null, "off");
Logger.error("LevelUP error! " + err);
callback(err, -1);
}}
if (value) {
return callback(null, value);
}
});
};

exports.SetLevel = function(sum, level, callback){
RedisServer.set("auth_level:" + sum, parseInt(level), function(err, reply) {
db.put("auth_level:" + sum, parseInt(level), function(err) {
if (err) {
Logger.error("LevelUP error! " + err);
callback(err, -1);
}
if (reply) {
if (!err) {
callback(null, parseInt(level));
} else {
return callback(null, 0);
}
});
};

exports.SetNSFW = function(channel, allow, callback){
RedisServer.set("auth_nsfw:" + channel, allow, function(err, reply) {
db.put("auth_nsfw:" + channel, allow, function(err) {
if (err) {
Logger.error("LevelUP error! " + err);
callback(err, -1);
}
if (reply) {
if (!err) {
callback(null, allow);
} else {
return callback(null, null);
}
}
});
};
2 changes: 1 addition & 1 deletion runtime/serverdefaulting.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports.fetch = function(callback){ // TODO: This is the most ridicolous method
callback(ServerID);
};

exports.check = function(callback){
exports.check = function(callback){ // TODO: Make more reliable, meant to fetch servers in which bot is the owner
var oldServers = [];
for (var owner in bot.servers) {
oldServers[owner] = bot.servers[owner];
Expand Down
Loading

0 comments on commit 0b50786

Please sign in to comment.