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

Diff of /trunk/src/commands/moderation/BanCommand.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 197 by rakin, Mon Jul 29 17:28:59 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js';  import { Permissions, BanOptions, CommandInteraction, GuildMember, Interaction, 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 getUser from '../../utils/getUser';  import getUser from '../../utils/getUser';
8  import History from '../../automod/History';  import History from '../../automod/History';
9    import Punishment from '../../models/Punishment';
10    import PunishmentType from '../../types/PunishmentType';
11    import { shouldNotModerate, hasPermission } from '../../utils/util';
12    
13  export default class BanCommand extends BaseCommand {  export default class BanCommand extends BaseCommand {
14      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
15        supportsContextMenu: boolean = true;
16        permissions = [Permissions.FLAGS.BAN_MEMBERS];
17    
18      constructor() {      constructor() {
19          super('ban', 'moderation', []);          super('ban', 'moderation', ['Ban']);
20      }      }
21    
22      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
# Line 102  export default class BanCommand extends Line 107  export default class BanCommand extends
107              }              }
108          }          }
109    
110            try {
111                const member = await msg.guild?.members.fetch(user.id);
112    
113                if (member && !(await hasPermission(client, member, msg, null, "You don't have permission to ban this user."))) {
114                    return;
115                }
116    
117                if (member && shouldNotModerate(client, member)) {
118                    await msg.reply({
119                        embeds: [
120                            new MessageEmbed()
121                            .setColor('#f14a60')
122                            .setDescription('Cannot ban this user: Operation not permitted')    
123                        ]
124                    });
125                    
126                    return;
127                }
128            }
129            catch (e) {
130                console.log(e);
131            }
132            
133          try {          try {
134              await msg.guild?.bans.create(user, banOptions);              await msg.guild?.bans.create(user, banOptions);
135    
136                await Punishment.create({
137                    type: PunishmentType.BAN,
138                    user_id: user.id,
139                    guild_id: msg.guild!.id,
140                    mod_id: msg.member!.user.id,
141                    mod_tag: (msg.member!.user as User).tag,
142                    reason: banOptions.reason ?? undefined
143                });
144    
145              await History.create(user.id, msg.guild!, 'ban', msg.member!.user.id, typeof banOptions.reason === 'undefined' ? null : banOptions.reason, async (data: any) => undefined);              await History.create(user.id, msg.guild!, 'ban', msg.member!.user.id, typeof banOptions.reason === 'undefined' ? null : banOptions.reason, async (data: any) => undefined);
146          }          }
147          catch (e) {          catch (e) {
# Line 143  export default class BanCommand extends Line 181  export default class BanCommand extends
181              ]              ]
182          });          });
183      }      }
 }  
184    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26