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