xernerx 4.14.1 → 4.15.1
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/client/XernerxClient.d.ts +3 -3
- package/dist/utils/ClientUtil.d.ts +1 -1
- package/dist/utils/ClientUtil.js +1 -1
- package/dist/utils/InteractionUtil.d.ts +2 -1
- package/dist/utils/InteractionUtil.js +26 -0
- package/dist/utils/MessageUtil.d.ts +2 -0
- package/dist/utils/MessageUtil.js +26 -0
- package/dist/validators/commandValidation.js +10 -22
- package/package.json +5 -3
- package/dist/functions/sendWebhook.d.ts +0 -4
- package/dist/functions/sendWebhook.js +0 -14
- package/dist/handlers/WebhookHandler.d.ts +0 -8
- package/dist/handlers/WebhookHandler.js +0 -10
|
@@ -17,19 +17,19 @@ export default class XernerxClient extends Client {
|
|
|
17
17
|
dm: boolean;
|
|
18
18
|
} | undefined;
|
|
19
19
|
ignore?: {
|
|
20
|
+
system: boolean;
|
|
21
|
+
users: string[];
|
|
20
22
|
owner: boolean;
|
|
21
23
|
self: boolean;
|
|
22
24
|
bots: boolean;
|
|
23
|
-
system: boolean;
|
|
24
|
-
users: string[];
|
|
25
25
|
channels: string[];
|
|
26
26
|
guilds: string[];
|
|
27
27
|
} | undefined;
|
|
28
28
|
log?: boolean | {
|
|
29
|
+
warn: boolean;
|
|
29
30
|
error: boolean;
|
|
30
31
|
ready: boolean;
|
|
31
32
|
info: boolean;
|
|
32
|
-
warn: boolean;
|
|
33
33
|
table: string[] | null;
|
|
34
34
|
} | undefined;
|
|
35
35
|
cooldown?: {
|
|
@@ -15,5 +15,5 @@ export default class ClientUtil extends Util {
|
|
|
15
15
|
resolveChannel(query: string | Record<string, string>): Promise<import("discord.js").Channel | null>;
|
|
16
16
|
resolveGuild(query: string | Record<string, string>): Promise<import("discord.js").Guild | null>;
|
|
17
17
|
uptime(timestamp?: number | null): string;
|
|
18
|
-
commands(): (
|
|
18
|
+
commands(): (XernerxSlashCommand | XernerxContextCommand | XernerxMessageCommand)[];
|
|
19
19
|
}
|
package/dist/utils/ClientUtil.js
CHANGED
|
@@ -76,6 +76,6 @@ export default class ClientUtil extends Util {
|
|
|
76
76
|
return `${seconds}s`;
|
|
77
77
|
}
|
|
78
78
|
commands() {
|
|
79
|
-
return [...this.client.commands.context, ...this.client.commands.slash, ...this.client.commands.message];
|
|
79
|
+
return [...this.client.commands.context.toJSON(), ...this.client.commands.slash.toJSON(), ...this.client.commands.message.toJSON()];
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { EmbedBuilder, InteractionEditReplyOptions, InteractionReplyOptions, MessageCreateOptions, MessagePayload } from 'discord.js';
|
|
3
3
|
import XernerxClient from '../client/XernerxClient.js';
|
|
4
4
|
import { ContextCommandArguments, PaginatorOptions, SlashCommandArguments } from '../types/interfaces.js';
|
|
5
|
-
import { XernerxInteraction } from '../types/types.js';
|
|
5
|
+
import { PermissionNames, XernerxInteraction } from '../types/types.js';
|
|
6
6
|
import Util from './Util.js';
|
|
7
7
|
import { XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUser, XernerxUserContextInteraction } from '../types/extenders.js';
|
|
8
8
|
type MimicOptions = {
|
|
@@ -20,5 +20,6 @@ export default class InteractionUtil extends Util {
|
|
|
20
20
|
mimic(user: XernerxUser | string, interaction: MessageCreateOptions, options: MimicOptions): Promise<void>;
|
|
21
21
|
paginator(embeds: Array<EmbedBuilder>, options?: PaginatorOptions): Promise<void | import("discord.js").Message<false> | import("discord.js").Message<true>>;
|
|
22
22
|
commands(): import("@discordjs/collection").Collection<string, import("../main.js").XernerxSlashCommand> | import("@discordjs/collection").Collection<string, import("../main.js").XernerxContextCommand>;
|
|
23
|
+
permissionCheck(type: 'user' | 'client', permissions: Array<PermissionNames>): boolean;
|
|
23
24
|
}
|
|
24
25
|
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, InteractionType, StringSelectMenuBuilder, } from 'discord.js';
|
|
3
3
|
import Util from './Util.js';
|
|
4
4
|
import XernerxError from '../tools/XernerxError.js';
|
|
5
|
+
import { Style } from 'dumfunctions';
|
|
5
6
|
export default class InteractionUtil extends Util {
|
|
6
7
|
constructor(client, interaction) {
|
|
7
8
|
super(client);
|
|
@@ -124,4 +125,29 @@ export default class InteractionUtil extends Util {
|
|
|
124
125
|
else
|
|
125
126
|
return this.client.commands.context;
|
|
126
127
|
}
|
|
128
|
+
permissionCheck(type, permissions) {
|
|
129
|
+
console.log(type);
|
|
130
|
+
const missing = [];
|
|
131
|
+
for (const permission of permissions) {
|
|
132
|
+
if (type == 'user') {
|
|
133
|
+
this.interaction.memberPermissions?.has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
|
|
134
|
+
}
|
|
135
|
+
if (type == 'client') {
|
|
136
|
+
this.interaction.guild?.members.me?.permissionsIn(this.interaction.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const command = this.commands().toJSON().find((cmd) => cmd.name == this.parsed.alias?.split(/ +/)[0]);
|
|
140
|
+
console.log(type);
|
|
141
|
+
if (missing.length) {
|
|
142
|
+
this.client.emit(`commandBlock`, this.interaction, {
|
|
143
|
+
reason: `missing${Style.pascalCase(type)}Permissions`,
|
|
144
|
+
message: `${type == 'user' ? 'You are' : 'I am'} missing the following permissions to run \`${command?.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
|
|
145
|
+
required: permissions,
|
|
146
|
+
missing,
|
|
147
|
+
}, command || null);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
else
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
127
153
|
}
|
|
@@ -4,6 +4,7 @@ import XernerxClient from '../client/XernerxClient.js';
|
|
|
4
4
|
import { XernerxMessage, XernerxUser } from '../types/extenders.js';
|
|
5
5
|
import Util from './Util.js';
|
|
6
6
|
import { PaginatorOptions } from '../types/interfaces.js';
|
|
7
|
+
import { PermissionNames } from '../main.js';
|
|
7
8
|
type MimicOptions = {
|
|
8
9
|
timeout: number;
|
|
9
10
|
};
|
|
@@ -20,5 +21,6 @@ export default class MessageUtil extends Util {
|
|
|
20
21
|
mimic(user: XernerxUser | string, message: MessageCreateOptions, options: MimicOptions): Promise<void>;
|
|
21
22
|
paginator(embeds: Array<EmbedBuilder>, options?: PaginatorOptions): Promise<void | import("discord.js").Message<boolean> | null>;
|
|
22
23
|
commands(): import("@discordjs/collection").Collection<string, import("../main.js").XernerxMessageCommand>;
|
|
24
|
+
permissionCheck(type: 'user' | 'client', permissions: Array<PermissionNames>): boolean;
|
|
23
25
|
}
|
|
24
26
|
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, } from 'discord.js';
|
|
3
3
|
import Util from './Util.js';
|
|
4
4
|
import XernerxError from '../tools/XernerxError.js';
|
|
5
|
+
import { Style } from 'dumfunctions';
|
|
5
6
|
export default class MessageUtil extends Util {
|
|
6
7
|
constructor(client, message) {
|
|
7
8
|
super(client);
|
|
@@ -138,4 +139,29 @@ export default class MessageUtil extends Util {
|
|
|
138
139
|
commands() {
|
|
139
140
|
return this.client.commands.message;
|
|
140
141
|
}
|
|
142
|
+
permissionCheck(type, permissions) {
|
|
143
|
+
console.log(type);
|
|
144
|
+
const missing = [];
|
|
145
|
+
for (const permission of permissions) {
|
|
146
|
+
if (type == 'user') {
|
|
147
|
+
this.message.member?.permissionsIn(this.message.channel.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
|
|
148
|
+
}
|
|
149
|
+
if (type == 'client') {
|
|
150
|
+
this.message.guild?.members.me?.permissionsIn(this.message.channel.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const command = this.commands().find((cmd) => cmd.name == this.parsed.alias || cmd.aliases?.includes(this.parsed.alias));
|
|
154
|
+
console.log(type);
|
|
155
|
+
if (missing.length) {
|
|
156
|
+
this.client.emit(`commandBlock`, this.message, {
|
|
157
|
+
reason: `missing${Style.pascalCase(type)}Permissions`,
|
|
158
|
+
message: `${type == 'user' ? 'You are' : 'I am'} missing the following permissions to run \`${command?.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
|
|
159
|
+
required: permissions,
|
|
160
|
+
missing,
|
|
161
|
+
}, command || null);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
else
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
141
167
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @format */
|
|
2
|
-
import { ChannelType
|
|
2
|
+
import { ChannelType } from 'discord.js';
|
|
3
|
+
import { Style } from 'dumfunctions';
|
|
3
4
|
var CommandTypes;
|
|
4
5
|
(function (CommandTypes) {
|
|
5
6
|
CommandTypes["SlashCommand"] = "slash";
|
|
@@ -88,10 +89,10 @@ export default async function commandValidation(event, command) {
|
|
|
88
89
|
reason: 'DMRestricted',
|
|
89
90
|
message: `\`${command.name}\` can't be used in a DM Channel`,
|
|
90
91
|
}, command);
|
|
91
|
-
if (userPermissions) {
|
|
92
|
-
const missing =
|
|
93
|
-
|
|
94
|
-
if (
|
|
92
|
+
if (userPermissions.length) {
|
|
93
|
+
const missing = [];
|
|
94
|
+
userPermissions.map((permission) => event.guild?.members.me?.permissionsIn(event.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission));
|
|
95
|
+
if (missing.length)
|
|
95
96
|
return await emit(event, {
|
|
96
97
|
reason: 'missingUserPermissions',
|
|
97
98
|
message: `You are missing the following permissions to run \`${command.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
|
|
@@ -99,10 +100,10 @@ export default async function commandValidation(event, command) {
|
|
|
99
100
|
missing,
|
|
100
101
|
}, command);
|
|
101
102
|
}
|
|
102
|
-
if (clientPermissions) {
|
|
103
|
-
const missing =
|
|
104
|
-
|
|
105
|
-
if (
|
|
103
|
+
if (clientPermissions.length) {
|
|
104
|
+
const missing = [];
|
|
105
|
+
clientPermissions.map((permission) => event.guild?.members.me?.permissionsIn(event.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission));
|
|
106
|
+
if (missing.length)
|
|
106
107
|
return await emit(event, {
|
|
107
108
|
reason: 'missingClientPermissions',
|
|
108
109
|
message: `I am missing the following permissions to run \`${command.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
|
|
@@ -121,16 +122,3 @@ async function emit(event, info, command) {
|
|
|
121
122
|
event.client.emit('commandBlock', event, info, command);
|
|
122
123
|
return true;
|
|
123
124
|
}
|
|
124
|
-
function toBigInt(permissions) {
|
|
125
|
-
let bigIntPermissions = 0n;
|
|
126
|
-
permissions.map((permission) => {
|
|
127
|
-
permission =
|
|
128
|
-
PermissionFlagsBits[permission
|
|
129
|
-
.split(/ +/)
|
|
130
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
131
|
-
.join('')];
|
|
132
|
-
if (typeof permission === 'bigint')
|
|
133
|
-
bigIntPermissions += permission;
|
|
134
|
-
});
|
|
135
|
-
return bigIntPermissions;
|
|
136
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xernerx",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.1",
|
|
4
4
|
"description": "A bot framework for discord.js.",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"site": "git add docs && npm run commit && git push",
|
|
31
31
|
"write": "npm i && npm run build && npm run format",
|
|
32
32
|
"format": "npx prettier --write src dist",
|
|
33
|
-
"build": "
|
|
33
|
+
"build": "npm run build:esm && npm run format",
|
|
34
|
+
"build:esm": "tsc",
|
|
35
|
+
"build:cjs": "tsc --module CommonJS --outDir dist/cjs"
|
|
34
36
|
},
|
|
35
37
|
"repository": {
|
|
36
38
|
"type": "git",
|
|
@@ -42,7 +44,7 @@
|
|
|
42
44
|
"dependencies": {
|
|
43
45
|
"dbl-sdk": "^2.0.3",
|
|
44
46
|
"discord.js": "^14.14.1",
|
|
45
|
-
"dumfunctions": "2.1.
|
|
47
|
+
"dumfunctions": "^2.1.6",
|
|
46
48
|
"xernerx-extension-builder": "0.0.16",
|
|
47
49
|
"zod": "^3.22.4"
|
|
48
50
|
},
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
export default async function sendWebhook(url, body) {
|
|
3
|
-
const response = await fetch(url, {
|
|
4
|
-
method: 'POST',
|
|
5
|
-
headers: {
|
|
6
|
-
'Content-Type': 'application/json',
|
|
7
|
-
},
|
|
8
|
-
body: JSON.stringify(body),
|
|
9
|
-
});
|
|
10
|
-
if (response.status === 204)
|
|
11
|
-
return true;
|
|
12
|
-
const data = await response.json();
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
-
import Handler from './Handler.js';
|
|
4
|
-
export default class IntegrationHandler extends Handler {
|
|
5
|
-
readonly readyTimestamp: number;
|
|
6
|
-
constructor(client: XernerxClient);
|
|
7
|
-
loadIntegrations(options: any): Promise<void>;
|
|
8
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** @format */
|
|
2
|
-
// import XernerxLog from '../tools/XernerxLog.js';
|
|
3
|
-
import Handler from './Handler.js';
|
|
4
|
-
export default class IntegrationHandler extends Handler {
|
|
5
|
-
constructor(client) {
|
|
6
|
-
super(client);
|
|
7
|
-
this.readyTimestamp = Number(Date.now());
|
|
8
|
-
}
|
|
9
|
-
async loadIntegrations(options) { }
|
|
10
|
-
}
|