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

Diff of /trunk/src/commands/moderation/MuteCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 124 by rakin, Mon Jul 29 17:28:41 2024 UTC revision 341 by rakin, Mon Jul 29 17:29:38 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js';  import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, Permissions, 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';
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 ms from 'ms';
 import { unmute } from './UnmuteCommand';  
9  import PunishmentType from '../../types/PunishmentType';  import PunishmentType from '../../types/PunishmentType';
10    import { hasPermission, shouldNotModerate } from '../../utils/util';
11    
12  export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) {  export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) {
13      try {      try {
# Line 56  export async function mute(client: Disco Line 54  export async function mute(client: Disco
54                  user_id: user.id,                  user_id: user.id,
55                  roles: roles.map(role => role.id),                  roles: roles.map(role => role.id),
56                  guild_id: msg.guild!.id,                  guild_id: msg.guild!.id,
57                    createdAt: new Date()
58              });              });
59          }          }
60    
# Line 71  export async function mute(client: Disco Line 70  export async function mute(client: Disco
70              reason,              reason,
71              meta: {              meta: {
72                  time: timeInterval ? ms(timeInterval) : undefined                  time: timeInterval ? ms(timeInterval) : undefined
73              }              },
74                createdAt: new Date()
75          });          });
76                    
77          await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User, hard);          await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User, hard);
78          await user.send({  
79              embeds: [          try {
80                  new MessageEmbed()              await user.send({
81                  .setAuthor({                  embeds: [
82                      iconURL: <string> msg.guild!.iconURL(),                      new MessageEmbed()
83                      name: `\tYou have been muted in ${msg.guild!.name}`                      .setAuthor({
84                  })                          iconURL: <string> msg.guild!.iconURL(),
85                  .addField("Reason", reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason)                          name: `\tYou have been muted in ${msg.guild!.name}`
86              ]                      })
87          });                      .addField("Reason", reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason)
88                    ]
89                });
90            }
91            catch (e) {
92                console.log(e);
93            }
94      }      }
95      catch (e) {      catch (e) {
96          console.log(e);          console.log(e);
# Line 112  export async function mute(client: Disco Line 118  export async function mute(client: Disco
118    
119  export default class MuteCommand extends BaseCommand {  export default class MuteCommand extends BaseCommand {
120      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
121        permissions = [Permissions.FLAGS.MODERATE_MEMBERS];
122    
123      constructor() {      constructor() {
124          super('mute', 'moderation', []);          super('mute', 'moderation', []);
# Line 233  export default class MuteCommand extends Line 240  export default class MuteCommand extends
240              dateTime = Date.now() + timeInterval;              dateTime = Date.now() + timeInterval;
241          }          }
242    
243            if (!(await hasPermission(client, user, msg, null, "You don't have permission to mute this user."))) {
244                return;
245            }
246            
247            if (shouldNotModerate(client, user)) {
248                await msg.reply({
249                    embeds: [
250                        {
251                            description: "This user cannot be muted."
252                        }
253                    ]
254                });
255    
256                return;
257            }
258            
259          await mute(client, dateTime, user, msg, timeInterval, reason, hard);          await mute(client, dateTime, user, msg, timeInterval, reason, hard);
260    
261          const fields = [          const fields = [
# Line 268  export default class MuteCommand extends Line 291  export default class MuteCommand extends
291              ]              ]
292          });          });
293      }      }
 }  
294    }

Legend:
Removed from v.124  
changed lines
  Added in v.341

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26