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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26