/[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 86 by rakin, Mon Jul 29 17:28:32 2024 UTC revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User } from 'discord.js';  import { CommandInteraction, GuildMember, Message, User } from 'discord.js';
2  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
4  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
# Line 6  import InteractionOptions from '../../ty Line 6  import InteractionOptions from '../../ty
6  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
7  import getMember from '../../utils/getMember';  import getMember from '../../utils/getMember';
8  import PunishmentType from '../../types/PunishmentType';  import PunishmentType from '../../types/PunishmentType';
 import Punishment from '../../models/Punishment';  
 import History from '../../automod/History';  
9    
10  export async function warn(client: DiscordClient, user: User, reason: string | undefined, msg: Message | CommandInteraction, warned_by?: User) {      export async function warn(client: DiscordClient, user: User, reason: string | undefined, msg: Message | CommandInteraction, warned_by?: User) {  
11        const { default: Punishment } = await import('../../models/Punishment');
12    
13      const warning = await Punishment.create({      const warning = await Punishment.create({
14          guild_id: msg.guild!.id,          guild_id: msg.guild!.id,
15          user_id: user.id,          user_id: user.id,
# Line 17  export async function warn(client: Disco Line 17  export async function warn(client: Disco
17          mod_id: warned_by?.id ?? msg.member!.user.id,          mod_id: warned_by?.id ?? msg.member!.user.id,
18          mod_tag: warned_by?.tag ?? (msg.member!.user as User).tag,          mod_tag: warned_by?.tag ?? (msg.member!.user as User).tag,
19          type: PunishmentType.WARNING,          type: PunishmentType.WARNING,
20            createdAt: new Date()
21      });      });
22    
23      const strike = await Punishment.count({      const strike = await Punishment.count({
24          where: {          guild_id: msg.guild!.id,
25              guild_id: msg.guild!.id,          user_id: user.id,
26              user_id: user.id,          type: PunishmentType.WARNING,
             type: PunishmentType.WARNING,  
         }  
27      });      });
28    
29      await History.create(user.id, msg.guild!, 'warn', warned_by?.id ?? msg.member!.user.id, reason ?? null);      // await History.create(user.id, msg.guild!, 'warn', warned_by?.id ?? msg.member!.user.id, reason ?? null);
30    
31      await user.send({      let DMed = true;
         embeds: [  
             new MessageEmbed({  
                 author: {  
                     name: `You have been warned in ${msg.guild!.name}`,  
                     iconURL: msg.guild!.iconURL()!  
                 },  
                 fields: [  
                     {  
                         name: 'Reason',  
                         value: reason ?? '*No reason provided*'  
                     },  
                     {  
                         name: 'Strike',  
                         value: `${strike} time(s)`  
                     }  
                 ]  
             })  
         ]  
     });  
32    
33        try {
34            await user.send({
35                embeds: [
36                    new MessageEmbed({
37                        author: {
38                            name: `You have been warned in ${msg.guild!.name}`,
39                            iconURL: msg.guild!.iconURL()!
40                        },
41                        fields: [
42                            {
43                                name: 'Reason',
44                                value: reason ?? '*No reason provided*'
45                            },
46                            {
47                                name: 'Strike',
48                                value: `${strike} time(s)`
49                            }
50                        ]
51                    })
52                ]
53            });
54        }
55        catch (e) {
56            console.log(e);
57            DMed = false;  
58        }
59        
60      await client.logger.logWarn(msg, user, (warned_by ?? msg.member!.user) as User, reason, warning.get('id') as number);      await client.logger.logWarn(msg, user, (warned_by ?? msg.member!.user) as User, reason, warning.get('id') as number);
61    
62      return { warning, strike };      return { warning, strike, DMed };
63  }  }
64    
65  export default class WarnCommand extends BaseCommand {  export default class WarnCommand extends BaseCommand {
# Line 128  export default class WarnCommand extends Line 135  export default class WarnCommand extends
135          }          }
136    
137          try {          try {
138              const { warning, strike } = await warn(client, user.user, reason, msg, msg.member?.user as User);              const { warning, strike, DMed } = await warn(client, user.user, reason, msg, msg.member?.user as User);
139    
140              await msg.reply({              await msg.reply({
141                  embeds: [                  embeds: [
142                      new MessageEmbed()                      new MessageEmbed()
143                      .setDescription(`The user ${user.user.tag} has been warned`)                      .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."))
144                      .addFields([                      .addFields([
145                          {                          {
146                              name: "Reason",                              name: "Reason",
# Line 159  export default class WarnCommand extends Line 166  export default class WarnCommand extends
166              console.log(e);                          console.log(e);            
167          }          }
168      }      }
 }  
169    }

Legend:
Removed from v.86  
changed lines
  Added in v.344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26