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

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

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

revision 85 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, 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';
5  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
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 Punishment from '../../models/Punishment';
 import getMember from '../../utils/getMember';  
 import ms from 'ms';  
 import Punishment from '../../types/Punishment';  
9  import { fetchEmoji } from '../../utils/Emoji';  import { fetchEmoji } from '../../utils/Emoji';
10  import PunishmentType from '../../types/PunishmentType';  import PunishmentType from '../../types/PunishmentType';
11    
# Line 52  export default class WarningCommand exte Line 49  export default class WarningCommand exte
49              return;              return;
50          }          }
51    
52          const warnings = await Punishment.findAll({          const warnings = await Punishment.find({
53              where: {              guild_id: msg.guild!.id,
54                  guild_id: msg.guild!.id,              user_id: user.id,
55                  user_id: user.id,              type: PunishmentType.WARNING
56                  type: PunishmentType.WARNING          }).sort({ createdAt: -1 });
             },  
         });  
57    
58          if (warnings.length < 1) {          if (warnings.length < 1) {
59              await msg.reply({              await msg.reply({
# Line 75  export default class WarningCommand exte Line 70  export default class WarningCommand exte
70          let str = '';          let str = '';
71    
72          for await (const warning of warnings) {          for await (const warning of warnings) {
73              str += `ID: ${warning.get().id}\n`;              str += `ID: ${warning.id}\n`;
74              str += `Reason: ${warning.get().reason ?? '*No reason provided*'}\n`;              str += `Reason: ${warning.reason ?? '*No reason provided*'}\n`;
75    
76              try {              try {
77                  str += `Warned by: ${(await client.users.fetch(warning.get().mod_id)).tag}\n`;                  str += `Warned by: ${(await client.users.fetch(warning.mod_id)).tag}\n`;
78              }              }
79              catch (e) {              catch (e) {
80                  str += `Warned by: ${warning.get().mod_id}\n`;                  str += `Warned by: ${warning.mod_id}\n`;
81              }              }
82                            
83              str += `Date: ${warning.get().createdAt}\n\n`;              str += `Date: ${warning.createdAt}\n\n`;
84          }          }
85    
86          await msg.reply({          await msg.reply({
# Line 133  export default class WarningCommand exte Line 128  export default class WarningCommand exte
128              return;              return;
129          }          }
130    
131          const warning = await Punishment.destroy({          const warning = await Punishment.deleteOne({
132              where: {              guild_id: msg.guild!.id,
133                  guild_id: msg.guild!.id,              user_id: user.id,
134                  user_id: user.id,              type: PunishmentType.WARNING
                 type: PunishmentType.WARNING  
             },  
135          });          });
136    
137          if (warning < 1) {          if (warning.deletedCount < 1) {
138              await msg.reply({              await msg.reply({
139                  embeds: [                  embeds: [
140                      new MessageEmbed()                      new MessageEmbed()
# Line 175  export default class WarningCommand exte Line 168  export default class WarningCommand exte
168              return;              return;
169          }          }
170    
171          const id = options.isInteraction ? options.options.getNumber('id') : parseInt(options.args[0]);          const id = options.isInteraction ? options.options.getString('id') : parseInt(options.args[0]);
172    
173          const warning = await Punishment.findOne({          const warning = await Punishment.findOne({
174              where: {              id,
175                  id,              guild_id: msg.guild!.id,
176                  guild_id: msg.guild!.id,              type: PunishmentType.WARNING
                 type: PunishmentType.WARNING  
             },  
             order: [  
                 ['id', 'DESC']  
             ],  
177          });          });
178    
179          if (!warning) {          if (!warning) {
# Line 200  export default class WarningCommand exte Line 188  export default class WarningCommand exte
188              return;              return;
189          }          }
190    
191          await warning.destroy();          await warning.delete();
192    
193          await msg.reply({          await msg.reply({
194              embeds: [              embeds: [
# Line 224  export default class WarningCommand exte Line 212  export default class WarningCommand exte
212              return;              return;
213          }          }
214    
215          const id = options.isInteraction ? options.options.getNumber('id') : parseInt(options.args[0]);          const id = options.isInteraction ? options.options.getString('id') : parseInt(options.args[0]);
216    
217          const warning = await Punishment.findOne({          const warning = await Punishment.findOne({
218              where: {              id,
219                  id,              guild_id: msg.guild!.id,
220                  guild_id: msg.guild!.id,              type: PunishmentType.WARNING
                 type: PunishmentType.WARNING  
             },  
             order: [  
                 ['id', 'DESC']  
             ],  
221          });          });
222    
223          if (!warning) {          if (!warning) {

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26