1 |
const History = require("../src/History"); |
2 |
const MessageEmbed = require("../src/MessageEmbed"); |
3 |
const { getUser } = require("../src/UserInput"); |
4 |
|
5 |
module.exports = { |
6 |
async handle(msg, cm) { |
7 |
if (typeof cm.args[0] === 'undefined') { |
8 |
await msg.reply({ |
9 |
embeds: [ |
10 |
new MessageEmbed() |
11 |
.setColor('#f14a60') |
12 |
.setDescription(`This command requires at least one argument.`) |
13 |
] |
14 |
}); |
15 |
|
16 |
return; |
17 |
} |
18 |
|
19 |
try { |
20 |
var user = await getUser(cm.args[0], msg); |
21 |
|
22 |
console.log(user); |
23 |
|
24 |
if (!user) { |
25 |
throw new Error('Invalid User'); |
26 |
} |
27 |
} |
28 |
catch (e) { |
29 |
console.log(e); |
30 |
|
31 |
await msg.reply({ |
32 |
embeds: [ |
33 |
new MessageEmbed() |
34 |
.setColor('#f14a60') |
35 |
.setDescription(`Invalid user given.`) |
36 |
] |
37 |
}); |
38 |
|
39 |
return; |
40 |
} |
41 |
|
42 |
let reason; |
43 |
|
44 |
if (typeof cm.args[1] !== 'undefined') { |
45 |
let args = [...cm.args]; |
46 |
args.shift(); |
47 |
|
48 |
await (reason = args.join(' ')); |
49 |
} |
50 |
|
51 |
await this.warn(user, reason, msg, async (data) => { |
52 |
await msg.reply({ |
53 |
embeds: [ |
54 |
new MessageEmbed() |
55 |
.setDescription(`The user ${user.user.tag} has been warned`) |
56 |
.addFields([ |
57 |
{ |
58 |
name: "Reason", |
59 |
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
60 |
}, |
61 |
{ |
62 |
name: "Strike", |
63 |
value: data.count + ' time(s)' |
64 |
}, |
65 |
{ |
66 |
name: "ID", |
67 |
value: data.id + '' |
68 |
} |
69 |
]) |
70 |
] |
71 |
}); |
72 |
|
73 |
console.log(data); |
74 |
}); |
75 |
}, |
76 |
async warn(user, reason, msg, callback, warned_by1) { |
77 |
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, warned_by1 === undefined ? msg.author.id : warned_by1], async (err) => { |
78 |
if (err) { |
79 |
console.log(err); |
80 |
} |
81 |
|
82 |
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) => { |
83 |
if (err) { |
84 |
console.log(err); |
85 |
} |
86 |
|
87 |
console.log('fr'); |
88 |
|
89 |
await app.logger.logWarn(msg, user, warned_by1 === undefined ? msg.author : warned_by1, typeof reason === 'undefined' ? '*No reason provided*' : reason); |
90 |
|
91 |
await History.create(user.id, msg.guild, 'warn', warned_by1 === undefined ? msg.author.id : warned_by1.id, typeof reason === 'undefined' ? null : reason, async (data2) => { |
92 |
await user.send({ |
93 |
embeds: [ |
94 |
new MessageEmbed() |
95 |
.setAuthor({ |
96 |
iconURL: msg.guild.iconURL(), |
97 |
name: `\tYou have been warned in ${msg.guild.name}` |
98 |
}) |
99 |
.addFields([ |
100 |
{ |
101 |
name: "Reason", |
102 |
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
103 |
}, |
104 |
{ |
105 |
name: "Strike", |
106 |
value: data.count + ' time(s)' |
107 |
} |
108 |
]) |
109 |
] |
110 |
}); |
111 |
|
112 |
callback(data); |
113 |
}); |
114 |
}); |
115 |
}); |
116 |
} |
117 |
}; |