/[sudobot]/trunk/src/commands/moderation/WarnCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/moderation/WarnCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 167 by rakin, Mon Jul 29 17:28:51 2024 UTC
# Line 4  import DiscordClient from '../../client/ Line 4  import DiscordClient from '../../client/
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');
13          if (err) {  
14              console.log(err);      const warning = await Punishment.create({
15            guild_id: msg.guild!.id,
16            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        const strike = await Punishment.count({
24            where: {
25                guild_id: msg.guild!.id,
26                user_id: user.id,
27                type: PunishmentType.WARNING,
28          }          }
29        });
30    
31          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);  
             }  
32    
33              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) => {      let DMed = true;
                 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);  
               
                 await History.create(user.id, msg.guild!, 'warn', warned_by1 === undefined ? msg.member!.user.id : warned_by1.id, typeof reason === 'undefined' ? null : reason, async () => {  
                     await user.send({  
                         embeds: [  
                             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)'  
                                 }  
                             ])  
                         ]  
                     });  
34    
35                      console.log(data3);                          try {
36            await user.send({
37                embeds: [
38                    new MessageEmbed({
39                        author: {
40                            name: `You have been warned in ${msg.guild!.name}`,
41                            iconURL: msg.guild!.iconURL()!
42                        },
43                        fields: [
44                            {
45                                name: 'Reason',
46                                value: reason ?? '*No reason provided*'
47                            },
48                            {
49                                name: 'Strike',
50                                value: `${strike} time(s)`
51                            }
52                        ]
53                    })
54                ]
55            });
56        }
57        catch (e) {
58            console.log(e);
59            DMed = false;  
60        }
61        
62        await client.logger.logWarn(msg, user, (warned_by ?? msg.member!.user) as User, reason, warning.get('id') as number);
63    
64                      callback({count: data3.count, ...data});      return { warning, strike, DMed };
                 });  
             });  
         });  
     });  
65  }  }
66    
67  export default class WarnCommand extends BaseCommand {  export default class WarnCommand extends BaseCommand {
# Line 126  export default class WarnCommand extends Line 137  export default class WarnCommand extends
137          }          }
138    
139          try {          try {
140              await warn(client, user.user, reason, msg, async (data: any) => {              const { warning, strike, DMed } = await warn(client, user.user, reason, msg, msg.member?.user as User);
141                  await msg.reply({  
142                      embeds: [              await msg.reply({
143                          new MessageEmbed()                  embeds: [
144                          .setDescription(`The user ${user.user.tag} has been warned`)                      new MessageEmbed()
145                          .addFields([                      .setDescription(`The user ${user.user.tag} has been warned` + (DMed ? "" : "\n:warning: The user has DMs disabled, so they might not know that they've been warned."))
146                              {                      .addFields([
147                                  name: "Reason",                          {
148                                  value: typeof reason === 'undefined' ? '*No reason provided*' : reason                              name: "Reason",
149                              },                              value: typeof reason === 'undefined' ? '*No reason provided*' : reason
150                              {                          },
151                                  name: "Strike",                          {
152                                  value: data.count + ' time(s)'                              name: "Strike",
153                              },                              value: strike + ' time(s)'
154                              {                          },
155                                  name: "Warned by",                          {
156                                  value: (msg.member?.user as User).tag                              name: "Warned by",
157                              },                              value: (msg.member?.user as User).tag
158                              {                          },
159                                  name: "ID",                          {
160                                  value: data.id + ''                              name: "ID",
161                              }                              value: warning.get('id') + ''
162                          ])                          }
163                      ]                      ])
164                  });                  ]
165              }, msg.member?.user as User);              });
166          }          }
167          catch (e) {          catch (e) {
168              console.log(e);                          console.log(e);            
169          }          }
170      }      }
 }  
171    }

Legend:
Removed from v.51  
changed lines
  Added in v.167

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26