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