1 |
import { ModalSubmitInteraction } from 'discord-modals'; |
import { ModalSubmitInteraction } from 'discord-modals'; |
2 |
import { AutocompleteInteraction, CommandInteraction, CommandInteractionOption, ContextMenuInteraction, Interaction, Message, MessageEditOptions, MessageOptions, MessagePayload, WebhookEditMessageOptions } from 'discord.js'; |
import { PermissionResolvable, AutocompleteInteraction, CommandInteraction, CommandInteractionOption, ContextMenuInteraction, Interaction, Message, MessageEditOptions, MessageOptions, MessagePayload, WebhookEditMessageOptions, SelectMenuInteraction, ButtonInteraction, GuildMember } from 'discord.js'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import AutoCompleteOptions from '../../types/AutoCompleteOptions'; |
import AutoCompleteOptions from '../../types/AutoCompleteOptions'; |
5 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
11 |
supportsContextMenu: boolean = false; |
supportsContextMenu: boolean = false; |
12 |
coolDown?: number; |
coolDown?: number; |
13 |
ownerOnly: boolean = false; |
ownerOnly: boolean = false; |
14 |
|
permissions: PermissionResolvable[] = []; |
15 |
|
|
16 |
|
|
17 |
constructor(private name: string, private category: string, private aliases: Array<string>) { |
constructor(private name: string, private category: string, private aliases: Array<string>) { |
18 |
|
|
19 |
} |
} |
20 |
|
|
21 |
getName(): string { |
getName(): string { |
22 |
return this.name; |
return this.name; |
23 |
} |
} |
24 |
|
|
25 |
getCategory(): string { |
getCategory(): string { |
26 |
return this.category; |
return this.category; |
27 |
} |
} |
28 |
|
|
29 |
getAliases(): Array<string> { |
getAliases(): Array<string> { |
30 |
return this.aliases; |
return this.aliases; |
31 |
} |
} |
32 |
|
|
33 |
|
async permissionValidation(client: DiscordClient, member: GuildMember): Promise <boolean> { |
34 |
|
return true; |
35 |
|
} |
36 |
|
|
37 |
async autoComplete(client: DiscordClient, interaction: AutocompleteInteraction, options: AutoCompleteOptions): Promise <void> { |
async autoComplete(client: DiscordClient, interaction: AutocompleteInteraction, options: AutoCompleteOptions): Promise <void> { |
38 |
|
|
54 |
return (await msg.editReply(options as string | MessagePayload | WebhookEditMessageOptions)) as Message; |
return (await msg.editReply(options as string | MessagePayload | WebhookEditMessageOptions)) as Message; |
55 |
} |
} |
56 |
|
|
57 |
|
async perms(client: DiscordClient, message: Message | Interaction) { |
58 |
|
let member: GuildMember | null = null; |
59 |
|
|
60 |
|
if (message.member && !(message.member instanceof GuildMember)) { |
61 |
|
try { |
62 |
|
member = (await message.guild?.members.fetch(message.member!.user.id)) ?? null; |
63 |
|
} |
64 |
|
catch (e) { |
65 |
|
console.log(e); |
66 |
|
return false; |
67 |
|
} |
68 |
|
} |
69 |
|
else { |
70 |
|
member = message.member; |
71 |
|
} |
72 |
|
|
73 |
|
for await (let permission of this.permissions) { |
74 |
|
if (!member?.permissions.has(permission, true)) { |
75 |
|
if (message instanceof Interaction && !message.isRepliable()) |
76 |
|
return; |
77 |
|
|
78 |
|
await message.reply({ |
79 |
|
embeds: [ |
80 |
|
{ |
81 |
|
description: ":x: You don't have enough permissions to run this command.", |
82 |
|
color: 0xf14a60 |
83 |
|
} |
84 |
|
] |
85 |
|
}); |
86 |
|
|
87 |
|
return false; |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
|
if (message instanceof Interaction && !message.isRepliable()) |
92 |
|
return; |
93 |
|
|
94 |
|
if (!(await this.permissionValidation(client, member!))) { |
95 |
|
await message.reply({ |
96 |
|
embeds: [ |
97 |
|
{ |
98 |
|
description: ":x: You don't have enough permissions to run this command.", |
99 |
|
color: 0xf14a60 |
100 |
|
} |
101 |
|
] |
102 |
|
}); |
103 |
|
|
104 |
|
return false; |
105 |
|
} |
106 |
|
|
107 |
|
return true; |
108 |
|
} |
109 |
|
|
110 |
|
async execute(client: DiscordClient, message: Message | Interaction, options: CommandOptions | InteractionOptions) { |
111 |
|
if (!(await this.perms(client, message))) { |
112 |
|
return; |
113 |
|
} |
114 |
|
|
115 |
|
await this.run(client, message, options); |
116 |
|
} |
117 |
|
|
118 |
abstract run(client: DiscordClient, message: Message | Interaction, options: CommandOptions | InteractionOptions): Promise<void>; |
abstract run(client: DiscordClient, message: Message | Interaction, options: CommandOptions | InteractionOptions): Promise<void>; |
|
} |
|
119 |
|
} |