diff --git a/core/commands.js b/core/commands.js index e2cfcb2..6d4740a 100644 --- a/core/commands.js +++ b/core/commands.js @@ -15,7 +15,7 @@ const checkCommand = (command, body) => { return true; }; -exports.register = (command, params, description, response) => { +exports.register = (command, params, usage, description, response) => { const compiled = params === '' ? `${command}` : `${command} ${params}`; if (checkCommand(command, params)) { @@ -25,6 +25,7 @@ exports.register = (command, params, description, response) => { description, response, compiled, + usage, }); } }; @@ -60,6 +61,8 @@ const getAllowedRoles = (serverPermissions, userRoles, plugin) => { client.on('message', async (msg) => { const message = msg.content; + if (!msg.guild && msg.author.id !== client.user.id) return msg.reply('I do not work in DMs'); + if (msg.author.id === client.user.id) return false; const serverPrefix = await this.getPrefix(msg.guild.id); const serverPermissions = await permissions.getServerPermissions(msg.guild.id); for (let i = 0; i < registeredCommands.length; i += 1) { @@ -70,9 +73,9 @@ client.on('message', async (msg) => { const plugin = loader.fromCommand(command); const userRoles = msg.member.roles.array(); const allowedRoles = getAllowedRoles(serverPermissions, userRoles, plugin); - if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || allowedRoles >= 1)) { + if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || allowedRoles.length >= 1)) { return command.response(msg, match); } } - return null; + return false; }); diff --git a/core/database.js b/core/database.js index 6160f75..b31c7c9 100644 --- a/core/database.js +++ b/core/database.js @@ -19,13 +19,13 @@ const Server = mongoose.model('Server', { const User = mongoose.model('User', { server: { type: Schema.Types.ObjectId, ref: 'Server' }, - descrim: Number, + discrim: String, }); const UserWarning = mongoose.model('UserWarnings', { user: { type: Schema.Types.ObjectId, ref: 'User' }, warning: String, - warner: Number, + warner: String, }); const Configuration = mongoose.model('Configuration', { diff --git a/plugins/core/help.js b/plugins/core/help.js index 82d57f3..a3d6432 100644 --- a/plugins/core/help.js +++ b/plugins/core/help.js @@ -3,7 +3,7 @@ const { discord } = require('@bot').client; exports.command = 'help'; -commands.register(this.command, '', 'Shows the help message', async (msg) => { +commands.register(this.command, '', 'help', 'Shows the help message', async (msg) => { const modules = loader.getPlugins(); const em = new discord.RichEmbed(); const prefix = await commands.getPrefix(msg.guild.id); @@ -15,7 +15,7 @@ commands.register(this.command, '', 'Shows the help message', async (msg) => { msg.reply(em); }); -commands.register(this.command, '(.*)', 'Shows the help message', async (msg, extra) => { +commands.register(this.command, '(.*)', 'help ', 'Shows the help message', async (msg, extra) => { const module = loader.getPlugin(extra[1]); if (module) { const em = new discord.RichEmbed(); @@ -23,7 +23,7 @@ commands.register(this.command, '(.*)', 'Shows the help message', async (msg, ex const prefix = await commands.getPrefix(msg.guild.id); em.setTitle(`${module.name} | Help`); moduleCommands.forEach((c) => { - em.addField(`${prefix}${c.command} ${c.params}`, `${c.description}`); + em.addField(`${prefix}${c.usage}`, `${c.description}`); }); return msg.channel.send(em); } diff --git a/plugins/core/permission-helper.js b/plugins/core/permission-helper.js index 3ff4180..437c2ba 100644 --- a/plugins/core/permission-helper.js +++ b/plugins/core/permission-helper.js @@ -3,7 +3,7 @@ const { discord } = require('@bot').client; exports.command = 'permissions'; -commands.register(this.command, 'add (.*) (.*)', 'Add permission to a plugin to a role', async (msg, extra) => { +commands.register(this.command, 'add (.*) (.*)', 'permissions add <@role>', 'Add permission to a plugin to a role', async (msg, extra) => { const plugin = loader.getPlugin(extra[1]); if (plugin) { const role = msg.mentions.roles.first(); @@ -16,7 +16,7 @@ commands.register(this.command, 'add (.*) (.*)', 'Add permission to a plugin to return msg.reply('Error plugin does not exist..'); }); -commands.register(this.command, '', 'Permissions help', async (msg) => { +commands.register(this.command, '', 'permissions', 'Permissions help', async (msg) => { const pluginCommands = commands.getCommands('permissions'); const em = new discord.RichEmbed(); const prefix = await commands.getPrefix(); diff --git a/plugins/core/plugin-helper.js b/plugins/core/plugin-helper.js index f261a6e..f9f1475 100644 --- a/plugins/core/plugin-helper.js +++ b/plugins/core/plugin-helper.js @@ -3,7 +3,7 @@ const { discord } = require('@bot').client; exports.command = 'plugins'; -commands.register(this.command, 'toggle (.*)', 'Toggle a plugin.', (msg, extra) => { +commands.register(this.command, 'toggle (.*)', 'plugins toggle ', 'Toggle a plugin.', (msg, extra) => { const module = loader.getPlugin(extra[1]); if (module) { module.toggle(); @@ -13,7 +13,7 @@ commands.register(this.command, 'toggle (.*)', 'Toggle a plugin.', (msg, extra) } }); -commands.register(this.command, 'status (.*)', 'Check the status of a plugin', (msg, extra) => { +commands.register(this.command, 'status (.*)', 'plugins status ', 'Check the status of a plugin', (msg, extra) => { const module = loader.getPlugin(extra[1]); if (module) { msg.reply(`Plugin status: ${module.state}`); @@ -22,7 +22,7 @@ commands.register(this.command, 'status (.*)', 'Check the status of a plugin', ( } }); -commands.register(this.command, '', 'Get a list of plugin discriminators', (msg) => { +commands.register(this.command, '', 'plugins', 'Get a list of plugin discriminators', (msg) => { const modules = loader.getPlugins(); const em = new discord.RichEmbed(); em.title = 'Plugins'; diff --git a/plugins/customize.js b/plugins/customize.js index d6614dc..53b272e 100644 --- a/plugins/customize.js +++ b/plugins/customize.js @@ -3,24 +3,24 @@ const { client, discord } = require('@bot').client; exports.command = 'customize'; -commands.register(this.command, '', 'Customize Help', async (msg) => { +commands.register(this.command, '', 'customize', 'Customize Help', async (msg) => { const pluginCommands = commands.getCommands('customize'); const em = new discord.RichEmbed(); const prefix = await commands.getPrefix(); em.setTitle('Customize | Help'); pluginCommands.forEach((c) => { - em.addField(`${prefix}${c.command} ${c.params}`, `${c.description}`); + em.addField(`${prefix}${c.usage}`, `${c.description}`); }); msg.channel.send(em); }); -commands.register(this.command, 'game (.*)', 'Change the bots game', (msg, extra) => { +commands.register(this.command, 'game (.*)', 'customize game ', 'Change the bots game', (msg, extra) => { client.user.setActivity(extra[1]); msg.reply(`Set game to: ${extra[1]}`); }); -commands.register(this.command, 'command prefix (.*)', 'Change the bots command Prefix', async (msg, extra) => { +commands.register(this.command, 'command prefix (.*)', 'customize command prefix ', 'Change the bots command Prefix', async (msg, extra) => { const changed = await commands.setPrefix(msg.guild.id, extra[1]); if (changed) { msg.reply(`Set prefix to: ${extra[1]}`); diff --git a/plugins/moderation/user-management.js b/plugins/moderation/user-management.js index 6abf2f1..ced1a9c 100644 --- a/plugins/moderation/user-management.js +++ b/plugins/moderation/user-management.js @@ -3,11 +3,18 @@ const { discord } = require('@bot').client; exports.command = 'mod'; -commands.register(this.command, '', 'Customize Help', (msg) => { - msg.reply('Customize the bot with other commands!'); +commands.register(this.command, '', 'mod', 'User Management Help', async (msg) => { + const pluginCommands = commands.getCommands('mod'); + const em = new discord.RichEmbed(); + const prefix = await commands.getPrefix(); + em.setTitle('Mod | Help'); + pluginCommands.forEach((c) => { + em.addField(`${prefix}${c.usage}`, `${c.description}`); + }); + msg.channel.send(em); }); -commands.register(this.command, 'info (.*)', 'Customize Help', (msg) => { +commands.register(this.command, 'info (.*)', 'mod info <@user>', 'Get a users information', (msg) => { const em = new discord.RichEmbed(); const user = msg.mentions.users.first(); em.setTitle(`User Information for [${user.username}]`); diff --git a/plugins/moderation/warn.js b/plugins/moderation/warn.js new file mode 100644 index 0000000..5fd853f --- /dev/null +++ b/plugins/moderation/warn.js @@ -0,0 +1,75 @@ +const { commands } = require('@bot'); +const { discord } = require('@bot').client; +const { User, Server, UserWarning } = require('@bot').database; + +exports.command = 'warn'; + +commands.register(this.command, '', 'warn', 'Warning Help', async (msg) => { + const pluginCommands = commands.getCommands('warn'); + const em = new discord.RichEmbed(); + const prefix = await commands.getPrefix(); + em.setTitle('Warnings | Help'); + pluginCommands.forEach((c) => { + em.addField(`${prefix}${c.usage}`, `${c.description}`); + }); + msg.channel.send(em); +}); + +/* + user: { type: Schema.Types.ObjectId, ref: 'User' }, + warning: String, + warner: Number, +*/ + +commands.register(this.command, '([^s]+) (.*)', 'warn <@user> ', 'Warn a user for something', async (msg, extra) => { + const serverID = msg.guild.id; + const server = await Server.findOne({ serverID }).exec(); + const warnedUser = msg.mentions.users.first(); + const warning = extra[2]; + const warner = msg.author.id; + if (server && warnedUser) { + const user = await User.findOne({ server, discrim: warnedUser.id }); + if (!user) { + const newUser = await User.create({ server, discrim: warnedUser.id }); + UserWarning.create({ user: newUser, warning, warner }, (warningError) => { + if (warningError) throw warningError; + msg.channel.send(`Warned {${extra[1]}} for {${extra[2]}}`); + return warnedUser.send(`You have been warned for {${extra[2]}}`); + }); + } + UserWarning.create({ user, warning, warner }, (warningError) => { + if (warningError) throw warningError; + msg.channel.send(`Warned {${extra[1]}} for {${extra[2]}}`); + return warnedUser.send(`You have been warned for {${extra[2]}}`); + }); + } + return msg.channel.send('Cannot warn, error?'); +}); + +commands.register(this.command, 'list (.*)', 'warn list <@user>', 'List a users warnings', async (msg) => { + const serverID = msg.guild.id; + const server = await Server.findOne({ serverID }).exec(); + if (server) { + const targetUser = msg.mentions.users.first(); + const user = await User.findOne({ server, discrim: targetUser.id }).exec(); + const warnings = await UserWarning.find({ user }).exec(); + if (warnings) { + const em = new discord.RichEmbed(); + em.setTitle(`${targetUser.username}'s | Warnings`); + warnings.forEach(w => em.addField(w.warning, `Issuer: ${msg.guild.members.find(u => u.id === w.warner)}`)); + em.setFooter(`Total Warnings: ${warnings.length}`); + return msg.channel.send(em); + } + return msg.channel.send('Nothing for that user'); + } + return msg.channel.send('Nothing for that user'); +}); + +exports.name = 'Warnings'; +exports.version = '1.0.0'; +exports.description = 'Warnings Plugin'; +exports.discrim = 'warn'; +exports.state = true; +exports.toggle = () => { + this.state = !this.state; +}; diff --git a/plugins/ping-pong.js b/plugins/ping-pong.js deleted file mode 100644 index eb4bf98..0000000 --- a/plugins/ping-pong.js +++ /dev/null @@ -1,28 +0,0 @@ -const { commands } = require('@bot'); - -exports.command = 'ping'; - -commands.register(this.command, '', 'Ping the bot', (msg) => { - msg.reply('PONG'); -}); - -commands.register(this.command, 'pong', 'Pong the bot', (msg) => { - msg.reply('PING'); -}); - -commands.register(this.command, 'pong ping pong ping', 'Pong the bot', (msg) => { - msg.reply('PONG'); -}); - -commands.register(this.command, 'pong ping pong', 'Ping the bot', (msg) => { - msg.reply('PING'); -}); - -exports.name = 'Ping-Pong'; -exports.version = '1.0.0'; -exports.description = 'Basic Ping Pong Plugin'; -exports.discrim = 'pingpong'; -exports.state = true; -exports.toggle = () => { - this.state = !this.state; -};