Skip to content

Commit 709b2c6

Browse files
authored
Merge pull request #16 from ItsJustMeChris/master
Update/Remove
2 parents e57c1c8 + 9699418 commit 709b2c6

File tree

9 files changed

+105
-48
lines changed

9 files changed

+105
-48
lines changed

core/commands.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const checkCommand = (command, body) => {
1515
return true;
1616
};
1717

18-
exports.register = (command, params, description, response) => {
18+
exports.register = (command, params, usage, description, response) => {
1919
const compiled = params === '' ? `${command}` : `${command} ${params}`;
2020

2121
if (checkCommand(command, params)) {
@@ -25,6 +25,7 @@ exports.register = (command, params, description, response) => {
2525
description,
2626
response,
2727
compiled,
28+
usage,
2829
});
2930
}
3031
};
@@ -60,6 +61,8 @@ const getAllowedRoles = (serverPermissions, userRoles, plugin) => {
6061

6162
client.on('message', async (msg) => {
6263
const message = msg.content;
64+
if (!msg.guild && msg.author.id !== client.user.id) return msg.reply('I do not work in DMs');
65+
if (msg.author.id === client.user.id) return false;
6366
const serverPrefix = await this.getPrefix(msg.guild.id);
6467
const serverPermissions = await permissions.getServerPermissions(msg.guild.id);
6568
for (let i = 0; i < registeredCommands.length; i += 1) {
@@ -70,9 +73,9 @@ client.on('message', async (msg) => {
7073
const plugin = loader.fromCommand(command);
7174
const userRoles = msg.member.roles.array();
7275
const allowedRoles = getAllowedRoles(serverPermissions, userRoles, plugin);
73-
if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || allowedRoles >= 1)) {
76+
if (pluginState && (`${serverPrefix}${command.compiled}` === message || match[1]) && (plugin.ignorePermissions || allowedRoles.length >= 1)) {
7477
return command.response(msg, match);
7578
}
7679
}
77-
return null;
80+
return false;
7881
});

core/database.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ const Server = mongoose.model('Server', {
1919

2020
const User = mongoose.model('User', {
2121
server: { type: Schema.Types.ObjectId, ref: 'Server' },
22-
descrim: Number,
22+
discrim: String,
2323
});
2424

2525
const UserWarning = mongoose.model('UserWarnings', {
2626
user: { type: Schema.Types.ObjectId, ref: 'User' },
2727
warning: String,
28-
warner: Number,
28+
warner: String,
2929
});
3030

3131
const Configuration = mongoose.model('Configuration', {

plugins/core/help.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { discord } = require('@bot').client;
33

44
exports.command = 'help';
55

6-
commands.register(this.command, '', 'Shows the help message', async (msg) => {
6+
commands.register(this.command, '', 'help', 'Shows the help message', async (msg) => {
77
const modules = loader.getPlugins();
88
const em = new discord.RichEmbed();
99
const prefix = await commands.getPrefix(msg.guild.id);
@@ -15,15 +15,15 @@ commands.register(this.command, '', 'Shows the help message', async (msg) => {
1515
msg.reply(em);
1616
});
1717

18-
commands.register(this.command, '(.*)', 'Shows the help message', async (msg, extra) => {
18+
commands.register(this.command, '(.*)', 'help <plugin-name>', 'Shows the help message', async (msg, extra) => {
1919
const module = loader.getPlugin(extra[1]);
2020
if (module) {
2121
const em = new discord.RichEmbed();
2222
const moduleCommands = commands.getCommands(module.command);
2323
const prefix = await commands.getPrefix(msg.guild.id);
2424
em.setTitle(`${module.name} | Help`);
2525
moduleCommands.forEach((c) => {
26-
em.addField(`${prefix}${c.command} ${c.params}`, `${c.description}`);
26+
em.addField(`${prefix}${c.usage}`, `${c.description}`);
2727
});
2828
return msg.channel.send(em);
2929
}

plugins/core/permission-helper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { discord } = require('@bot').client;
33

44
exports.command = 'permissions';
55

6-
commands.register(this.command, 'add (.*) (.*)', 'Add permission to a plugin to a role', async (msg, extra) => {
6+
commands.register(this.command, 'add (.*) (.*)', 'permissions add <plugin-discriminator> <@role>', 'Add permission to a plugin to a role', async (msg, extra) => {
77
const plugin = loader.getPlugin(extra[1]);
88
if (plugin) {
99
const role = msg.mentions.roles.first();
@@ -16,7 +16,7 @@ commands.register(this.command, 'add (.*) (.*)', 'Add permission to a plugin to
1616
return msg.reply('Error plugin does not exist..');
1717
});
1818

19-
commands.register(this.command, '', 'Permissions help', async (msg) => {
19+
commands.register(this.command, '', 'permissions', 'Permissions help', async (msg) => {
2020
const pluginCommands = commands.getCommands('permissions');
2121
const em = new discord.RichEmbed();
2222
const prefix = await commands.getPrefix();

plugins/core/plugin-helper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { discord } = require('@bot').client;
33

44
exports.command = 'plugins';
55

6-
commands.register(this.command, 'toggle (.*)', 'Toggle a plugin.', (msg, extra) => {
6+
commands.register(this.command, 'toggle (.*)', 'plugins toggle <plugin-discriminator>', 'Toggle a plugin.', (msg, extra) => {
77
const module = loader.getPlugin(extra[1]);
88
if (module) {
99
module.toggle();
@@ -13,7 +13,7 @@ commands.register(this.command, 'toggle (.*)', 'Toggle a plugin.', (msg, extra)
1313
}
1414
});
1515

16-
commands.register(this.command, 'status (.*)', 'Check the status of a plugin', (msg, extra) => {
16+
commands.register(this.command, 'status (.*)', 'plugins status <plugin-discriminator>', 'Check the status of a plugin', (msg, extra) => {
1717
const module = loader.getPlugin(extra[1]);
1818
if (module) {
1919
msg.reply(`Plugin status: ${module.state}`);
@@ -22,7 +22,7 @@ commands.register(this.command, 'status (.*)', 'Check the status of a plugin', (
2222
}
2323
});
2424

25-
commands.register(this.command, '', 'Get a list of plugin discriminators', (msg) => {
25+
commands.register(this.command, '', 'plugins', 'Get a list of plugin discriminators', (msg) => {
2626
const modules = loader.getPlugins();
2727
const em = new discord.RichEmbed();
2828
em.title = 'Plugins';

plugins/customize.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ const { client, discord } = require('@bot').client;
33

44
exports.command = 'customize';
55

6-
commands.register(this.command, '', 'Customize Help', async (msg) => {
6+
commands.register(this.command, '', 'customize', 'Customize Help', async (msg) => {
77
const pluginCommands = commands.getCommands('customize');
88
const em = new discord.RichEmbed();
99
const prefix = await commands.getPrefix();
1010
em.setTitle('Customize | Help');
1111
pluginCommands.forEach((c) => {
12-
em.addField(`${prefix}${c.command} ${c.params}`, `${c.description}`);
12+
em.addField(`${prefix}${c.usage}`, `${c.description}`);
1313
});
1414
msg.channel.send(em);
1515
});
1616

17-
commands.register(this.command, 'game (.*)', 'Change the bots game', (msg, extra) => {
17+
commands.register(this.command, 'game (.*)', 'customize game <game-name>', 'Change the bots game', (msg, extra) => {
1818
client.user.setActivity(extra[1]);
1919
msg.reply(`Set game to: ${extra[1]}`);
2020
});
2121

2222

23-
commands.register(this.command, 'command prefix (.*)', 'Change the bots command Prefix', async (msg, extra) => {
23+
commands.register(this.command, 'command prefix (.*)', 'customize command prefix <prefix>', 'Change the bots command Prefix', async (msg, extra) => {
2424
const changed = await commands.setPrefix(msg.guild.id, extra[1]);
2525
if (changed) {
2626
msg.reply(`Set prefix to: ${extra[1]}`);

plugins/moderation/user-management.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ const { discord } = require('@bot').client;
33

44
exports.command = 'mod';
55

6-
commands.register(this.command, '', 'Customize Help', (msg) => {
7-
msg.reply('Customize the bot with other commands!');
6+
commands.register(this.command, '', 'mod', 'User Management Help', async (msg) => {
7+
const pluginCommands = commands.getCommands('mod');
8+
const em = new discord.RichEmbed();
9+
const prefix = await commands.getPrefix();
10+
em.setTitle('Mod | Help');
11+
pluginCommands.forEach((c) => {
12+
em.addField(`${prefix}${c.usage}`, `${c.description}`);
13+
});
14+
msg.channel.send(em);
815
});
916

10-
commands.register(this.command, 'info (.*)', 'Customize Help', (msg) => {
17+
commands.register(this.command, 'info (.*)', 'mod info <@user>', 'Get a users information', (msg) => {
1118
const em = new discord.RichEmbed();
1219
const user = msg.mentions.users.first();
1320
em.setTitle(`User Information for [${user.username}]`);

plugins/moderation/warn.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const { commands } = require('@bot');
2+
const { discord } = require('@bot').client;
3+
const { User, Server, UserWarning } = require('@bot').database;
4+
5+
exports.command = 'warn';
6+
7+
commands.register(this.command, '', 'warn', 'Warning Help', async (msg) => {
8+
const pluginCommands = commands.getCommands('warn');
9+
const em = new discord.RichEmbed();
10+
const prefix = await commands.getPrefix();
11+
em.setTitle('Warnings | Help');
12+
pluginCommands.forEach((c) => {
13+
em.addField(`${prefix}${c.usage}`, `${c.description}`);
14+
});
15+
msg.channel.send(em);
16+
});
17+
18+
/*
19+
user: { type: Schema.Types.ObjectId, ref: 'User' },
20+
warning: String,
21+
warner: Number,
22+
*/
23+
24+
commands.register(this.command, '([^s]+) (.*)', 'warn <@user> <reason>', 'Warn a user for something', async (msg, extra) => {
25+
const serverID = msg.guild.id;
26+
const server = await Server.findOne({ serverID }).exec();
27+
const warnedUser = msg.mentions.users.first();
28+
const warning = extra[2];
29+
const warner = msg.author.id;
30+
if (server && warnedUser) {
31+
const user = await User.findOne({ server, discrim: warnedUser.id });
32+
if (!user) {
33+
const newUser = await User.create({ server, discrim: warnedUser.id });
34+
UserWarning.create({ user: newUser, warning, warner }, (warningError) => {
35+
if (warningError) throw warningError;
36+
msg.channel.send(`Warned {${extra[1]}} for {${extra[2]}}`);
37+
return warnedUser.send(`You have been warned for {${extra[2]}}`);
38+
});
39+
}
40+
UserWarning.create({ user, warning, warner }, (warningError) => {
41+
if (warningError) throw warningError;
42+
msg.channel.send(`Warned {${extra[1]}} for {${extra[2]}}`);
43+
return warnedUser.send(`You have been warned for {${extra[2]}}`);
44+
});
45+
}
46+
return msg.channel.send('Cannot warn, error?');
47+
});
48+
49+
commands.register(this.command, 'list (.*)', 'warn list <@user>', 'List a users warnings', async (msg) => {
50+
const serverID = msg.guild.id;
51+
const server = await Server.findOne({ serverID }).exec();
52+
if (server) {
53+
const targetUser = msg.mentions.users.first();
54+
const user = await User.findOne({ server, discrim: targetUser.id }).exec();
55+
const warnings = await UserWarning.find({ user }).exec();
56+
if (warnings) {
57+
const em = new discord.RichEmbed();
58+
em.setTitle(`${targetUser.username}'s | Warnings`);
59+
warnings.forEach(w => em.addField(w.warning, `Issuer: ${msg.guild.members.find(u => u.id === w.warner)}`));
60+
em.setFooter(`Total Warnings: ${warnings.length}`);
61+
return msg.channel.send(em);
62+
}
63+
return msg.channel.send('Nothing for that user');
64+
}
65+
return msg.channel.send('Nothing for that user');
66+
});
67+
68+
exports.name = 'Warnings';
69+
exports.version = '1.0.0';
70+
exports.description = 'Warnings Plugin';
71+
exports.discrim = 'warn';
72+
exports.state = true;
73+
exports.toggle = () => {
74+
this.state = !this.state;
75+
};

plugins/ping-pong.js

-28
This file was deleted.

0 commit comments

Comments
 (0)