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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26