From 7e64eaf9f7b86ab0e863d9046993ba9a408053f9 Mon Sep 17 00:00:00 2001
From: Remco
Date: Sun, 8 May 2016 15:21:07 +0200
Subject: [PATCH] 3.0.0-alpha.2
---
CHANGELOG.md | 105 ++++++++++++++++++++++++++++++++++++
DougBot.js | 24 +++++----
README.md | 2 +-
config.example.json | 5 +-
package.json | 4 +-
runtime/commandcontrol.js | 34 ++++++++----
runtime/commands/default.js | 14 ++++-
runtime/commands/fun.js | 6 +++
runtime/commands/music.js | 16 ++++--
runtime/giphy.js | 16 ++----
runtime/internal/voice.js | 4 +-
11 files changed, 185 insertions(+), 45 deletions(-)
create mode 100644 CHANGELOG.md
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 000000000..9d350c472
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,105 @@
+# 3.0.0
+## Alpha phase
+### 3.0.0.alpha.2
+Enabled command alias system.
+Changed giphy endpoint for more randomness.
+Added a `noDM` key.
+
+### 3.0.0-alpha.1
+Initial release, featuring all-new code.
+
+# 2.0.0
+## Release phase
+### 2.1.1
+Added timeouts.
+Changed `request` to only accept full links from now on.
+Made preparations for a future update.
+
+### 2.1.0
+Changed callbacks to promises.
+Removed `playliststart`, playlists start automatically after the first video has been entered.
+Extended timeout for initial join.
+Several small tweaks.
+
+### 2.0.0
+Revamped database system.
+Added token login support for the upcoming official Discord API.
+Added expansive server-specific customization options.
+Added user tracking for namechanges.
+Added an upgrade script for users to upgrade from gamma.7 to 2.0.0
+Removed server defaulting system.
+Removed unneeded and unfinished files in `runtime`.
+Removed unnecessary fluff from `config.json`.
+Removed `welcoming-whitellist.json`, this is now handled by `customize`.
+Removed `birds`, `ìdle` and `online`, `idle` and `online` are replaced with `setstatus`.
+Temporary removed server blacklisting system, this will be reintroduced later.
+
+# 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.7
+Changed welcoming system to adhere to a whitelist instead of being global.
+Added server blacklisting for `join-server`.
+**IMPORTANT** Changed `join-server` to use mentions instead of usernames, the new invocation is `join-server @WildBeast `, change `WildBeast` with your bots username.
+
+### 2.0.0-gamma.6
+Added YouTube playlist support.
+
+### 2.0.0-gamma.5
+Removed `play` and `yt-play`.
+Added playlisting for YouTube video's.
+
+### 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.
+
+### 2.0.0-gamma.2
+Added some extra commands.
+Revamped debug mode and verbose logging.
+Changed `setowner` to set server owner to level 4 instead of level 3.
+Changed commands that where at level 4 to level 5.
+
+### 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.
+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`.
+Added `debug_mode` and `verbose_logging`. *(Note, only enable these on request of the devs!)*
+Added a config value that'll change the way `++help` functions.
+Updated the layout of `config.json`, **meaning that users need to remake their config files.**
+
+### 2.0.0-beta.3
+Fixed `giphy.js` not having requires.
+Fixed `suffix` not behaving accordingly.
+Added `++fortunecow`, `++randomcat`, `++rule34` and `++leetspeak`.
+Added `mashape_key` to `config.json`.
+Removed NSFW flags from commands that did not need them, as this will cause problems with `++help`.
+Removed `deletion.js`, as this is needlessly split.
+
+### 2.0.0-beta.2
+Updated `versionchecker.js` to check for beta updates.
+Moved to double prefix activation instead of single prefix activation as requested by Discord API, we recommend using `++`.
+Bot is also compliant with the [Discord bot best practises](https://github.com/meew0/discord-bot-best-practices), also requested by Discord API.
+
+### 2.0.0-beta.1
+Initial release of DougBot 2.0, featuring new permission system and stability improvements.
+
+## Alpha phase
+Nothing too interesting lol.
diff --git a/DougBot.js b/DougBot.js
index a9bc924f1..1275b8cff 100644
--- a/DougBot.js
+++ b/DougBot.js
@@ -7,6 +7,7 @@ var runtime = require('./runtime/runtime.js')
var Logger = runtime.internal.logger.Logger
var timeout = runtime.internal.timeouts
var commands = runtime.commandcontrol.Commands
+var aliases = runtime.commandcontrol.Aliases
var datacontrol = runtime.datacontrol
var argv = require('minimist')(process.argv.slice(2))
var Config
@@ -47,7 +48,7 @@ if (!argv.forceupgrade) {
bot.Dispatcher.on(Event.GATEWAY_READY, function () {
Logger.info('Ready to start!')
- Logger.info(`Logged in as ${bot.User.username} (ID: ${bot.User.id}) and serving ${bot.Users.length} users in ${bot.Guilds.length} servers.`)
+ Logger.info(`Logged in as ${bot.User.username}#${bot.User.discriminator} (ID: ${bot.User.id}) and serving ${bot.Users.length} users in ${bot.Guilds.length} servers.`)
})
bot.Dispatcher.on(Event.MESSAGE_CREATE, function (c) {
@@ -56,19 +57,15 @@ bot.Dispatcher.on(Event.MESSAGE_CREATE, function (c) {
var prefix
datacontrol.customize.prefix(c.message).then(function (r) {
if (!r) {
- prefix = [Config.settings.prefix, null]
+ prefix = Config.settings.prefix
} else {
- prefix = [Config.settings.prefix, r]
+ prefix = r
}
var cmd
var suffix
- if (c.message.content.indexOf(prefix[0]) === 0) {
- cmd = c.message.content.substr(prefix[0].length).split(' ')[0]
- suffix = c.message.content.substr(prefix[0].length).split(' ')
- suffix = suffix.slice(1, suffix.length).join(' ')
- } else if (c.message.content.indexOf(prefix[1]) === 0) {
- cmd = c.message.content.substr(prefix[1].length).split(' ')[0]
- suffix = c.message.content.substr(prefix[1].length).split(' ')
+ if (c.message.content.indexOf(prefix) === 0) {
+ cmd = c.message.content.substr(prefix.length).split(' ')[0]
+ suffix = c.message.content.substr(prefix.length).split(' ')
suffix = suffix.slice(1, suffix.length).join(' ')
} else if (c.message.content.indexOf(bot.User.mention) === 0) {
cmd = c.message.content.substr(bot.User.mention.length + 1).split(' ')[0]
@@ -85,6 +82,9 @@ bot.Dispatcher.on(Event.MESSAGE_CREATE, function (c) {
if (cmd === 'help') {
runtime.commandcontrol.helpHandle(c.message, suffix)
}
+ if (aliases[cmd]) {
+ cmd = aliases[cmd].name
+ }
if (commands[cmd]) {
if (typeof commands[cmd] !== 'object') {
return // ignore JS build-in array functions
@@ -149,6 +149,10 @@ bot.Dispatcher.on(Event.MESSAGE_CREATE, function (c) {
}
})
} else {
+ if (commands[cmd].noDM) {
+ c.message.channel.sendMessage('This command cannot be used in DM.')
+ return
+ }
datacontrol.permissions.checkLevel(c.message, c.message.author.id).then(function (r) {
if (r >= commands[cmd].level) {
try {
diff --git a/README.md b/README.md
index 49d73113a..cfee323a7 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ WildBeast
-
+
diff --git a/config.example.json b/config.example.json
index 2fa68665a..41082a893 100644
--- a/config.example.json
+++ b/config.example.json
@@ -10,7 +10,10 @@
"prefix": "anything can be entered as the global prefix along side mentions"
},
"permissions": {
- "master": ["you need to enter the ID from the user you want as master here", "you can extend this array like this if you need more"]
+ "master": ["you need to enter the ID from the user you want as master here", "you can extend this array like this if you need more"],
+ "level1": [],
+ "level2": [],
+ "level3": []
},
"api_keys": {
"imgflip": {
diff --git a/package.json b/package.json
index 5d254d7e8..8947d1452 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"private": true,
"name": "WildBeast",
- "version": "3.0.0-alpha.1",
+ "version": "3.0.0-alpha.2",
"description": "A Discord Bot",
"main": "DougBot.js",
"maintainers": [
@@ -28,7 +28,7 @@
"url": "git+https://github.com/SteamingMutt/WildBeast.git"
},
"engines": {
- "node": "^5.x.x",
+ "node": "4.x.x - 5.10.1",
"npm": ">=3.x.x"
},
"license": "GPL-3.0",
diff --git a/runtime/commandcontrol.js b/runtime/commandcontrol.js
index 2438bb100..99abdf2d0 100644
--- a/runtime/commandcontrol.js
+++ b/runtime/commandcontrol.js
@@ -8,20 +8,32 @@ var Logger = require('./internal/logger.js').Logger
var commands = []
var alias = []
-for (var i in com) {
- for (var c in com[i].Commands) {
- commands[c] = com[i].Commands[c]
- alias[c] = com[i].Commands[c].aliases
+for (var d in com) {
+ for (var o in com[d].Commands) {
+ commands[o] = com[d].Commands[o]
+ if (com[d].Commands[o].aliases !== undefined) {
+ for (var u in com[d].Commands[o].aliases) {
+ alias[com[d].Commands[o].aliases[u]] = com[d].Commands[o]
+ }
+ }
}
}
+
if (cus !== null) {
- for (var j in cus) {
- for (var f in cus[j].Commands) {
- if (commands[f]) {
+ for (var g in cus) {
+ for (var l in cus[g].Commands) {
+ if (commands[l]) {
throw new Error('Custom commands cannot have the same name as default commands!')
}
- commands[f] = cus[j].Commands[f]
- alias[j] = cus[j].Commands[f].aliases
+ commands[l] = cus[g].Commands[l]
+ if (cus[g].Commands[l].aliases !== undefined) {
+ for (var e in cus[g].Commands[l].aliases) {
+ if (alias[cus[g].Commands[l].aliases[e]]) {
+ throw new Error('Custom commands cannot share aliases with other commands!')
+ }
+ alias[cus[g].Commands[l].aliases[e]] = cus[g].Commands[l]
+ }
+ }
}
}
}
@@ -39,8 +51,8 @@ exports.helpHandle = function (msg, suffix) {
if (!msg.isPrivate) {
msg.channel.sendMessage('Help is underway ' + msg.author.mention + '!')
}
- msg.author.openDM().then((c) => {
- c.sendMessage(msgArray.join('\n'))
+ msg.author.openDM().then((y) => {
+ y.sendMessage(msgArray.join('\n'))
}).catch((e) => {
Logger.error(e)
msg.channel.sendMessage('Whoops, try again.')
diff --git a/runtime/commands/default.js b/runtime/commands/default.js
index 51efa74c5..9d861110e 100644
--- a/runtime/commands/default.js
+++ b/runtime/commands/default.js
@@ -17,6 +17,7 @@ Commands.ping = {
Commands.say = {
name: 'say',
help: 'Repeat after me.',
+ aliases: ['echo', 'repeat'],
module: 'default',
timeout: 10,
level: 0,
@@ -102,6 +103,7 @@ Commands.twitch = {
Commands.customize = {
name: 'customize',
help: 'Adjust my behaviour in this server!',
+ noDM: true,
level: 0,
fn: function (msg, suffix) {
var c = require('../databases/controllers/customize.js')
@@ -132,6 +134,7 @@ Commands.info = {
Commands.leave = {
name: 'leave',
help: "I'll leave this server if I am not welcome here.",
+ noDM: true,
level: 3,
fn: function (msg) {
if (msg.isPrivate) {
@@ -157,6 +160,7 @@ Commands.killswitch = {
Commands.namechanges = {
name: 'namechanges',
help: 'I will tell you the name changes for the user you mention.',
+ noDM: true,
level: 0,
fn: function (msg) {
const n = require('../databases/controllers/users.js')
@@ -175,6 +179,7 @@ Commands.namechanges = {
Commands.setlevel = {
name: 'setlevel',
help: 'This changes the permission level of a user.',
+ noDM: true,
module: 'default',
level: 3,
fn: function (msg, suffix) {
@@ -208,6 +213,7 @@ Commands.setlevel = {
Commands.setnsfw = {
name: 'setnsfw',
help: 'This changes if the channel allows NSFW commands.',
+ noDM: true,
module: 'default',
usage: '',
level: 3,
@@ -286,6 +292,8 @@ Commands.setstatus = {
Commands['server-info'] = {
name: 'server-info',
help: "I'll tell you some information about the server you're currently in.",
+ aliases: ['serverinfo'],
+ noDM: true,
module: 'default',
timeout: 20,
level: 0,
@@ -325,6 +333,7 @@ Commands['server-info'] = {
Commands.userinfo = {
name: 'userinfo',
help: "I'll get some information about the user you've mentioned.",
+ noDM: true,
module: 'default',
level: 0,
fn: function (msg) {
@@ -332,7 +341,6 @@ Commands.userinfo = {
if (msg.isPrivate) {
msg.channel.sendMessage("Sorry you can't use this in DMs")
}
-
if (msg.mentions.length === 0) {
Permissions.checkLevel(msg, msg.author.id).then((level) => {
var msgArray = []
@@ -358,7 +366,6 @@ Commands.userinfo = {
})
return
}
-
msg.mentions.map(function (user) {
Permissions.checkLevel(msg, user.id).then(function (level) {
var msgArray = []
@@ -392,6 +399,7 @@ Commands.userinfo = {
Commands['join-server'] = {
name: 'join-server',
help: "I'll join the server you've requested me to join, as long as the invite is valid and I'm not banned of already in the requested server.",
+ aliases: ['join', 'joinserver', 'invite'],
module: 'default',
usage: ' ',
level: 0,
@@ -445,6 +453,7 @@ Commands['join-server'] = {
Commands.kick = {
name: 'kick',
help: 'Kick the user(s) out of the server!',
+ noDM: true,
module: 'default',
usage: '',
level: 0,
@@ -478,6 +487,7 @@ Commands.kick = {
Commands.ban = {
name: 'ban',
help: 'Swing the banhammer on someone!',
+ noDM: true,
module: 'default',
usage: ' [days]',
level: 0,
diff --git a/runtime/commands/fun.js b/runtime/commands/fun.js
index ce1115dc9..a3290454e 100644
--- a/runtime/commands/fun.js
+++ b/runtime/commands/fun.js
@@ -12,6 +12,7 @@ Cb.prepare(function () {
Commands.gif = {
name: 'gif',
help: "I'll search Giphy for a gif matching your tags.",
+ aliases: ['giphy'],
timeout: 10,
level: 0,
fn: function (msg, suffix) {
@@ -61,6 +62,7 @@ Commands.randomcat = {
Commands.leetspeak = {
name: 'leetspeak',
help: "1'Ll 3nc0d3 Y0uR Me5s@g3 1Nt0 l337sp3@K!",
+ aliases: ['leetspeek', 'leetspeach'],
level: 0,
fn: function (msg, suffix) {
if (suffix.length > 0) {
@@ -132,6 +134,7 @@ Commands.yomomma = {
Commands.advice = {
name: 'advice',
help: "I'll give you some fantastic advice!",
+ noDM: true, // Ratelimits Ratelimits Ratelimits Ratelimits
timeout: 5,
level: 0,
fn: function (msg) {
@@ -176,6 +179,7 @@ Commands.yesno = {
Commands.urbandictionary = {
name: 'urbandictionary',
help: "I'll fetch what idiots on the internet think something means",
+ aliases: ['ud', 'urban'],
timeout: 10,
level: 0,
fn: function (msg, suffix) {
@@ -264,6 +268,7 @@ Commands.dice = {
Commands.fancyinsult = {
name: 'fancyinsult',
help: "I'll insult your friends!",
+ aliases: ['insult'],
timeout: 5,
level: 0,
fn: function (msg, suffix) {
@@ -290,6 +295,7 @@ Commands.fancyinsult = {
Commands.cleverbot = {
name: 'cleverbot',
help: 'Talk to cleverbot!',
+ aliases: ['chat', 'cb', 'talk'],
level: 0,
fn: function (msg, suffix) {
msg.channel.sendTyping()
diff --git a/runtime/commands/music.js b/runtime/commands/music.js
index 58cf4e1e4..323c30f58 100644
--- a/runtime/commands/music.js
+++ b/runtime/commands/music.js
@@ -5,7 +5,8 @@ var Commands = []
Commands.pauseplay = {
name: 'pauseplay',
help: "I'll pause/play the music!",
- timeout: 10,
+ aliases: ['playpause'],
+ noDM: true,
level: 0,
fn: function (msg, suffix, bot) {
v.pausePlay(msg, suffix, bot)
@@ -15,7 +16,8 @@ Commands.pauseplay = {
Commands.volume = {
name: 'volume',
help: "I'll change my volume!",
- timeout: 10,
+ aliases: ['vol'],
+ noDM: true,
level: 0,
fn: function (msg, suffix, bot) {
v.volume(msg, suffix, bot)
@@ -25,7 +27,7 @@ Commands.volume = {
Commands.skip = {
name: 'skip',
help: "I'll skip this song if you don't like it.",
- timeout: 10,
+ noDM: true,
level: 0,
fn: function (msg, suffix, bot) {
v.skip(msg, suffix, bot)
@@ -35,6 +37,8 @@ Commands.skip = {
Commands.playlist = {
name: 'playlist',
help: "I'll fetch you the playlsit I'm currently playing!",
+ aliases: ['list'],
+ noDM: true,
timeout: 10,
level: 0,
fn: function (msg) {
@@ -58,6 +62,8 @@ Commands.playlist = {
Commands.voice = {
name: 'voice',
help: "I'll join a voice channel!",
+ aliases: ['join-voice'],
+ noDM: true,
timeout: 10,
level: 0,
fn: function (msg, suffix, bot) {
@@ -68,7 +74,9 @@ Commands.voice = {
Commands.request = {
name: 'request',
help: 'Use this to request songs!',
- usage: 'Youtube-link',
+ aliases: ['queue'],
+ noDM: true,
+ usage: 'link',
timeout: 10,
level: 0,
fn: function (msg, suffix, bot) {
diff --git a/runtime/giphy.js b/runtime/giphy.js
index a79c00fce..c80bed0fd 100644
--- a/runtime/giphy.js
+++ b/runtime/giphy.js
@@ -1,11 +1,6 @@
-/*
-TODO: Change runtime to be more random
-*/
-
var qs = require('querystring')
exports.get_gif = function (tags, func) {
- // limit=1 will only return 1 gif
var params = {
'api_key': 'dc6zaTOxFJmzC',
'rating': 'r',
@@ -15,21 +10,18 @@ exports.get_gif = function (tags, func) {
var query = qs.stringify(params)
if (tags !== null) {
- query += '&q=' + tags.join('+')
+ query += '&tag=' + tags.join('+')
}
- // wouldnt see request lib if defined at the top for some reason:\
var request = require('request')
- // Logger.log('debug', query)
- request('http://api.giphy.com/v1/gifs/search' + '?' + query, function (error, response, body) {
- // Logger.log('debug', arguments)
+ request('http://api.giphy.com/v1/gifs/random' + '?' + query, function (error, response, body) {
if (error || response.statusCode !== 200) {
// Logger.log('debug', response)
} else {
var responseObj = JSON.parse(body)
- if (responseObj.data.length) {
- func(responseObj.data[0].id)
+ if (responseObj.data) {
+ func(responseObj.data.id)
} else {
func(undefined)
}
diff --git a/runtime/internal/voice.js b/runtime/internal/voice.js
index 96e8e4019..8172f4fcc 100644
--- a/runtime/internal/voice.js
+++ b/runtime/internal/voice.js
@@ -7,7 +7,7 @@ var Config = require('../../config.json')
exports.join = function (msg, suffix, bot) {
if (bot.VoiceConnections.length > 10) {
- msg.channel.sendMessage('Sorry all streaming slots are taken, try again later. :cry:')
+ msg.channel.sendMessage('Sorry, all streaming slots are taken, try again later. :cry:')
} else {
var voiceCheck = bot.VoiceConnections.find((r) => r.voiceConnection.guild.id === msg.guild.id)
if (!voiceCheck && !suffix) {
@@ -104,7 +104,7 @@ function next (msg, suffix, bot) {
}
exports.volume = function (msg, suffix, bot) {
- if (!isNaN(suffix) && suffix <= 100) {
+ if (!isNaN(suffix) && suffix <= 100 && suffix > 0) {
bot.VoiceConnections
.map((connection) => {
if (connection.voiceConnection.guild.id === msg.guild.id) {