xernerx 4.4.3 → 4.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/ContextCommandBuilder.d.ts +49 -0
- package/dist/build/ContextCommandBuilder.js +67 -0
- package/dist/build/EventBuilder.d.ts +24 -0
- package/dist/build/EventBuilder.js +29 -0
- package/dist/build/InhibitorBuilder.d.ts +19 -0
- package/dist/build/InhibitorBuilder.js +22 -0
- package/dist/build/MessageCommandBuilder.d.ts +47 -0
- package/dist/build/MessageCommandBuilder.js +60 -0
- package/dist/build/SlashCommandBuilder.d.ts +55 -0
- package/dist/build/SlashCommandBuilder.js +113 -0
- package/dist/client/XernerxClient.d.ts +55 -0
- package/dist/client/XernerxClient.js +82 -0
- package/dist/client/XernerxShardClient.d.ts +16 -0
- package/dist/client/XernerxShardClient.js +32 -0
- package/dist/functions/delay.d.ts +1 -0
- package/dist/functions/delay.js +3 -0
- package/dist/functions/deploy.d.ts +2 -0
- package/dist/functions/deploy.js +33 -0
- package/dist/functions/isOwner.d.ts +3 -0
- package/dist/functions/isOwner.js +3 -0
- package/dist/functions/isVoter.d.ts +3 -0
- package/dist/functions/isVoter.js +5 -0
- package/dist/functions/load.d.ts +3 -0
- package/dist/functions/load.js +32 -0
- package/dist/functions/reload.d.ts +2 -0
- package/dist/functions/reload.js +39 -0
- package/dist/functions/sendWebhook.d.ts +2 -0
- package/dist/functions/sendWebhook.js +12 -0
- package/dist/functions/setPresence.d.ts +3 -0
- package/dist/functions/setPresence.js +19 -0
- package/dist/functions/xernerxUser.d.ts +3 -0
- package/dist/functions/xernerxUser.js +8 -0
- package/dist/handlers/CommandHandler.d.ts +13 -0
- package/dist/handlers/CommandHandler.js +251 -0
- package/dist/handlers/EventHandler.d.ts +7 -0
- package/dist/handlers/EventHandler.js +24 -0
- package/dist/handlers/ExtensionHandler.d.ts +7 -0
- package/dist/handlers/ExtensionHandler.js +21 -0
- package/dist/handlers/Handler.d.ts +14 -0
- package/dist/handlers/Handler.js +36 -0
- package/dist/handlers/InhibitorHandler.d.ts +7 -0
- package/dist/handlers/InhibitorHandler.js +24 -0
- package/dist/handlers/WebhookHandler.d.ts +7 -0
- package/dist/handlers/WebhookHandler.js +50 -0
- package/dist/main.d.ts +42 -0
- package/dist/main.js +43 -0
- package/dist/models/Arguments.d.ts +8 -0
- package/dist/models/Arguments.js +135 -0
- package/dist/tools/XernerxError.d.ts +6 -0
- package/dist/tools/XernerxError.js +10 -0
- package/dist/tools/XernerxLog.d.ts +14 -0
- package/dist/tools/XernerxLog.js +48 -0
- package/dist/types/extenders.d.ts +28 -0
- package/dist/types/extenders.js +1 -0
- package/dist/types/interfaces.d.ts +236 -0
- package/dist/types/interfaces.js +1 -0
- package/dist/types/types.d.ts +181 -0
- package/dist/types/types.js +1 -0
- package/dist/utils/ClientUtil.d.ts +10 -0
- package/dist/utils/ClientUtil.js +30 -0
- package/dist/utils/InteractionUtil.d.ts +10 -0
- package/dist/utils/InteractionUtil.js +15 -0
- package/dist/utils/MessageUtil.d.ts +15 -0
- package/dist/utils/MessageUtil.js +46 -0
- package/dist/utils/Util.d.ts +5 -0
- package/dist/utils/Util.js +6 -0
- package/dist/validators/commandValidation.d.ts +6 -0
- package/dist/validators/commandValidation.js +49 -0
- package/dist/validators/inhibitorValidations.d.ts +18 -0
- package/dist/validators/inhibitorValidations.js +34 -0
- package/package.json +1 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SlashCommandBooleanOption,
|
|
3
|
+
SlashCommandChannelOption,
|
|
4
|
+
SlashCommandIntegerOption,
|
|
5
|
+
SlashCommandMentionableOption,
|
|
6
|
+
SlashCommandNumberOption,
|
|
7
|
+
SlashCommandRoleOption,
|
|
8
|
+
SlashCommandStringOption,
|
|
9
|
+
SlashCommandUserOption,
|
|
10
|
+
} from 'discord.js';
|
|
11
|
+
import { XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUserContextInteraction } from './extenders.js';
|
|
12
|
+
export type FileType = 'MessageCommand' | 'SlashCommand' | 'ContextCommand' | 'Event' | 'Inhibitor';
|
|
13
|
+
export type Locales =
|
|
14
|
+
| 'en-US'
|
|
15
|
+
| 'en-GB'
|
|
16
|
+
| 'bg'
|
|
17
|
+
| 'zh-CN'
|
|
18
|
+
| 'zh-TW'
|
|
19
|
+
| 'hr'
|
|
20
|
+
| 'cs'
|
|
21
|
+
| 'da'
|
|
22
|
+
| 'nl'
|
|
23
|
+
| 'fi'
|
|
24
|
+
| 'fr'
|
|
25
|
+
| 'de'
|
|
26
|
+
| 'el'
|
|
27
|
+
| 'hi'
|
|
28
|
+
| 'hu'
|
|
29
|
+
| 'it'
|
|
30
|
+
| 'ja'
|
|
31
|
+
| 'ko'
|
|
32
|
+
| 'lt'
|
|
33
|
+
| 'no'
|
|
34
|
+
| 'pl'
|
|
35
|
+
| 'pt-BR'
|
|
36
|
+
| 'ro'
|
|
37
|
+
| 'ru'
|
|
38
|
+
| 'es-ES'
|
|
39
|
+
| 'sv-SE'
|
|
40
|
+
| 'th'
|
|
41
|
+
| 'tr'
|
|
42
|
+
| 'uk'
|
|
43
|
+
| 'vi';
|
|
44
|
+
export type SlashCommandArgumentType = 'attachment' | 'boolean' | 'channel' | 'integer' | 'mentionable' | 'number' | 'role' | 'string' | 'user';
|
|
45
|
+
export type SlashCommandOptionChoices = SlashCommandStringOption | SlashCommandNumberOption | SlashCommandIntegerOption;
|
|
46
|
+
export type SlashCommandOption = SlashCommandOptionChoices | SlashCommandBooleanOption | SlashCommandUserOption | SlashCommandChannelOption | SlashCommandRoleOption | SlashCommandMentionableOption;
|
|
47
|
+
export type MessageCommandArgumentType =
|
|
48
|
+
| 'string'
|
|
49
|
+
| 'number'
|
|
50
|
+
| 'boolean'
|
|
51
|
+
| 'confirm'
|
|
52
|
+
| 'channel'
|
|
53
|
+
| 'guild'
|
|
54
|
+
| 'integer'
|
|
55
|
+
| 'mentionable'
|
|
56
|
+
| 'role'
|
|
57
|
+
| 'user'
|
|
58
|
+
| 'message'
|
|
59
|
+
| 'member'
|
|
60
|
+
| 'list'
|
|
61
|
+
| 'option'
|
|
62
|
+
| 'rest';
|
|
63
|
+
export type DiscordEventType =
|
|
64
|
+
| 'applicationCommandPermissionsUpdate'
|
|
65
|
+
| 'autoModerationActionExecution'
|
|
66
|
+
| 'autoModerationRuleCreate'
|
|
67
|
+
| 'autoModerationRuleDelete'
|
|
68
|
+
| 'autoModerationRuleUpdate'
|
|
69
|
+
| 'ready'
|
|
70
|
+
| 'guildCreate'
|
|
71
|
+
| 'guildDelete'
|
|
72
|
+
| 'guildUpdate'
|
|
73
|
+
| 'guildUnavailable'
|
|
74
|
+
| 'guildMemberAdd'
|
|
75
|
+
| 'guildMemberRemove'
|
|
76
|
+
| 'guildMemberUpdate'
|
|
77
|
+
| 'guildMemberAvailable'
|
|
78
|
+
| 'guildMembersChunk'
|
|
79
|
+
| 'guildIntegrationsUpdate'
|
|
80
|
+
| 'roleCreate'
|
|
81
|
+
| 'roleDelete'
|
|
82
|
+
| 'inviteCreate'
|
|
83
|
+
| 'inviteDelete'
|
|
84
|
+
| 'roleUpdate'
|
|
85
|
+
| 'emojiCreate'
|
|
86
|
+
| 'emojiDelete'
|
|
87
|
+
| 'emojiUpdate'
|
|
88
|
+
| 'guildBanAdd'
|
|
89
|
+
| 'guildBanRemove'
|
|
90
|
+
| 'channelCreate'
|
|
91
|
+
| 'channelDelete'
|
|
92
|
+
| 'channelUpdate'
|
|
93
|
+
| 'channelPinsUpdate'
|
|
94
|
+
| 'messageCreate'
|
|
95
|
+
| 'messageDelete'
|
|
96
|
+
| 'messageUpdate'
|
|
97
|
+
| 'messageDeleteBulk'
|
|
98
|
+
| 'messageReactionAdd'
|
|
99
|
+
| 'messageReactionRemove'
|
|
100
|
+
| 'messageReactionRemoveAll'
|
|
101
|
+
| 'messageReactionRemoveEmoji'
|
|
102
|
+
| 'threadCreate'
|
|
103
|
+
| 'threadDelete'
|
|
104
|
+
| 'threadUpdate'
|
|
105
|
+
| 'threadListSync'
|
|
106
|
+
| 'threadMemberUpdate'
|
|
107
|
+
| 'threadMembersUpdate'
|
|
108
|
+
| 'userUpdate'
|
|
109
|
+
| 'presenceUpdate'
|
|
110
|
+
| 'voiceServerUpdate'
|
|
111
|
+
| 'voiceStateUpdate'
|
|
112
|
+
| 'typingStart'
|
|
113
|
+
| 'webhookUpdate'
|
|
114
|
+
| 'interactionCreate'
|
|
115
|
+
| 'error'
|
|
116
|
+
| 'warn'
|
|
117
|
+
| 'debug'
|
|
118
|
+
| 'cacheSweep'
|
|
119
|
+
| 'shardDisconnect'
|
|
120
|
+
| 'shardError'
|
|
121
|
+
| 'shardReconnecting'
|
|
122
|
+
| 'shardReady'
|
|
123
|
+
| 'shardResume'
|
|
124
|
+
| 'invalidated'
|
|
125
|
+
| 'raw'
|
|
126
|
+
| 'stageInstanceCreate'
|
|
127
|
+
| 'stageInstanceUpdate'
|
|
128
|
+
| 'stageInstanceDelete'
|
|
129
|
+
| 'stickerCreate'
|
|
130
|
+
| 'stickerDelete'
|
|
131
|
+
| 'stickerUpdate'
|
|
132
|
+
| 'guildScheduledEventCreate'
|
|
133
|
+
| 'guildScheduledEventUpdate'
|
|
134
|
+
| 'guildScheduledEventDelete'
|
|
135
|
+
| 'guildScheduledEventUserAdd'
|
|
136
|
+
| 'guildScheduledEventUserRemove';
|
|
137
|
+
export type EventType = DiscordEventType | 'webhookInit' | 'webhookPost' | 'webhookError';
|
|
138
|
+
export type XernerxInteraction = XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction;
|
|
139
|
+
export type PermissionNames =
|
|
140
|
+
| 'create instant invite'
|
|
141
|
+
| 'kick members'
|
|
142
|
+
| 'ban members'
|
|
143
|
+
| 'administrator'
|
|
144
|
+
| 'manage channels'
|
|
145
|
+
| 'manage guild'
|
|
146
|
+
| 'add reactions'
|
|
147
|
+
| 'view audit log'
|
|
148
|
+
| 'priority speaker'
|
|
149
|
+
| 'stream'
|
|
150
|
+
| 'view channel'
|
|
151
|
+
| 'send messages'
|
|
152
|
+
| 'send tts messages'
|
|
153
|
+
| 'manage messages'
|
|
154
|
+
| 'embed links'
|
|
155
|
+
| 'attach files'
|
|
156
|
+
| 'read message history'
|
|
157
|
+
| 'mention everyone'
|
|
158
|
+
| 'use external emojis'
|
|
159
|
+
| 'view guild insights'
|
|
160
|
+
| 'connect'
|
|
161
|
+
| 'speak'
|
|
162
|
+
| 'mute members'
|
|
163
|
+
| 'deafen members'
|
|
164
|
+
| 'move members'
|
|
165
|
+
| 'use vad'
|
|
166
|
+
| 'change nickname'
|
|
167
|
+
| 'manage nicknames'
|
|
168
|
+
| 'manage roles'
|
|
169
|
+
| 'manage webhooks'
|
|
170
|
+
| 'manage emojis and stickers'
|
|
171
|
+
| 'use application commands'
|
|
172
|
+
| 'request to speak'
|
|
173
|
+
| 'manage events'
|
|
174
|
+
| 'manage threads'
|
|
175
|
+
| 'create public threads'
|
|
176
|
+
| 'create private threads'
|
|
177
|
+
| 'use external stickers'
|
|
178
|
+
| 'send messages in threads'
|
|
179
|
+
| 'start embedded activities'
|
|
180
|
+
| 'moderate members';
|
|
181
|
+
export type InhibitorType = 'message' | 'interaction' | 'command' | 'channel' | 'user' | 'member' | 'guild' | 'contextCommand' | 'messageCommand' | 'slashCommand';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
2
|
+
import { PresenceOptions } from '../types/interfaces.js';
|
|
3
|
+
import Util from './Util.js';
|
|
4
|
+
export default class ClientUtil extends Util {
|
|
5
|
+
hasVoted?: Function;
|
|
6
|
+
constructor(client: XernerxClient);
|
|
7
|
+
setPresence(options: PresenceOptions): import('discord.js').ClientPresence | undefined;
|
|
8
|
+
resolveChannel(query: string | Record<string, string>): Promise<import('discord.js').Channel | null>;
|
|
9
|
+
resolveGuild(query: string | Record<string, string>): Promise<import('discord.js').Guild | null>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import setPresence from '../functions/setPresence.js';
|
|
2
|
+
import Util from './Util.js';
|
|
3
|
+
export default class ClientUtil extends Util {
|
|
4
|
+
constructor(client) {
|
|
5
|
+
super(client);
|
|
6
|
+
}
|
|
7
|
+
setPresence(options) {
|
|
8
|
+
return setPresence(this.client, options);
|
|
9
|
+
}
|
|
10
|
+
async resolveChannel(query) {
|
|
11
|
+
if (typeof query == 'object') query = query.id;
|
|
12
|
+
try {
|
|
13
|
+
let channel = this.client.channels.cache.find((channel) => (channel.name == query.toLowerCase() || channel.id == query.toLowerCase() ? channel : null)) || null;
|
|
14
|
+
if (!channel) channel = (await this.client.channels.fetch(query)) || null;
|
|
15
|
+
return channel;
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async resolveGuild(query) {
|
|
21
|
+
if (typeof query == 'object') query = query.id;
|
|
22
|
+
try {
|
|
23
|
+
let guild = this.client.guilds.cache.find((guild) => guild.name.toLowerCase() == query.toLowerCase()) || null;
|
|
24
|
+
if (!guild) guild = (await this.client.guilds.fetch(query)) || null;
|
|
25
|
+
return guild;
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MessagePayload } from 'discord.js';
|
|
2
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
+
import { XernerxInteraction } from '../types/types.js';
|
|
4
|
+
import Util from './Util.js';
|
|
5
|
+
export default class InteractionUtil extends Util {
|
|
6
|
+
private interaction;
|
|
7
|
+
constructor(client: XernerxClient, interaction: XernerxInteraction);
|
|
8
|
+
reply(content: MessagePayload): Promise<import('discord.js').Message<boolean> | import('discord.js').InteractionResponse<boolean>>;
|
|
9
|
+
delay(time: number): Promise<unknown>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import delay from '../functions/delay.js';
|
|
2
|
+
import Util from './Util.js';
|
|
3
|
+
export default class InteractionUtil extends Util {
|
|
4
|
+
interaction;
|
|
5
|
+
constructor(client, interaction) {
|
|
6
|
+
super(client);
|
|
7
|
+
this.interaction = interaction;
|
|
8
|
+
}
|
|
9
|
+
async reply(content) {
|
|
10
|
+
return await (this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content));
|
|
11
|
+
}
|
|
12
|
+
async delay(time) {
|
|
13
|
+
return await delay(time);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MessagePayload, User } from 'discord.js';
|
|
2
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
+
import { XernerxMessage } from '../types/extenders.js';
|
|
4
|
+
import Util from './Util.js';
|
|
5
|
+
export default class MessageUtil extends Util {
|
|
6
|
+
private readonly message;
|
|
7
|
+
parsed: {
|
|
8
|
+
alias: null | string;
|
|
9
|
+
prefix: null | string;
|
|
10
|
+
};
|
|
11
|
+
constructor(client: XernerxClient, message: XernerxMessage);
|
|
12
|
+
reply(content: MessagePayload): Promise<import('discord.js').Message<boolean> | undefined>;
|
|
13
|
+
webhookReply(content: MessagePayload, url?: URL, user?: User): Promise<void>;
|
|
14
|
+
delay(time: number): Promise<unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ChannelType } from 'discord.js';
|
|
2
|
+
import delay from '../functions/delay.js';
|
|
3
|
+
import Util from './Util.js';
|
|
4
|
+
import sendWebhook from '../functions/sendWebhook.js';
|
|
5
|
+
import XernerxError from '../tools/XernerxError.js';
|
|
6
|
+
export default class MessageUtil extends Util {
|
|
7
|
+
message;
|
|
8
|
+
constructor(client, message) {
|
|
9
|
+
super(client);
|
|
10
|
+
this.message = message;
|
|
11
|
+
this.parsed = {
|
|
12
|
+
alias: null,
|
|
13
|
+
prefix: null,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async reply(content) {
|
|
17
|
+
if (this.client.cache.messages.has(this.message.id)) {
|
|
18
|
+
const id = this.client.cache.messages.get(this.message.id);
|
|
19
|
+
if (!id) return;
|
|
20
|
+
const msg = await this.message.channel.messages.fetch(id);
|
|
21
|
+
msg.edit(content);
|
|
22
|
+
return msg;
|
|
23
|
+
}
|
|
24
|
+
const msg = await this.message.reply(content);
|
|
25
|
+
this.client.cache.messages.set(this.message.id, msg.id);
|
|
26
|
+
return msg;
|
|
27
|
+
}
|
|
28
|
+
async webhookReply(content, url, user) {
|
|
29
|
+
if (this.message.channel.type === ChannelType.DM) throw new XernerxError(`Can't use this method in DM Channels`);
|
|
30
|
+
const channel = this.message.channel;
|
|
31
|
+
let webhook;
|
|
32
|
+
if (!url) {
|
|
33
|
+
webhook = await channel.createWebhook({
|
|
34
|
+
name: user?.username || this.client.user?.username,
|
|
35
|
+
avatar: user?.avatarURL() || this.client.user?.avatarURL(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!webhook) webhook = { url };
|
|
39
|
+
await sendWebhook(webhook.url, content);
|
|
40
|
+
if (!url) webhook.delete();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
async delay(time) {
|
|
44
|
+
return await delay(time);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import ContextCommandBuilder from '../build/ContextCommandBuilder.js';
|
|
2
|
+
import MessageCommandBuilder from '../build/MessageCommandBuilder.js';
|
|
3
|
+
import SlashCommandBuilder from '../build/SlashCommandBuilder.js';
|
|
4
|
+
import { XernerxMessage } from '../types/extenders.js';
|
|
5
|
+
import { XernerxInteraction } from '../types/types.js';
|
|
6
|
+
export default function commandValidation(event: XernerxInteraction | XernerxMessage, command: MessageCommandBuilder | SlashCommandBuilder | ContextCommandBuilder): Promise<boolean>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ChannelType, PermissionFlagsBits } from 'discord.js';
|
|
2
|
+
export default async function commandValidation(event, command) {
|
|
3
|
+
const client = event.client;
|
|
4
|
+
if (command.ignore?.owner && client.settings.ownerId.includes(event.user.id)) return false;
|
|
5
|
+
if (!client.cache.cooldowns.has(`${event.user.id}-${command.name}`)) {
|
|
6
|
+
client.cache.cooldowns.set(`${event.user.id}-${command.name}`, {
|
|
7
|
+
id: event.user.id,
|
|
8
|
+
command: command.name,
|
|
9
|
+
createdTimestamp: Number(Date.now()) + (command.cooldown || 0),
|
|
10
|
+
});
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
client.cache.cooldowns.delete(`${event.user.id}-${command.name}`);
|
|
13
|
+
}, command.cooldown || 0);
|
|
14
|
+
} else {
|
|
15
|
+
const user = client.cache.cooldowns.get(`${event.user.id}-${command.name}`);
|
|
16
|
+
const time = (user?.createdTimestamp || 0) - Number(Date.now());
|
|
17
|
+
return emit(event, `Command on cooldown, ${time}`);
|
|
18
|
+
}
|
|
19
|
+
if ((command.ignore?.channels?.length || 0) > 0 && command.ignore?.channels?.includes(event.channel?.id)) return true;
|
|
20
|
+
if ((command.ignore?.guilds?.length || 0) > 0 && command.ignore?.guilds?.includes(event.guild?.id)) return true;
|
|
21
|
+
if ((command.ignore?.users?.length || 0) > 0 && command.ignore?.users?.includes(event.user.id)) return true;
|
|
22
|
+
if (command.strict?.owner && !client.settings.ownerId.includes(event.user.id)) return await emit(event, 'Command is a developer command');
|
|
23
|
+
if ((command.strict?.channels?.length || 0) > 0 && !command.strict?.channels?.includes(event.channel?.id)) return await emit(event, 'Command cannot be ran in this channel');
|
|
24
|
+
if ((command.strict?.guilds?.length || 0) > 0 && !command.strict?.guilds?.includes(event.guild?.id)) return await emit(event, 'Command cannot be ran in this guild');
|
|
25
|
+
if ((command.strict?.users?.length || 0) > 0 && !command.strict?.users?.includes(event.user.id)) return await emit(event, 'Command cannot be ran by you');
|
|
26
|
+
if (command.permissions?.dm == false && event.channel?.type === ChannelType.DM) return await emit(event, "Can't use in a DM Channel");
|
|
27
|
+
if (command.permissions?.user) {
|
|
28
|
+
if (!(event.member?.permissions).has(toBigInt(command.permissions.user))) return await emit(event, 'Missing User Permissions');
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
async function emit(event, reason) {
|
|
33
|
+
event.client.emit('commandBlock', event, reason);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
function toBigInt(permissions) {
|
|
37
|
+
let bigIntPermissions = 0n;
|
|
38
|
+
permissions.map((permission) => {
|
|
39
|
+
permission =
|
|
40
|
+
PermissionFlagsBits[
|
|
41
|
+
permission
|
|
42
|
+
.split(/ +/)
|
|
43
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
44
|
+
.join('')
|
|
45
|
+
];
|
|
46
|
+
if (typeof permission === 'bigint') bigIntPermissions += permission;
|
|
47
|
+
});
|
|
48
|
+
return bigIntPermissions;
|
|
49
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ContextCommandBuilder, MessageCommandBuilder, SlashCommandBuilder } from '../main.js';
|
|
2
|
+
import { XernerxMessage } from '../types/extenders.js';
|
|
3
|
+
import { InhibitorType, XernerxInteraction } from '../types/types.js';
|
|
4
|
+
export declare function inhibitorValidation(event: XernerxMessage | XernerxInteraction, cmd?: ContextCommandBuilder | MessageCommandBuilder | SlashCommandBuilder): Promise<boolean>;
|
|
5
|
+
export declare function inhibitorArguments(
|
|
6
|
+
event: XernerxMessage | XernerxInteraction,
|
|
7
|
+
cmd: ContextCommandBuilder | MessageCommandBuilder | SlashCommandBuilder | null,
|
|
8
|
+
type: InhibitorType
|
|
9
|
+
):
|
|
10
|
+
| import('discord.js').Guild
|
|
11
|
+
| import('discord.js').GuildMember
|
|
12
|
+
| import('discord.js').TextBasedChannel
|
|
13
|
+
| import('discord.js').User
|
|
14
|
+
| SlashCommandBuilder
|
|
15
|
+
| ContextCommandBuilder
|
|
16
|
+
| MessageCommandBuilder
|
|
17
|
+
| import('../main.js').APIInteractionGuildMember
|
|
18
|
+
| null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export async function inhibitorValidation(event, cmd) {
|
|
2
|
+
const client = event.client;
|
|
3
|
+
const inhibits = [];
|
|
4
|
+
for (const [name, inhibitor] of client.inhibitors) {
|
|
5
|
+
if (Boolean(await inhibitor.check(event, await inhibitorArguments(event, cmd || null, inhibitor.type)))) {
|
|
6
|
+
inhibits.push(name);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return !!inhibits.length;
|
|
10
|
+
}
|
|
11
|
+
export function inhibitorArguments(event, cmd, type) {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case 'channel':
|
|
14
|
+
return event.channel || null;
|
|
15
|
+
case 'command':
|
|
16
|
+
return cmd;
|
|
17
|
+
case 'contextCommand':
|
|
18
|
+
return cmd;
|
|
19
|
+
case 'guild':
|
|
20
|
+
return event.guild || null;
|
|
21
|
+
case 'interaction':
|
|
22
|
+
return null;
|
|
23
|
+
case 'member':
|
|
24
|
+
return event.member || null;
|
|
25
|
+
case 'message':
|
|
26
|
+
return null;
|
|
27
|
+
case 'messageCommand':
|
|
28
|
+
return cmd;
|
|
29
|
+
case 'slashCommand':
|
|
30
|
+
return cmd;
|
|
31
|
+
case 'user':
|
|
32
|
+
return event.user;
|
|
33
|
+
}
|
|
34
|
+
}
|