4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
|
import getUser from '../../utils/getUser'; |
|
|
import History from '../../automod/History'; |
|
7 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
8 |
import ms from 'ms'; |
import PunishmentType from '../../types/PunishmentType'; |
9 |
|
import History from '../../automod/History'; |
10 |
|
|
11 |
export async function warn(client: DiscordClient, user: User, reason: string | undefined, msg: Message | CommandInteraction, callback: Function, warned_by1?: User) { |
export async function warn(client: DiscordClient, user: User, reason: string | undefined, msg: Message | CommandInteraction, warned_by?: User) { |
12 |
await client.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.member!.user.id : warned_by1.id], async (err: any) => { |
const { default: Punishment } = await import('../../models/Punishment'); |
|
if (err) { |
|
|
console.log(err); |
|
|
} |
|
13 |
|
|
14 |
await client.db.get('SELECT * FROM warnings WHERE user_id = ? AND guild_id = ? ORDER BY id DESC LIMIT 0, 1', [user.id, msg.guild!.id], async (err: any, data: any) => { |
const warning = await Punishment.create({ |
15 |
if (err) { |
guild_id: msg.guild!.id, |
16 |
console.log(err); |
user_id: user.id, |
17 |
} |
reason, |
18 |
|
mod_id: warned_by?.id ?? msg.member!.user.id, |
19 |
|
mod_tag: warned_by?.tag ?? (msg.member!.user as User).tag, |
20 |
|
type: PunishmentType.WARNING, |
21 |
|
}); |
22 |
|
|
23 |
await client.db.get('SELECT id, COUNT(*) as count, guild_id, user_id FROM warnings WHERE user_id = ? AND guild_id = ?', [user.id, msg.guild!.id], async (err: any, data3: any) => { |
const strike = await Punishment.count({ |
24 |
await client.logger.logWarn(msg as Message, user, warned_by1 === undefined ? msg.member!.user as User : warned_by1, typeof reason === 'undefined' ? '*No reason provided*' : reason, data.id); |
where: { |
25 |
|
guild_id: msg.guild!.id, |
26 |
await History.create(user.id, msg.guild!, 'warn', warned_by1 === undefined ? msg.member!.user.id : warned_by1.id, typeof reason === 'undefined' ? null : reason, async () => { |
user_id: user.id, |
27 |
await user.send({ |
type: PunishmentType.WARNING, |
28 |
embeds: [ |
} |
29 |
new MessageEmbed() |
}); |
|
.setAuthor({ |
|
|
iconURL: msg.guild!.iconURL() as string, |
|
|
name: `\tYou have been warned in ${msg.guild!.name}` |
|
|
}) |
|
|
.addFields([ |
|
|
{ |
|
|
name: "Reason", |
|
|
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
|
|
}, |
|
|
{ |
|
|
name: "Strike", |
|
|
value: data3.count + ' time(s)' |
|
|
} |
|
|
]) |
|
|
] |
|
|
}); |
|
30 |
|
|
31 |
console.log(data3); |
await History.create(user.id, msg.guild!, 'warn', warned_by?.id ?? msg.member!.user.id, reason ?? null); |
32 |
|
|
33 |
callback({count: data3.count, ...data}); |
await user.send({ |
34 |
}); |
embeds: [ |
35 |
}); |
new MessageEmbed({ |
36 |
}); |
author: { |
37 |
|
name: `You have been warned in ${msg.guild!.name}`, |
38 |
|
iconURL: msg.guild!.iconURL()! |
39 |
|
}, |
40 |
|
fields: [ |
41 |
|
{ |
42 |
|
name: 'Reason', |
43 |
|
value: reason ?? '*No reason provided*' |
44 |
|
}, |
45 |
|
{ |
46 |
|
name: 'Strike', |
47 |
|
value: `${strike} time(s)` |
48 |
|
} |
49 |
|
] |
50 |
|
}) |
51 |
|
] |
52 |
}); |
}); |
53 |
|
|
54 |
|
await client.logger.logWarn(msg, user, (warned_by ?? msg.member!.user) as User, reason, warning.get('id') as number); |
55 |
|
|
56 |
|
return { warning, strike }; |
57 |
} |
} |
58 |
|
|
59 |
export default class WarnCommand extends BaseCommand { |
export default class WarnCommand extends BaseCommand { |
129 |
} |
} |
130 |
|
|
131 |
try { |
try { |
132 |
await warn(client, user.user, reason, msg, async (data: any) => { |
const { warning, strike } = await warn(client, user.user, reason, msg, msg.member?.user as User); |
133 |
await msg.reply({ |
|
134 |
embeds: [ |
await msg.reply({ |
135 |
new MessageEmbed() |
embeds: [ |
136 |
.setDescription(`The user ${user.user.tag} has been warned`) |
new MessageEmbed() |
137 |
.addFields([ |
.setDescription(`The user ${user.user.tag} has been warned`) |
138 |
{ |
.addFields([ |
139 |
name: "Reason", |
{ |
140 |
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
name: "Reason", |
141 |
}, |
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
142 |
{ |
}, |
143 |
name: "Strike", |
{ |
144 |
value: data.count + ' time(s)' |
name: "Strike", |
145 |
}, |
value: strike + ' time(s)' |
146 |
{ |
}, |
147 |
name: "Warned by", |
{ |
148 |
value: (msg.member?.user as User).tag |
name: "Warned by", |
149 |
}, |
value: (msg.member?.user as User).tag |
150 |
{ |
}, |
151 |
name: "ID", |
{ |
152 |
value: data.id + '' |
name: "ID", |
153 |
} |
value: warning.get('id') + '' |
154 |
]) |
} |
155 |
] |
]) |
156 |
}); |
] |
157 |
}, msg.member?.user as User); |
}); |
158 |
} |
} |
159 |
catch (e) { |
catch (e) { |
160 |
console.log(e); |
console.log(e); |