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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3258 byte(s)
Release version 2.0
1 rakin 51 import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User } from 'discord.js';
2     import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4     import CommandOptions from '../../types/CommandOptions';
5     import InteractionOptions from '../../types/InteractionOptions';
6     import MessageEmbed from '../../client/MessageEmbed';
7     import getUser from '../../utils/getUser';
8     import History from '../../automod/History';
9     import getMember from '../../utils/getMember';
10     import ms from 'ms';
11 rakin 5
12 rakin 51 export default class WarningCommand extends BaseCommand {
13     supportsInteractions: boolean = true;
14    
15     constructor() {
16     super('warning', 'moderation', []);
17     }
18    
19     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
20     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
21 rakin 5 await msg.reply({
22     embeds: [
23     new MessageEmbed()
24     .setColor('#f14a60')
25     .setDescription(`This command requires at least one argument.`)
26     ]
27     });
28    
29     return;
30     }
31    
32 rakin 51 let id: string;
33    
34     if (options.isInteraction) {
35     id = await options.options.getNumber('id')?.toString()!;
36     }
37     else {
38     id = options.args[0];
39     }
40    
41     await client.db.get('SELECT * FROM warnings WHERE id = ?', [id], async (err: any, data: any) => {
42 rakin 5 if (err) {
43     console.log(err);
44     }
45    
46     if (!data) {
47     await msg.reply({
48     embeds: [
49     new MessageEmbed()
50     .setColor('#f14a60')
51     .setDescription(`No warning found.`)
52     ]
53     });
54    
55     return;
56     }
57    
58     let user = data.user_id;
59    
60     console.log('here1');
61    
62     try {
63 rakin 51 user = await msg.guild!.members.fetch(data.user_id);
64 rakin 5 }
65     catch(e) {
66     console.log(e);
67     }
68    
69    
70     console.log('user2');
71    
72     let by = data.warned_by;
73    
74     console.log(data);
75    
76     try {
77 rakin 51 by = await msg.guild!.members.fetch(data.warned_by);
78 rakin 5 }
79     catch(e) {
80     console.log(e);
81     }
82    
83     console.log('here');
84     let embed = await new MessageEmbed()
85     .setDescription(data.reason === '\c\b\c' ? "*No reason provided*" : data.reason)
86     .addField('ID', data.id + '')
87     .addField('Warned by', typeof by === 'string' ? by : by.user.tag);
88    
89     if (typeof user === 'string') {
90     embed.setAuthor({
91     name: `${user}`
92     });
93     }
94     else {
95     embed.setAuthor({
96     iconURL: user.displayAvatarURL(),
97     name: `${user.user.tag}`
98     })
99     }
100    
101    
102     await msg.reply({
103     embeds: [
104     embed
105     ]
106     });
107 rakin 51 });
108 rakin 5 }
109 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26