|
| 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 | +}; |
0 commit comments