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

Diff of /trunk/src/commands/moderation/ShotCommand.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 160 by rakin, Mon Jul 29 17:28:50 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js';  import { BanOptions, CommandInteraction, ContextMenuInteraction, 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 7  import MessageEmbed from '../../client/M Line 7  import MessageEmbed from '../../client/M
7  import getUser from '../../utils/getUser';  import getUser from '../../utils/getUser';
8  import getMember from '../../utils/getMember';  import getMember from '../../utils/getMember';
9  import History from '../../automod/History';  import History from '../../automod/History';
10    import Punishment from '../../models/Punishment';
11    import PunishmentType from '../../types/PunishmentType';
12    
13  export default class BeanCommand extends BaseCommand {  export default class BeanCommand extends BaseCommand {
14      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
15        supportsContextMenu: boolean = true;
16    
17      constructor() {      constructor() {
18          super('bean', 'moderation', []);          super('bean', 'moderation', ['Bean']);
19      }      }
20    
21      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) {
22          if (!options.isInteraction && typeof options.args[0] === 'undefined') {          if (!options.isInteraction && typeof options.args[0] === 'undefined') {
23              await msg.reply({              await msg.reply({
24                  embeds: [                  embeds: [
# Line 29  export default class BeanCommand extends Line 32  export default class BeanCommand extends
32          }          }
33    
34          let user: GuildMember;          let user: GuildMember;
35            let dm = true;
36          let reason: string | undefined;          let reason: string | undefined;
37    
38          if (options.isInteraction) {          if (options.isInteraction) {
39              user = await <GuildMember> options.options.getMember('member');              user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member'));
40    
41              if (!user) {              if (!user) {
42                  await msg.reply({                  await msg.reply({
43                      embeds: [                      embeds: [
44                          new MessageEmbed()                          new MessageEmbed()
45                          .setColor('#f14a60')                          .setColor('#f14a60')
46                          .setDescription("Invalid user given.")                          .setDescription("Invalid member given.")
47                      ]                      ]
48                  });                  });
49            
# Line 82  export default class BeanCommand extends Line 86  export default class BeanCommand extends
86          }          }
87    
88          try {                      try {            
89                await Punishment.create({
90                    type: PunishmentType.BEAN,
91                    user_id: user.id,
92                    guild_id: msg.guild!.id,
93                    mod_id: msg.member!.user.id,
94                    mod_tag: (msg.member!.user as User).tag,
95                    reason
96                });
97    
98              await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);              await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);
99    
100              await user.send({              try {
101                  embeds: [                  await user.send({
102                      new MessageEmbed()                      embeds: [
103                      .setAuthor({                          new MessageEmbed()
104                          iconURL: <string> msg.guild!.iconURL(),                          .setAuthor({
105                          name: `\tYou have been beaned in ${msg.guild!.name}`                              iconURL: <string> msg.guild!.iconURL(),
106                      })                              name: `\tYou have been beaned in ${msg.guild!.name}`
107                      .addFields([                          })
108                          {                          .addFields([
109                              name: "Reason",                              {
110                              value: typeof reason === 'undefined' ? '*No reason provided*' : reason                                  name: "Reason",
111                          }                                  value: typeof reason === 'undefined' ? '*No reason provided*' : reason
112                      ])                              }
113                  ]                          ])
114              });                      ]
115                    });
116                }
117                catch (e) {
118                    console.log(e);
119                    dm = false;
120                }
121    
122              await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User);              await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User);
123          }          }
# Line 113  export default class BeanCommand extends Line 132  export default class BeanCommand extends
132                      name: user.user.tag,                      name: user.user.tag,
133                      iconURL: user.user.displayAvatarURL(),                      iconURL: user.user.displayAvatarURL(),
134                  })                  })
135                  .setDescription(user.user.tag + " has been beaned.")                  .setDescription(user.user.tag + " has been beaned." + (!dm ? "\nThey have DMs disabled. They will not know that they have been beaned." : ''))
136                  .addFields([                  .addFields([
137                      {                      {
138                          name: "Beaned by",                          name: "Beaned by",
# Line 127  export default class BeanCommand extends Line 146  export default class BeanCommand extends
146              ]              ]
147          });          });
148      }      }
 }  
149    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26