Skip to content

Commit

Permalink
Merge pull request #16 from ItsJustMeChris/master
Browse files Browse the repository at this point in the history
Update/Remove
  • Loading branch information
gmemstr authored Feb 13, 2019
2 parents e57c1c8 + 9699418 commit 709b2c6
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 48 deletions.
9 changes: 6 additions & 3 deletions core/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -25,6 +25,7 @@ exports.register = (command, params, description, response) => {
description,
response,
compiled,
usage,
});
}
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
});
4 changes: 2 additions & 2 deletions core/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
6 changes: 3 additions & 3 deletions plugins/core/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -15,15 +15,15 @@ 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 <plugin-name>', 'Shows the help message', async (msg, extra) => {
const module = loader.getPlugin(extra[1]);
if (module) {
const em = new discord.RichEmbed();
const moduleCommands = commands.getCommands(module.command);
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);
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/core/permission-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <plugin-discriminator> <@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();
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions plugins/core/plugin-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <plugin-discriminator>', 'Toggle a plugin.', (msg, extra) => {
const module = loader.getPlugin(extra[1]);
if (module) {
module.toggle();
Expand All @@ -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 <plugin-discriminator>', 'Check the status of a plugin', (msg, extra) => {
const module = loader.getPlugin(extra[1]);
if (module) {
msg.reply(`Plugin status: ${module.state}`);
Expand All @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions plugins/customize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <game-name>', '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 <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]}`);
Expand Down
13 changes: 10 additions & 3 deletions plugins/moderation/user-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}]`);
Expand Down
75 changes: 75 additions & 0 deletions plugins/moderation/warn.js
Original file line number Diff line number Diff line change
@@ -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> <reason>', '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;
};
28 changes: 0 additions & 28 deletions plugins/ping-pong.js

This file was deleted.

0 comments on commit 709b2c6

Please sign in to comment.