xernerx 3.0.2 → 3.1.0
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 +2 -2
- package/dist/client/XernerxClient.js +3 -1
- package/dist/handlers/EventHandler.js +1 -1
- package/dist/handlers/WebhookHandler.d.ts +12 -0
- package/dist/handlers/WebhookHandler.js +40 -0
- package/dist/interfaces/ClientInterfaces.d.ts +7 -0
- package/dist/models/top.gg.d.ts +1 -0
- package/dist/models/top.gg.js +1 -0
- package/dist/models/webhooks.d.ts +6 -0
- package/dist/models/webhooks.js +5 -0
- package/dist/tools/values.d.ts +1 -0
- package/dist/tools/values.js +1 -0
- package/dist/types/Types.d.ts +3 -3
- package/dist/utils/CommandUtil.d.ts +13 -1
- package/dist/utils/CommandUtil.js +40 -10
- package/package.json +10 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client, Collection } from "discord.js";
|
|
2
2
|
import { ClientUtil } from "../utils/ClientUtil.js";
|
|
3
|
-
import { DiscordOptions, ClientOptions, Commands, Cache, Modules, HandlerOptions } from "../interfaces/ClientInterfaces.js";
|
|
3
|
+
import { DiscordOptions, ClientOptions, DBLOptions, Commands, Cache, Modules, HandlerOptions } from "../interfaces/ClientInterfaces.js";
|
|
4
4
|
/**
|
|
5
5
|
* @description - The Client.
|
|
6
6
|
* @param {DiscordOptions} discordOptions - The options for discord.js.
|
|
@@ -17,6 +17,6 @@ export default class XernerxClient extends Client {
|
|
|
17
17
|
events: Collection<string, object>;
|
|
18
18
|
inhibitors: Collection<string, object>;
|
|
19
19
|
config: object;
|
|
20
|
-
constructor(discordOptions: DiscordOptions, clientOptions: ClientOptions, config?: object);
|
|
20
|
+
constructor(discordOptions: DiscordOptions, clientOptions: ClientOptions, dblOptions?: DBLOptions, config?: object);
|
|
21
21
|
register(token: string): void;
|
|
22
22
|
}
|
|
@@ -5,6 +5,7 @@ import EventHandler from "../handlers/EventHandler.js";
|
|
|
5
5
|
import InhibitorHandler from "../handlers/InhibitorHandler.js";
|
|
6
6
|
import { ClientUtil } from "../utils/ClientUtil.js";
|
|
7
7
|
import { logStyle } from "../models/Functions.js";
|
|
8
|
+
import WebhookHandler from "../handlers/WebhookHandler.js";
|
|
8
9
|
/**
|
|
9
10
|
* @description - The Client.
|
|
10
11
|
* @param {DiscordOptions} discordOptions - The options for discord.js.
|
|
@@ -21,7 +22,7 @@ export default class XernerxClient extends Client {
|
|
|
21
22
|
events;
|
|
22
23
|
inhibitors;
|
|
23
24
|
config;
|
|
24
|
-
constructor(discordOptions, clientOptions, config) {
|
|
25
|
+
constructor(discordOptions, clientOptions, dblOptions, config) {
|
|
25
26
|
super(discordOptions);
|
|
26
27
|
this.settings = s
|
|
27
28
|
.object({
|
|
@@ -56,6 +57,7 @@ export default class XernerxClient extends Client {
|
|
|
56
57
|
commandHandler: new CommandHandler(this),
|
|
57
58
|
eventHandler: new EventHandler(this),
|
|
58
59
|
inhibitorHandler: new InhibitorHandler(this),
|
|
60
|
+
webhookHandler: new WebhookHandler(this),
|
|
59
61
|
};
|
|
60
62
|
this.util = new ClientUtil(this);
|
|
61
63
|
this.handlerOptions = {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { XernerxClient } from "../main.js";
|
|
2
|
+
interface WebhookOptions {
|
|
3
|
+
token: string;
|
|
4
|
+
logging: boolean;
|
|
5
|
+
}
|
|
6
|
+
export default class WebhookHandler {
|
|
7
|
+
client: XernerxClient;
|
|
8
|
+
constructor(client: XernerxClient);
|
|
9
|
+
post(options: WebhookOptions): import("topgg-autoposter/dist/structs/BasePoster.js").BasePoster;
|
|
10
|
+
vote(options: WebhookOptions): void;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { AutoPoster } from 'topgg-autoposter';
|
|
3
|
+
import SDK from '@top-gg/sdk';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
export default class WebhookHandler {
|
|
6
|
+
client;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.vote = this.vote;
|
|
10
|
+
this.post = this.post;
|
|
11
|
+
}
|
|
12
|
+
post(options) {
|
|
13
|
+
const auto = AutoPoster(options.token, this.client);
|
|
14
|
+
auto
|
|
15
|
+
.on('posted', post => {
|
|
16
|
+
if (options.logging)
|
|
17
|
+
console.info(`Xernerx | Successfully posted bot stats to Top.gg!`);
|
|
18
|
+
return this.client.emit('webhookPost', post);
|
|
19
|
+
})
|
|
20
|
+
.on('error', error => {
|
|
21
|
+
if (options.logging)
|
|
22
|
+
console.info(`Xernerx | An error occurred while posting stats to Top.gg, ${error}.`);
|
|
23
|
+
return this.client.emit('webhookError', error);
|
|
24
|
+
});
|
|
25
|
+
return auto;
|
|
26
|
+
}
|
|
27
|
+
vote(options) {
|
|
28
|
+
const app = express();
|
|
29
|
+
const webhook = new SDK.Webhook(options.token);
|
|
30
|
+
// app.post("/dblwebhook", webhook.listener(vote => {
|
|
31
|
+
// try {
|
|
32
|
+
// return this.client.emit("webhookVote", (vote as WebhookPayload))
|
|
33
|
+
// }
|
|
34
|
+
// catch (error) {
|
|
35
|
+
// return this.client.emit("webhookError", error)
|
|
36
|
+
// }
|
|
37
|
+
// }))
|
|
38
|
+
app.listen(4444);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -4,6 +4,7 @@ import EventHandler from "../handlers/EventHandler.js";
|
|
|
4
4
|
import InhibitorHandler from "../handlers/InhibitorHandler.js";
|
|
5
5
|
import { ContextCommandOptions, MessageCommandOptions, SlashCommandOptions, EventLoadOptions, InhibitorLoadOptions } from "./HandlerInterfaces.js";
|
|
6
6
|
import { MessageCommand } from "../build/MessageCommand.js";
|
|
7
|
+
import WebhookHandler from "../handlers/WebhookHandler.js";
|
|
7
8
|
export interface DiscordOptions {
|
|
8
9
|
shards?: number | number[] | "auto";
|
|
9
10
|
closeTimeout?: number;
|
|
@@ -31,6 +32,11 @@ export interface ClientOptions {
|
|
|
31
32
|
cache?: number;
|
|
32
33
|
};
|
|
33
34
|
}
|
|
35
|
+
export interface DBLOptions {
|
|
36
|
+
token?: string;
|
|
37
|
+
webhook?: string;
|
|
38
|
+
logging?: boolean;
|
|
39
|
+
}
|
|
34
40
|
export interface HandlerOptions {
|
|
35
41
|
message?: MessageCommandOptions;
|
|
36
42
|
slash?: SlashCommandOptions;
|
|
@@ -55,4 +61,5 @@ export interface Modules {
|
|
|
55
61
|
commandHandler: CommandHandler;
|
|
56
62
|
eventHandler: EventHandler;
|
|
57
63
|
inhibitorHandler: InhibitorHandler;
|
|
64
|
+
webhookHandler: WebhookHandler;
|
|
58
65
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/Types.d.ts
CHANGED
|
@@ -14,9 +14,9 @@ export declare enum EventEmitterType {
|
|
|
14
14
|
Rest = "rest",
|
|
15
15
|
Process = "process"
|
|
16
16
|
}
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
17
|
+
export type SlashCommandOptionChoices = SlashCommandStringOption | SlashCommandNumberOption | SlashCommandIntegerOption;
|
|
18
|
+
export type SlashCommandOption = SlashCommandOptionChoices | SlashCommandBooleanOption | SlashCommandUserOption | SlashCommandChannelOption | SlashCommandRoleOption | SlashCommandMentionableOption;
|
|
19
|
+
export type NiceTypes = "String" | "Number" | "Boolean" | "User" | "Channel" | "Role" | "Mentionable" | "Integer";
|
|
20
20
|
declare const _default: {
|
|
21
21
|
CommandType: typeof CommandType;
|
|
22
22
|
EventEmitterType: typeof EventEmitterType;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, Interaction, Message, MessagePayload } from "discord.js";
|
|
1
|
+
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, Interaction, Message, MessagePayload, StringSelectMenuBuilder } from "discord.js";
|
|
2
2
|
import XernerxClient from "../client/XernerxClient.js";
|
|
3
3
|
import { XernerxMessage } from "../interfaces/HandlerInterfaces.js";
|
|
4
|
+
interface SelectMenuOptions {
|
|
5
|
+
index?: EmbedBuilder;
|
|
6
|
+
row?: ActionRowBuilder;
|
|
7
|
+
component?: StringSelectMenuBuilder;
|
|
8
|
+
components?: object[];
|
|
9
|
+
reply?: boolean;
|
|
10
|
+
id?: string;
|
|
11
|
+
filter?: Function;
|
|
12
|
+
time?: number;
|
|
13
|
+
ephemeral?: boolean;
|
|
14
|
+
}
|
|
4
15
|
interface ButtonOptions {
|
|
5
16
|
index?: number;
|
|
6
17
|
buttons?: Array<string>;
|
|
@@ -32,6 +43,7 @@ export declare class InteractionCommandUtil {
|
|
|
32
43
|
reply(content: MessagePayload | string): any;
|
|
33
44
|
defer(time: number): Promise<unknown>;
|
|
34
45
|
getCommands(): import("@discordjs/collection").Collection<string, object>;
|
|
46
|
+
selectMenuPaginator(embeds: Array<EmbedBuilder>, options?: SelectMenuOptions): void;
|
|
35
47
|
buttonPaginator(embeds: Array<EmbedBuilder>, options: ButtonOptions): void;
|
|
36
48
|
isOwner(): boolean;
|
|
37
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder,
|
|
1
|
+
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, StringSelectMenuBuilder, } from "discord.js";
|
|
2
2
|
export class MessageCommandUtil {
|
|
3
3
|
client;
|
|
4
4
|
message;
|
|
@@ -111,7 +111,7 @@ export class InteractionCommandUtil {
|
|
|
111
111
|
return this.client.commands.context;
|
|
112
112
|
}
|
|
113
113
|
#getCommandName() { }
|
|
114
|
-
|
|
114
|
+
selectMenuPaginator(embeds, options) {
|
|
115
115
|
if (!Array.isArray(embeds))
|
|
116
116
|
throw new Error(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
|
|
117
117
|
if (embeds.length > 25)
|
|
@@ -136,23 +136,48 @@ export class InteractionCommandUtil {
|
|
|
136
136
|
options.row = new ActionRowBuilder();
|
|
137
137
|
if (!options.id)
|
|
138
138
|
options.id = `${this.interaction.id}-menu`;
|
|
139
|
-
options.component = new
|
|
139
|
+
options.component = new StringSelectMenuBuilder()
|
|
140
140
|
.setCustomId(options.id)
|
|
141
141
|
.setMaxValues(1)
|
|
142
142
|
.setMinValues(1)
|
|
143
143
|
.setPlaceholder("Select a page.")
|
|
144
|
-
.addOptions({ label: "index", value: "
|
|
145
|
-
embeds.map((embed, i = 0) => {
|
|
144
|
+
.addOptions({ label: "index", value: "0" });
|
|
145
|
+
embeds.map((embed, i = 0) => {
|
|
146
|
+
options?.component?.addOptions({
|
|
147
|
+
label: embed.data.title || "No Name",
|
|
148
|
+
description: embed.data.description || `Page ${i}`,
|
|
149
|
+
value: String(i + 1),
|
|
150
|
+
});
|
|
151
|
+
});
|
|
146
152
|
options.row.addComponents(options.component);
|
|
147
153
|
}
|
|
154
|
+
embeds.unshift(options.index);
|
|
148
155
|
const content = {
|
|
149
156
|
embeds: [options.index],
|
|
150
|
-
components: [options.
|
|
157
|
+
components: [options.row, ...options.components],
|
|
151
158
|
ephemeral: !!options.ephemeral,
|
|
152
159
|
};
|
|
153
|
-
options.reply === undefined || options.reply === true
|
|
160
|
+
(options.reply === undefined || options.reply === true
|
|
154
161
|
? this.interaction.util.reply(content)
|
|
155
|
-
: this.interaction.channel.send(content)
|
|
162
|
+
: this.interaction.channel.send(content)).then(() => {
|
|
163
|
+
const collector = this.interaction.channel
|
|
164
|
+
.createMessageComponentCollector({
|
|
165
|
+
filter: options?.filter,
|
|
166
|
+
time: options?.time || 60000,
|
|
167
|
+
})
|
|
168
|
+
.on("collect", (interaction) => {
|
|
169
|
+
if (!interaction.customId.startsWith(this.interaction.id))
|
|
170
|
+
return;
|
|
171
|
+
interaction.update({
|
|
172
|
+
embeds: [
|
|
173
|
+
embeds[parseInt(interaction.values[0])],
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
})
|
|
177
|
+
.on("end", () => {
|
|
178
|
+
this.interaction.editReply({ components: [] });
|
|
179
|
+
});
|
|
180
|
+
});
|
|
156
181
|
}
|
|
157
182
|
buttonPaginator(embeds, options) {
|
|
158
183
|
if (!Array.isArray(embeds))
|
|
@@ -221,8 +246,13 @@ export class InteractionCommandUtil {
|
|
|
221
246
|
}
|
|
222
247
|
}
|
|
223
248
|
stop
|
|
224
|
-
? interaction.update({
|
|
225
|
-
|
|
249
|
+
? interaction.update({
|
|
250
|
+
embeds: [embed],
|
|
251
|
+
components: [],
|
|
252
|
+
})
|
|
253
|
+
: interaction.update({
|
|
254
|
+
embeds: [embed],
|
|
255
|
+
});
|
|
226
256
|
}
|
|
227
257
|
})
|
|
228
258
|
.on("end", () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "xernerx",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"description": "A bot framework for discord.js. [BETA]",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"scripts": {
|
|
@@ -18,8 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/TheDummi/xernerx#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@sapphire/shapeshift": "^3.7.
|
|
22
|
-
"
|
|
21
|
+
"@sapphire/shapeshift": "^3.7.1",
|
|
22
|
+
"@top-gg/sdk": "^3.1.3",
|
|
23
|
+
"discord.js": "^14.7.0",
|
|
24
|
+
"express": "^4.18.2",
|
|
25
|
+
"topgg-autoposter": "^2.0.1"
|
|
23
26
|
},
|
|
24
|
-
"packageManager": "npm@8.5.5"
|
|
27
|
+
"packageManager": "npm@8.5.5",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/express": "^4.17.15"
|
|
30
|
+
}
|
|
25
31
|
}
|