1 |
const MessageEmbed = require("../src/MessageEmbed"); |
2 |
|
3 |
module.exports = { |
4 |
async handle(msg, cm) { |
5 |
var test = false; |
6 |
|
7 |
if (typeof cm.args[0] === 'undefined') { |
8 |
var args1 = ['SELECT * FROM warnings WHERE guild_id = ?', [msg.guild.id]]; |
9 |
var a = { |
10 |
name: `All warnings` |
11 |
}; |
12 |
} |
13 |
else { |
14 |
var user = await msg.mentions.members.first(); |
15 |
|
16 |
if (typeof user !== 'object') { |
17 |
try { |
18 |
user = await msg.guild.members.fetch(cm.args[0]); |
19 |
} |
20 |
catch(e) { |
21 |
|
22 |
} |
23 |
} |
24 |
|
25 |
if (typeof user !== 'object') { |
26 |
await msg.reply({ |
27 |
embeds: [ |
28 |
new MessageEmbed() |
29 |
.setColor('#f14a60') |
30 |
.setDescription(`Invalid user given.`) |
31 |
] |
32 |
}); |
33 |
|
34 |
return; |
35 |
} |
36 |
|
37 |
var args1 = ['SELECT id, user_id, guild_id, reason FROM warnings WHERE user_id = ? AND guild_id = ?', [user.id, msg.guild.id]]; |
38 |
var a = { |
39 |
iconURL: user.displayAvatarURL(), |
40 |
name: `All warnings for ${user.user.tag} in ${msg.guild.name}` |
41 |
}; |
42 |
|
43 |
test = true; |
44 |
} |
45 |
|
46 |
await app.db.all(...args1, async (err, data) => { |
47 |
if (err) { |
48 |
console.log(err); |
49 |
} |
50 |
|
51 |
let i = 0; |
52 |
|
53 |
let warnings = await data.map(value => { |
54 |
i++; |
55 |
return { |
56 |
name: "Warning " + i + " (ID: " + value.id + (!test ? ", To: " + value.user_id : "") + ")", |
57 |
value: value.reason === '\c\b\c' ? "No reason provided" : value.reason |
58 |
}; |
59 |
}); |
60 |
|
61 |
if (test) { |
62 |
warnings.push( |
63 |
{ |
64 |
name: "Strike", |
65 |
value: i + ' time(s)' |
66 |
} |
67 |
); |
68 |
} |
69 |
|
70 |
await msg.reply({ |
71 |
embeds: [ |
72 |
new MessageEmbed() |
73 |
.setAuthor(a) |
74 |
.addFields(warnings) |
75 |
] |
76 |
}); |
77 |
}); |
78 |
} |
79 |
}; |