Skip to content

Commit

Permalink
merge exp to master (#308)
Browse files Browse the repository at this point in the history
* One get for guild data.

* Rename permissions.js to database/controllers/permissions.js

* I hate github

* Update permissions.js

* Whoops

* So done.

* Fix rule34, mention command bug, and spacing

* Fixes an issue with prefix in DMs, not the right way but hot patch until proper rewrite.

* closes #299 and a couple little things.

* buffer ay yo

* it picked on me for litle things!

* now we got buffering and prefix fix yet again

* wow

* prefix was wrong in the "use [prefix]request to add more songs"

* bye bye ytdl-core.

* left in some console.logs

* bad logic is bad

* whoops forgot about them ECONNRESETS

* You forced this on yourselves.

* whoops ear rape

* ugh this command is broken again

* cucked by standard

* whatever

* memleaks

* idk maybe get rid of the type error

* welcomeChannel customize method

* accommodate changes to rule34 api
  • Loading branch information
zaza7 authored Jan 10, 2018
1 parent f5ac516 commit 830278d
Show file tree
Hide file tree
Showing 9 changed files with 470 additions and 395 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# 4.0.0
## Release phase

### 4.5.0
Improvements to command handler.
Improvement to permissions database controller.
Improvement to customize database controller.
Improvement to join-voice command.
Improvement to songs playing.

### 4.4.0
Improvements to help handler.
Added aliases to `dogfact` and `catfact`.
Expand Down
26 changes: 17 additions & 9 deletions DougBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,21 @@ bot.Dispatcher.on(Event.GUILD_MEMBER_ADD, function (s) {
datacontrol.customize.isKnown(s.guild)
datacontrol.customize.check(s.guild).then((r) => {
if (r === 'on' || r === 'channel') {
datacontrol.customize.reply(s, 'welcomeMessage').then((x) => {
if (x === null || x === 'default') {
s.guild.generalChannel.sendMessage(`Welcome ${s.member.username} to ${s.guild.name}!`)
} else {
s.guild.generalChannel.sendMessage(x.replace(/%user/g, s.member.mention).replace(/%server/g, s.guild.name))
}
}).catch((e) => {
Logger.error(e)
datacontrol.customize.reply(s, 'welcomeChannel').then(rep => {
datacontrol.customize.reply(s, 'welcomeMessage').then((x) => {
var channel = s.guild.channels.find(g => g.id === rep)
if (!channel) return
if (x === null || x === 'default') {
channel.sendMessage(`Welcome ${s.member.username} to ${s.guild.name}!`)
} else {
channel.sendMessage(x.replace(/%user/g, s.member.mention).replace(/%server/g, s.guild.name))
}
}).catch((e) => {
Logger.error(e)
})
}).catch(e => {
if (e === 'Unsupported reply method') return // oh well
else Logger.error(e)
})
} else if (r === 'private') {
datacontrol.customize.reply(s, 'welcomeMessage').then((x) => {
Expand Down Expand Up @@ -333,7 +340,8 @@ bot.Dispatcher.onAny((type, data) => {

process.on('unhandledRejection', (reason, p) => {
if (p !== null && reason !== null) {
bugsnag.notify(new Error(`Unhandled promise: ${require('util').inspect(p, {depth: 3})}: ${reason}`))
if (reason instanceof Error) bugsnag.notify(reason)
else bugsnag.notify(new Error(`Unhandlled promise: ${require('util').inspect(p, {depth: 3})}: ${reason}`))
}
})

Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "WildBeast",
"version": "4.4.0",
"version": "4.5.0",
"description": "A Discord Bot",
"main": "DougBot.js",
"maintainers": [
Expand Down Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"bugsnag": "^1.9.0",
"cleverbot.io": "^1.0.4",
"discordie": "qeled/discordie#dev",
"discordie": "github:qeled/discordie#dev",
"imgflipper": "^1.0.1",
"leetspeak": "0.0.1",
"minimist": "^1.2.0",
Expand All @@ -53,8 +53,7 @@
"winston-elasticsearch": "^0.5.0",
"xml2js": "^0.4.16",
"youtube-api": "^2.0.2",
"youtube-dl": "^1.11.1",
"ytdl-core": "^0.17.0"
"youtube-dl": "^1.11.1"
},
"devDependencies": {
"eslint": "^4.1.0",
Expand Down
96 changes: 55 additions & 41 deletions runtime/commands/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getUptime () {

Commands.ping = {
name: 'ping',
help: "I'll reply to you with pong!",
help: 'I\'ll reply to you with pong!',
timeout: 10,
level: 0,
fn: function (msg) {
Expand Down Expand Up @@ -204,27 +204,27 @@ Commands.twitch = {
}
var url = 'https://api.twitch.tv/kraken/streams/' + suffix
request.get(url)
.set({'Accept': 'application/vnd.twitchtv.v3+json', 'Client-ID': config.api_keys.twitchId})
.end((error, response) => {
if (error) {
bugsnag.notify(error)
}
if (!error && response.statusCode === 200) {
var resp
try {
resp = response.body
} catch (e) {
msg.channel.sendMessage('The API returned an unconventional response.')
.set({'Accept': 'application/vnd.twitchtv.v3+json', 'Client-ID': config.api_keys.twitchId})
.end((error, response) => {
if (error) {
bugsnag.notify(error)
}
if (resp.stream !== null) {
msg.channel.sendMessage(suffix + ' is currently live at https://www.twitch.tv/' + suffix)
} else if (resp.stream === null) {
msg.channel.sendMessage(suffix + ' is not currently streaming')
if (!error && response.statusCode === 200) {
var resp
try {
resp = response.body
} catch (e) {
msg.channel.sendMessage('The API returned an unconventional response.')
}
if (resp.stream !== null) {
msg.channel.sendMessage(suffix + ' is currently live at https://www.twitch.tv/' + suffix)
} else if (resp.stream === null) {
msg.channel.sendMessage(suffix + ' is not currently streaming')
}
} else if (!error && response.statusCode === 404) {
msg.channel.sendMessage('Channel does not exist!')
}
} else if (!error && response.statusCode === 404) {
msg.channel.sendMessage('Channel does not exist!')
}
})
})
}
}

Expand Down Expand Up @@ -256,7 +256,7 @@ Commands.customize = {

Commands.info = {
name: 'info',
help: "I'll print some information about me.",
help: 'I\'ll print some information about me.',
timeout: 10,
level: 0,
fn: function (msg, suffix, bot) {
Expand Down Expand Up @@ -292,7 +292,7 @@ Commands.info = {

Commands['leave-server'] = {
name: 'leave-server',
help: "I'll leave this server if I am not welcome here.",
help: 'I\'ll leave this server if I am not welcome here.',
noDM: true,
level: 3,
fn: function (msg) {
Expand Down Expand Up @@ -350,9 +350,9 @@ Commands.setlevel = {
} else if (msg.mentions.filter(m => m.id !== bot.User.id).length === 0 && msg.mention_roles.length === 0 && !msg.mention_everyone) {
msg.reply('Please @mention the user(s)/role(s) you want to set the permission level of.')
} else if (msg.mentions.filter(m => m.id !== bot.User.id).length === 1 && msg.mentions.filter(m => m.id !== bot.User.id)[0].id === msg.guild.owner.id) {
msg.reply("You cannot set the server owner's level.")
msg.reply('You cannot set the server owner\'s level.')
} else if (msg.mentions.filter(m => m.id !== bot.User.id).length === 1 && msg.mentions.filter(m => m.id !== bot.User.id)[0].id === bot.User.id) {
msg.reply("I don't need any level set, I can do anything regardless of access levels.")
msg.reply('I don\'t need any level set, I can do anything regardless of access levels.')
} else {
Permissions.adjustLevel(msg, msg.mentions, parseFloat(suffix[0]), msg.mention_roles).then(function () {
msg.channel.sendMessage('Alright! The permission levels have been set successfully!')
Expand Down Expand Up @@ -484,24 +484,24 @@ Commands.setnsfw = {
msg.channel.sendMessage('NSFW commands are now disallowed for ' + msg.channel.mention)
}
}).catch(() => {
msg.reply("I've failed to set NSFW flag!")
msg.reply('I\'ve failed to set NSFW flag!')
})
} else {
msg.channel.sendMessage('Use either `on` or `off` as suffix!')
}
} else {
msg.channel.sendMessage("NSFW commands are always allowed in DM's.")
msg.channel.sendMessage('NSFW commands are always allowed in DM\'s.')
}
}
}

Commands.hello = {
name: 'hello',
help: "I'll respond to you with hello along with a GitHub link!",
help: 'I\'ll respond to you with hello along with a GitHub link!',
timeout: 20,
level: 0,
fn: function (msg, suffix, bot) {
msg.channel.sendMessage('Hi ' + msg.author.username + ", I'm " + bot.User.username + ' and I was developed by the team over at TheSharks! Improve me by contributing to my source code on GitHub: https://github.com/TheSharks/WildBeast')
msg.channel.sendMessage('Hi ' + msg.author.username + ', I\'m ' + bot.User.username + ' and I was developed by the team over at TheSharks! Improve me by contributing to my source code on GitHub: https://github.com/TheSharks/WildBeast')
}
}

Expand Down Expand Up @@ -541,7 +541,7 @@ Commands.setstatus = {

Commands['server-info'] = {
name: 'server-info',
help: "I'll tell you some information about the server you're currently in.",
help: 'I\'ll tell you some information about the server you\'re currently in.',
aliases: ['serverinfo'],
noDM: true,
timeout: 20,
Expand All @@ -550,7 +550,11 @@ Commands['server-info'] = {
// if we're not in a PM, return some info about the channel
if (msg.guild) {
var field = [{name: 'Server name', value: `${msg.guild.name} [${msg.guild.acronym}] (${msg.guild.id})`},
{name: 'Owned by', value: '```\n' + `${msg.guild.owner.username}#${msg.guild.owner.discriminator} (${msg.guild.owner.id})` + '```', inline: true},
{
name: 'Owned by',
value: '```\n' + `${msg.guild.owner.username}#${msg.guild.owner.discriminator} (${msg.guild.owner.id})` + '```',
inline: true
},
{name: 'Current Region', value: '```\n' + msg.guild.region + '```', inline: true},
{name: 'Members', value: '```\n' + msg.guild.members.length + '```', inline: true},
{name: 'Text Channels', value: '```\n' + msg.guild.textChannels.length + '```', inline: true},
Expand All @@ -560,7 +564,10 @@ Commands['server-info'] = {
if (msg.guild.afk_channel === null) {
field.push({name: 'AFK-Channel', value: '```\nNone```'})
} else {
field.push({name: 'AFK-channel', value: '```\n' + `${msg.guild.afk_channel.name} (${msg.guild.afk_channel.id})` + '```'})
field.push({
name: 'AFK-channel',
value: '```\n' + `${msg.guild.afk_channel.name} (${msg.guild.afk_channel.id})` + '```'
})
}
var embed = {
author: {name: `Information requested by ${msg.author.username}`},
Expand All @@ -575,24 +582,26 @@ Commands['server-info'] = {
}
msg.channel.sendMessage('', false, embed)
} else {
msg.channel.sendMessage("You can't do that in a DM, dummy!")
msg.channel.sendMessage('You can\'t do that in a DM, dummy!')
}
}
}

Commands.userinfo = {
name: 'userinfo',
help: "I'll get some information about the user you've mentioned.",
help: 'I\'ll get some information about the user you\'ve mentioned.',
noDM: true,
level: 0,
fn: function (msg, suffix, bot) {
var Permissions = require('../databases/controllers/permissions.js')
if (msg.isPrivate) {
msg.channel.sendMessage("Sorry you can't use this in DMs")
msg.channel.sendMessage('Sorry you can\'t use this in DMs')
}
if (msg.mentions.filter(m => m.id !== bot.User.id).length === 0) {
Permissions.checkLevel(msg, msg.author.id, msg.member.roles).then((level) => {
var tempRoles = msg.member.roles.sort(function (a, b) { return a.position - b.position }).reverse()
var tempRoles = msg.member.roles.sort(function (a, b) {
return a.position - b.position
}).reverse()
var roles = []
for (var i in tempRoles) {
roles.push(tempRoles[i].name)
Expand Down Expand Up @@ -628,7 +637,9 @@ Commands.userinfo = {
Permissions.checkLevel(msg, user.id, user.memberOf(msg.guild).roles).then(function (level) {
var guild = msg.guild
var member = guild.members.find((m) => m.id === user.id)
var tempRoles = member.roles.sort(function (a, b) { return a.position - b.position }).reverse()
var tempRoles = member.roles.sort(function (a, b) {
return a.position - b.position
}).reverse()
var roles = []
for (var i in tempRoles) {
roles.push(tempRoles[i].name)
Expand Down Expand Up @@ -664,13 +675,13 @@ 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.",
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'],
usage: '<bot-mention> <instant-invite>',
level: 0,
fn: function (msg, suffix, bot) {
if (bot.User.bot) {
msg.channel.sendMessage("Sorry, bot accounts can't accept instant invites, instead, use my OAuth URL: <" + config.bot.oauth + '>')
msg.channel.sendMessage('Sorry, bot accounts can\'t accept instant invites, instead, use my OAuth URL: <' + config.bot.oauth + '>')
} else {
Logger.warn('Using user accounts is deprecated!')
}
Expand Down Expand Up @@ -844,7 +855,8 @@ Commands.softban = {
let banMembers = {success: [], error: []}
let reasonWords = []
suffix.split(' ').map((id) => {
if (id.startsWith('<@')) {} else {
if (id.startsWith('<@')) {
} else {
reasonWords.push(id)
}
})
Expand Down Expand Up @@ -939,7 +951,7 @@ Commands.softban = {

Commands.prefix = {
name: 'prefix',
help: "If you, despite reading this have no clue what my prefix is, I'll tell you!",
help: 'If you, despite reading this have no clue what my prefix is, I\'ll tell you!',
timeout: 5,
level: 0,
fn: function (msg) {
Expand Down Expand Up @@ -986,7 +998,9 @@ Commands.colorrole = {
msg.reply('I do not have Manage Roles permission here, sorry!')
return
}
var botRole = bot.User.memberOf(msg.guild).roles.sort(function (a, b) { return a.position < b.position })[0]
var botRole = bot.User.memberOf(msg.guild).roles.sort(function (a, b) {
return a.position < b.position
})[0]
if (role.position >= botRole.position) {
msg.reply('This role is higher or equal to my highest role, I cannot color it!')
return
Expand Down
Loading

0 comments on commit 830278d

Please sign in to comment.