/[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 106 by rakin, Mon Jul 29 17:28:37 2024 UTC revision 124 by rakin, Mon Jul 29 17:28:41 2024 UTC
# Line 11  import ms from 'ms'; Line 11  import ms from 'ms';
11  import { unmute } from './UnmuteCommand';  import { unmute } from './UnmuteCommand';
12  import PunishmentType from '../../types/PunishmentType';  import PunishmentType from '../../types/PunishmentType';
13    
14  export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined) {  export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) {
15      try {      try {
16          const { default: Punishment } = await import('../../models/Punishment');          const { default: Punishment } = await import('../../models/Punishment');
17                    
# Line 47  export async function mute(client: Disco Line 47  export async function mute(client: Disco
47              });              });
48          }          }
49                    
50            if (hard) {
51                const { default: Hardmute } = await import("../../models/Hardmute");
52                const roles = await user.roles.cache.filter(r => r.id !== msg.guild!.id);
53                await user.roles.remove(roles, reason);
54    
55                await Hardmute.create({
56                    user_id: user.id,
57                    roles: roles.map(role => role.id),
58                    guild_id: msg.guild!.id,
59                });
60            }
61    
62          const role = await msg.guild!.roles.fetch(client.config.get('mute_role'));          const role = await msg.guild!.roles.fetch(client.config.get('mute_role'));
63          await user.roles.add(role!);          await user.roles.add(role!, reason);
64    
65          await Punishment.create({          await Punishment.create({
66              type: PunishmentType.MUTE,              type: hard ? PunishmentType.HARDMUTE : PunishmentType.MUTE,
67              user_id: user.id,              user_id: user.id,
68              guild_id: msg.guild!.id,              guild_id: msg.guild!.id,
69              mod_id: msg.member!.user.id,              mod_id: msg.member!.user.id,
# Line 61  export async function mute(client: Disco Line 73  export async function mute(client: Disco
73                  time: timeInterval ? ms(timeInterval) : undefined                  time: timeInterval ? ms(timeInterval) : undefined
74              }              }
75          });          });
76            
77          await History.create(user.id, msg.guild!, 'mute', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);          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);  
78          await user.send({          await user.send({
79              embeds: [              embeds: [
80                  new MessageEmbed()                  new MessageEmbed()
# Line 78  export async function mute(client: Disco Line 89  export async function mute(client: Disco
89      catch (e) {      catch (e) {
90          console.log(e);          console.log(e);
91                    
92          await msg.reply({          if (msg instanceof Message)
93              embeds: [              await msg.reply({
94                  new MessageEmbed()                  embeds: [
95                  .setColor('#f14a60')                      new MessageEmbed()
96                  .setDescription("Failed to assign the muted role to this user. Maybe missing permisions/roles or I'm not allowed to assign roles this user?")                      .setColor('#f14a60')
97              ]                      .setDescription("Failed to assign the muted role to this user. Maybe missing permisions/roles or I'm not allowed to assign roles this user?")
98          });                  ]
99                });
100            else
101                await msg.editReply({
102                    embeds: [
103                        new MessageEmbed()
104                        .setColor('#f14a60')
105                        .setDescription("Failed to assign the muted role to this user. Maybe missing permisions/roles or I'm not allowed to assign roles this user?")
106                    ]
107                });
108    
109          return;          return;
110      }      }
# Line 110  export default class MuteCommand extends Line 130  export default class MuteCommand extends
130              return;              return;
131          }          }
132    
133            if (msg instanceof CommandInteraction)
134                await msg.deferReply();
135    
136          let user: GuildMember;          let user: GuildMember;
137          let reason: string | undefined;          let reason: string | undefined;
138          let time: string | undefined;          let time: string | undefined;
139          let timeInterval: number | undefined;          let timeInterval: number | undefined;
140          let dateTime: number | undefined;          let dateTime: number | undefined;
141            let hard: boolean = false;
142    
143          if (options.isInteraction) {          if (options.isInteraction) {
144              user = await <GuildMember> options.options.getMember('member');              user = await <GuildMember> options.options.getMember('member');
# Line 123  export default class MuteCommand extends Line 147  export default class MuteCommand extends
147                  reason = await <string> options.options.getString('reason');                  reason = await <string> options.options.getString('reason');
148              }              }
149    
150                if (options.options.getBoolean('hardmute')) {
151                    hard = await <boolean> options.options.getBoolean('hardmute');
152                }
153    
154              if (options.options.getString('time')) {              if (options.options.getString('time')) {
155                  time = await options.options.getString('time') as string;                  time = await options.options.getString('time') as string;
156                  timeInterval = await ms(time);                  timeInterval = await ms(time);
157    
158                  if (!timeInterval) {                  if (!timeInterval) {
159                      await msg.reply({                      await this.deferReply(msg, {
160                          embeds: [                          embeds: [
161                              new MessageEmbed()                              new MessageEmbed()
162                              .setColor('#f14a60')                              .setColor('#f14a60')
# Line 144  export default class MuteCommand extends Line 172  export default class MuteCommand extends
172              const user2 = await getMember((msg as Message), options);              const user2 = await getMember((msg as Message), options);
173    
174              if (!user2) {              if (!user2) {
175                  await msg.reply({                  await this.deferReply(msg, {
176                      embeds: [                      embeds: [
177                          new MessageEmbed()                          new MessageEmbed()
178                          .setColor('#f14a60')                          .setColor('#f14a60')
# Line 164  export default class MuteCommand extends Line 192  export default class MuteCommand extends
192                  args.shift();                  args.shift();
193    
194                  if (index !== -1) {                  if (index !== -1) {
195                      args.splice(index - 1, 2)                      args.splice(index - 1, 2);
196                  }                  }
197    
198                  reason = await args.join(' ');                  reason = await args.join(' ');
# Line 174  export default class MuteCommand extends Line 202  export default class MuteCommand extends
202                  time = await options.args[index + 1];                  time = await options.args[index + 1];
203    
204                  if (time === undefined) {                  if (time === undefined) {
205                      await msg.reply({                      await this.deferReply(msg, {
206                          embeds: [                          embeds: [
207                              new MessageEmbed()                              new MessageEmbed()
208                              .setColor('#f14a60')                              .setColor('#f14a60')
# Line 186  export default class MuteCommand extends Line 214  export default class MuteCommand extends
214                  }                  }
215    
216                  if (!ms(time)) {                  if (!ms(time)) {
217                      await msg.reply({                      await this.deferReply(msg, {
218                          embeds: [                          embeds: [
219                              new MessageEmbed()                              new MessageEmbed()
220                              .setColor('#f14a60')                              .setColor('#f14a60')
# Line 205  export default class MuteCommand extends Line 233  export default class MuteCommand extends
233              dateTime = Date.now() + timeInterval;              dateTime = Date.now() + timeInterval;
234          }          }
235    
236          await mute(client, dateTime, user, msg, timeInterval, reason);          await mute(client, dateTime, user, msg, timeInterval, reason, hard);
237    
238          const fields = [          const fields = [
239              {              {
# Line 219  export default class MuteCommand extends Line 247  export default class MuteCommand extends
247              {              {
248                  name: "Duration",                  name: "Duration",
249                  value: time === undefined ? "*No duration set*" : (time + '')                  value: time === undefined ? "*No duration set*" : (time + '')
250                },
251                {
252                    name: "Role Takeout",
253                    value: hard ? 'Yes' : 'No'
254              }              }
255          ];          ];
256    
257          console.log(fields);                  console.log(fields);        
258    
259          await msg.reply({          await this.deferReply(msg, {
260              embeds: [              embeds: [
261                  new MessageEmbed()                  new MessageEmbed()
262                  .setAuthor({                  .setAuthor({

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26