1 |
const MessageEmbed = require("../src/MessageEmbed"); |
2 |
|
3 |
module.exports = { |
4 |
async handle(msg, cm) { |
5 |
if (typeof cm.args[0] === 'undefined') { |
6 |
await msg.reply({ |
7 |
embeds: [ |
8 |
new MessageEmbed() |
9 |
.setColor('#f14a60') |
10 |
.setDescription(`This command requires at least one argument.`) |
11 |
] |
12 |
}); |
13 |
|
14 |
return; |
15 |
} |
16 |
|
17 |
var user = await msg.mentions.members.first(); |
18 |
let reason; |
19 |
|
20 |
if (typeof cm.args[1] !== 'undefined') { |
21 |
let args = [...cm.args]; |
22 |
args.shift(); |
23 |
|
24 |
await (reason = args.join(' ')); |
25 |
} |
26 |
|
27 |
if (typeof user !== 'object') { |
28 |
try { |
29 |
user = await msg.guild.members.fetch(cm.args[0]); |
30 |
} |
31 |
catch(e) { |
32 |
|
33 |
} |
34 |
} |
35 |
|
36 |
if (typeof user !== 'object') { |
37 |
await msg.reply({ |
38 |
embeds: [ |
39 |
new MessageEmbed() |
40 |
.setColor('#f14a60') |
41 |
.setDescription(`Invalid user given.`) |
42 |
] |
43 |
}); |
44 |
|
45 |
return; |
46 |
} |
47 |
|
48 |
await this.warn(user, reason, msg, async (data) => { |
49 |
await msg.reply({ |
50 |
embeds: [ |
51 |
new MessageEmbed() |
52 |
.setDescription(`The user ${user.user.tag} has been warned`) |
53 |
.addFields([ |
54 |
{ |
55 |
name: "Reason", |
56 |
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
57 |
}, |
58 |
{ |
59 |
name: "Strike", |
60 |
value: data.count + ' time(s)' |
61 |
}, |
62 |
{ |
63 |
name: "ID", |
64 |
value: data.id + '' |
65 |
} |
66 |
]) |
67 |
] |
68 |
}); |
69 |
|
70 |
console.log(data); |
71 |
}); |
72 |
}, |
73 |
async warn(user, reason, msg, callback) { |
74 |
await app.db.get('INSERT INTO warnings(user_id, guild_id, strike, reason, warned_by) VALUES(?, ?, 1, ?, ?)', [user.id, msg.guild.id, reason === undefined ? '\c\b\c' : reason, msg.author.id], async (err) => { |
75 |
if (err) { |
76 |
console.log(err); |
77 |
} |
78 |
|
79 |
await app.db.get('SELECT id, user_id, guild_id, COUNT(*) AS count FROM warnings WHERE user_id = ? AND guild_id = ? ORDER BY id DESC LIMIT 0, 1', [user.id, msg.guild.id], async (err, data) => { |
80 |
if (err) { |
81 |
console.log(err); |
82 |
} |
83 |
|
84 |
await user.send({ |
85 |
embeds: [ |
86 |
new MessageEmbed() |
87 |
.setAuthor({ |
88 |
iconURL: msg.guild.iconURL(), |
89 |
name: `\tYou have been warned in ${msg.guild.name}` |
90 |
}) |
91 |
.addFields([ |
92 |
{ |
93 |
name: "Reason", |
94 |
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
95 |
}, |
96 |
{ |
97 |
name: "Strike", |
98 |
value: data.count + ' time(s)' |
99 |
} |
100 |
]) |
101 |
] |
102 |
}); |
103 |
|
104 |
callback(data); |
105 |
}); |
106 |
}); |
107 |
} |
108 |
}; |