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 Jan 16, 2016
1 parent 54c377b commit 4e00864
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.0.0-beta.5
Fixes several problems caused by 2.0.0-beta.4
Added an *incomplete* server defaulting system.
Added `setstatus`.
Changed the fixed length of `cmd_prefix` to a dynamic length.
Changed the fixed character prefix to switch to mention activation if desired.

## 2.0.0-beta.4
Fixed `myapifilms_token` not existing.
Fixed problems with `++setowner`.
Expand Down
33 changes: 23 additions & 10 deletions DougBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var VersionChecker = require("./runtime/versionchecker.js");
var forever = require("forever");
var DebugMode;
var VerboseLog;
var Defaulting = require("./runtime/serverdefaulting.js");

// Declare if debug mode or verbose logging is needed
if (ConfigFile.bot_settings.debug_mode === true){
Expand Down Expand Up @@ -62,6 +63,10 @@ bot.on("ready", function() {
if (DebugMode === true){
DebugLogger.debug("DEBUG MODE LOG: Ready event fired.");
}
if (bot.servers.length === 0){
Logger.warn("No servers deteted, creating default server.");
Defaulting.create(bot);
}
Logger.info("Joining pre-defined servers...");
for (var index in ConfigFile.join_on_launch){
bot.joinServer(ConfigFile.join_on_launch[index], function(error, server){
Expand Down Expand Up @@ -92,14 +97,22 @@ bot.on("message", function(msg) {
if (msg.author.equals(bot.user)) {
return;
}
var prefix = ConfigFile.bot_settings.cmd_prefix.split("");
if (msg.content.charAt(0) === prefix[0]) {
if (msg.content.charAt(1) === prefix[1] ){
var prefix;
if (ConfigFile.bot_settings.cmd_prefix != "mention"){
prefix = ConfigFile.bot_settings.cmd_prefix;
} else if (ConfigFile.bot_settings.cmd_prefix === "mention") {
prefix = bot.user + " ";
} else {
if (DebugMode === true){
DebugLogger.debug("DEBUG MODE LOG: Weird prefix detected.");
}
}
if (msg.content.search(prefix) === 0) {
Logger.info("Executing <" + msg.content + "> from " + msg.author.username);
var step = msg.content.substr(2);
var step = msg.content.substr(prefix.length);
var chunks = step.split(" ");
var command = chunks[0];
var suffix = msg.content.substring(command.length + 3);
var suffix = msg.content.substring(command.length + (prefix.length + 1));
if (command === "help"){
Commands.help.fn(bot, msg, suffix);
return;
Expand Down Expand Up @@ -156,10 +169,10 @@ bot.on("message", function(msg) {
if (DebugMode === true){
DebugLogger.debug("DEBUG MODE LOG: User has no permission to use that command.");
}
bot.sendMessage(msg.channel, "You don't have permission to use this command!");
return;
}
});
bot.sendMessage(msg.channel, "You don't have permission to use this command!");
return;
}
});
} 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){
Expand All @@ -186,7 +199,7 @@ bot.on("message", function(msg) {
}
});
}
}}}});
}}});

// Initial functions
function init(token) {
Expand Down
20 changes: 16 additions & 4 deletions config.example.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"useful_comments": [
"Please only enable debug_mode or verbose_logging if requested by one of the devs, as enabling this extends the logging capabilities and could potentially include sensitive info.",
"Command prefixes are double prefix activation ONLY.",
"Command prefixes are length dynamic, meaning that prefixes can be as long as you want, change the value to `mention` to switch to mention activation.",
"There can only be 1 master user, 1 global level 1 user, etc.",
"If you define a different path to the image or music directory, type it like this:", "C:\\Users\\foobar\\Music",
"help_mode can either be `private` or `channel`",
"auto_restart tries to reconnect to Discord after an error or disconnection automatically."
"auto_restart tries to reconnect to Discord after an error or disconnection automatically.",
"default_server is a server the bot will create at first run, with this you can have a central contol hub for your bot.",
"error_printing, periodic_statistics and all of the overrides don't do anything yet.",
"If the channel entered in print_to_which_channel doens't exist, the bot will create it."
],

"discord" : {
Expand All @@ -19,9 +22,18 @@
"verbose_logging": false,
"auto_restart": false,
"debug_mode": false,
"welcome_new_members": false,
"image_folder": "./images",
"music_folder": "./music"
},
"default_server" : {
"error_printing": true,
"periodic_statistics": true,
"print_to_which_channel": "logbook",
"override_timeouts": false,
"override_permissions": false,
"override_nsfw": false
},
"join_on_launch" : [
"https://discord.gg/0cFoiR5QVh4agupi",
"https://discord.gg/0cFoiR5QVh57Spqg"
Expand All @@ -30,7 +42,7 @@
"google_key": "Create one here: https://console.developers.google.com",
"cse_key": "https://github.com/SteamingMutt/DougleyBot/wiki/CSE",
"mashape_key": "https://market.mashape.com/dashboard",
"myapifilms_token": "token",
"myapifilms_token": "token"
},
"imgflip" : {
"username": "foobar",
Expand All @@ -46,5 +58,5 @@
"host" : "localhost",
"port" : 6379,
"url" : "If you need to connect to a Redis URL, use this key and remove `host` and `port`, if you don't need this, remove this key and the comma at the end of `port`"
},
}
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DougleyBot",
"version": "2.0.0-beta.4",
"version": "2.0.0-beta.5",
"description": "A Discord bot",
"readme": "README.md",
"maintainers": ["Perpetucake"],
Expand All @@ -15,7 +15,6 @@
"winston": "^1.1.1",
"cleverbot-node": "0.2.x",
"request": "^2.61.0",
"ws": "^0.8.0",
"xml2js": "*",
"leetspeak": "*",
"imgflipper": "*",
Expand Down
69 changes: 54 additions & 15 deletions runtime/commands.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
var ConfigFile = require("../config.json");
var Logger = require("./logger.js").Logger;
var Permissions = require("./permissions.js");
var imgDirectory = require("../config.json").image_folder;
var Giphy = require("./giphy.js");
var Cleverbot = require('cleverbot-node');
var cleverbot = new Cleverbot();
var yt = require("./youtube_plugin");
var youtube_plugin = new yt();
var version = require("../package.json").version;
var unirest = require('unirest');
var VerboseLog = require("../DougBot.js").VerboseLog;
var DebugLog = require("../DougBot.js").DebugLog;
var DebugLogger = require("./logger.js").DebugModeLog;
var VerboseLogger = require("./logger.js").VerboseModeLog;
var ConfigFile = require("../config.json"),
Logger = require("./logger.js").Logger,
Permissions = require("./permissions.js"),
imgDirectory = require("../config.json").image_folder,
Giphy = require("./giphy.js"),
Cleverbot = require('cleverbot-node'),
cleverbot = new Cleverbot(),
yt = require("./youtube_plugin"),
youtube_plugin = new yt(),
version = require("../package.json").version,
unirest = require('unirest'),
DebugMode,
VerboseLog,
DebugLogger = require("./logger.js").DebugModeLog,
Defaulting = require("./serverdefaulting.js"),
VerboseLogger = require("./logger.js").VerboseModeLog;

if (ConfigFile.bot_settings.verbose_logging === true){
VerboseLog = true;
} else {
VerboseLog = false;
}

var Commands = [];

Expand All @@ -27,6 +34,38 @@ Commands.ping = {
bot.sendMessage(msg.channel, "Pong!");
}};

Commands.setstatus = {
name: "setstatus",
help: "This will change my current status to something else",
usage: "<online / away> [playing status]",
level: 4,
fn: function(bot, msg, suffix){
var step = suffix.split(" "),
status = step[0],
playingstep = step.slice(1, step.length),
playing = playingstep.join(" ");
if (VerboseLog === true) {
VerboseLogger.debug("VERBOSE LOG: SetStatus is being executed.");
}
if (!suffix){
bot.sendMessage(msg.channel, "You need a suffix, dummy!");
return;
}
if (status !== "online" && suffix !== "away"){
bot.sendMessage(msg.channel, "I can only be `online` or `away`!");
return;
}
bot.setStatus(status, playing, function(error){
if (error){
bot.sendMessage(msg.channel, "Whoops, that doesn't work, try again.");
} else if (playing) {
bot.sendMessage(msg.channel, "Okay, I'm now " + status + " and playing " + playing);
} else {
bot.sendMessage(msg.channel, "Okay, I'm now " + status + ".");
}
});
}};

Commands.fortunecow = {
name: "fortunecow",
help: "I'll get a random fortunecow!",
Expand Down
1 change: 1 addition & 0 deletions runtime/dummychecking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//TODO: Actually make functions here, lmao
66 changes: 66 additions & 0 deletions runtime/serverdefaulting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var Discord = require("discord.js"),
bot = new Discord.Client(),
ConfigFile = require("../config.json"),
Logger = require("./logger.js").Logger,
DebugLogger = require("./logger.js").DebugModeLog,
LogBookID,
ServerID;

exports.create = function(bot){
Logger.info("Creating default server...");
bot.createServer(bot.user.username + " Base Camp", "london", function(error, server){
if (server){
Logger.info("Default server sucessfully created.");
var msgArray = [];
msgArray.push("Hello! My name is " + bot.user.username + ", welcome to my base camp!");
msgArray.push("With this server, you can monitor and contol the bot.");
msgArray.push("`leave` will not function in this server, as I'm the owner of this server, so be assured that I'll always be in at least 1 server.");
msgArray.push("There are some special commands that only work in this server, `adminme` for example if you're my master."); // TODO: Not yet actually, I haven't done that yet.
msgArray.push("Thanks for choosing DougleyBot as your framework, have fun!");
bot.sendMessage(server.defaultChannel, msgArray);
var step = ConfigFile.default_server.print_to_which_channel.split(" ");
bot.createChannel(server, step.join("-"), function(channel, error){
if (channel){
Logger.info("Logbook channel sucessfully created.");
LogBookID = channel.id;
} else if (error){
Logger.error("Creating the logbook channel failed, got error: " + error);
}
});
bot.createInvite(server.defaultChannel, function(error, invite){
if (invite){
Logger.info("Default server sucessfully created, invite: " + invite);
} else if (error){
Logger.error("Creating the invite for the default server failed, try manually making an invite via my account, got error: " + error);
}
});
} else if (error){
Logger.error("Creating the default server failed, got error: " + error);
}
});
};

exports.logbook = function(entry, user, server){
Logger.info("About to log something to the logbook: " + entry);
var msgArray = [];
msgArray.push("New logbook entry:");
msgArray.push("```" + entry + "```");
msgArray.push("Triggered by " + user + " in server " + server);
bot.sendMessage(LogBookID, msgArray);
};

exports.fetch = function(callback){ // TODO: This is the most ridicolous method to fetch this, change to a more sensible method.
callback(ServerID);
};

exports.check = function(callback){
var oldServers = [];
for (var owner in bot.servers) {
oldServers[owner] = bot.servers[owner];
if (oldServers.indexOf(bot.user) !== -1) {
return callback(true);
} else {
return callback(false);
}
}
};

0 comments on commit 4e00864

Please sign in to comment.