xernerx 4.10.0 → 4.12.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.
@@ -46,6 +46,7 @@ export default class XernerxClient extends Client {
46
46
  readonly stats: Record<string, number>;
47
47
  readonly cache: XernerxCache;
48
48
  readonly cooldowns: Cooldowns;
49
+ readonly dbl: any;
49
50
  constructor(discordOptions: ClientOptions, xernerxOptions: XernerxOptions, config?: unknown);
50
51
  connect(token: string): Promise<string>;
51
52
  }
@@ -4,7 +4,7 @@ import { z } from 'zod';
4
4
  import CommandHandler from '../handlers/CommandHandler.js';
5
5
  import EventHandler from '../handlers/EventHandler.js';
6
6
  import InhibitorHandler from '../handlers/InhibitorHandler.js';
7
- import WebhookHandler from '../handlers/WebhookHandler.js';
7
+ import IntegrationHandler from '../handlers/IntegrationHandler.js';
8
8
  import XernerxLog from '../tools/XernerxLog.js';
9
9
  import ClientUtil from '../utils/ClientUtil.js';
10
10
  import ExtensionHandler from '../handlers/ExtensionHandler.js';
@@ -64,26 +64,28 @@ export default class XernerxClient extends Client {
64
64
  };
65
65
  this.events = new Collection();
66
66
  this.inhibitors = new Collection();
67
- this.modules = {
68
- options: {},
69
- commandHandler: new CommandHandler(this),
70
- eventHandler: new EventHandler(this),
71
- inhibitorHandler: new InhibitorHandler(this),
72
- webhookHandler: new WebhookHandler(this),
73
- extensionHandler: new ExtensionHandler(this),
74
- };
75
67
  this.util = new ClientUtil(this);
76
68
  this.stats = {
77
69
  guildCount: this.guilds.cache.size,
78
70
  userCount: 0,
79
71
  shardId: 0,
80
- shardCount: 1,
72
+ shardCount: this.options.shardCount || 1,
73
+ voteCount: 0,
81
74
  };
75
+ this.dbl = {};
82
76
  this.cache = {
83
77
  messages: new Collection(),
84
78
  cooldowns: new Collection(),
85
79
  };
86
80
  this.cooldowns = new Cooldowns(this, xernerxOptions.cooldown?.collections);
81
+ this.modules = {
82
+ options: {},
83
+ commandHandler: new CommandHandler(this),
84
+ eventHandler: new EventHandler(this),
85
+ inhibitorHandler: new InhibitorHandler(this),
86
+ integrationHandler: new IntegrationHandler(this),
87
+ extensionHandler: new ExtensionHandler(this),
88
+ };
87
89
  return this;
88
90
  }
89
91
  async connect(token) {
@@ -11,6 +11,8 @@ export default class XernerxShardClient extends ShardingManager {
11
11
  guildCount: number;
12
12
  userCount: number;
13
13
  shardCount: number;
14
+ voteCount: number;
15
+ shards: {};
14
16
  };
15
17
  user: ClientUser | null;
16
18
  spawner: Promise<import("@discordjs/collection").Collection<number, import("discord.js").Shard>>;
@@ -5,18 +5,19 @@ import { Style } from 'dumfunctions';
5
5
  export default class XernerxShardClient extends ShardingManager {
6
6
  constructor(file, discordOptions, xernerxOptions) {
7
7
  super(file, discordOptions);
8
- this.stats = { guildCount: 0, userCount: 0, shardCount: 0 };
8
+ this.stats = { guildCount: 0, userCount: 0, shardCount: 0, voteCount: 0, shards: {} };
9
9
  this.user = null;
10
10
  this.on('shardCreate', async (shard) => {
11
11
  shard
12
12
  .on('ready', async () => {
13
- const guilds = (await shard.fetchClientValue('guilds.cache'));
14
- const guildCount = guilds.length;
15
- const userCount = guilds.map((guild) => guild.memberCount).length ? guilds.map((guild) => guild.memberCount).reduce((a, b) => (a += b)) : 0;
13
+ await new Promise((resolve) => setTimeout(resolve, 250));
14
+ const stats = (await shard.fetchClientValue('stats'));
15
+ this.stats.shards[String(shard.id)] = stats;
16
16
  this.user = (await shard.fetchClientValue('user'));
17
- this.stats.guildCount += Number(guildCount);
18
- this.stats.userCount += Number(userCount);
17
+ this.stats.guildCount += stats.guildCount;
18
+ this.stats.userCount += stats.userCount;
19
19
  this.stats.shardCount++;
20
+ this.stats.voteCount = stats.voteCount;
20
21
  await new XernerxLog({ settings: xernerxOptions }).info(`Launched shard ${Style.log(String(shard.id), { color: Style.TextColor.Cyan })} for ${Style.log(this.user?.tag, { color: Style.TextColor.Blue })}! ${xernerxOptions?.timeout ? `Automatically killing in ${Style.log(String(xernerxOptions.timeout), { color: Style.TextColor.Cyan })}ms.` : ''}`);
21
22
  })
22
23
  .on('error', (error) => {
@@ -7,7 +7,14 @@ const globalCommands = [];
7
7
  const localCommands = [];
8
8
  export default function deploy(client) {
9
9
  const commands = [];
10
+ function stats() {
11
+ client.stats.guildCount = client.guilds.cache.size;
12
+ client.stats.userCount = client.guilds.cache.map((g) => g.memberCount || g.approximateMemberCount || 0).reduce((a, b) => (a += b));
13
+ }
14
+ client.on('messageCreate', stats);
15
+ client.on('interactionCreate', stats);
10
16
  client.prependOnceListener('ready', (client) => {
17
+ stats();
11
18
  client.commands.slash.map((command) => commands.push(command));
12
19
  client.commands.context.map((command) => commands.push(command));
13
20
  client.commands.slash.map((command) => commands.push(command));
@@ -44,7 +51,7 @@ function put(client, global, body) {
44
51
  if (!global && !client.settings?.local)
45
52
  throw new XernerxError(`No guild ID provided as local guild!`);
46
53
  if (!global && client.settings?.local)
47
- rest.put(Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
54
+ return rest.put(Routes.applicationGuildCommands(client.user?.id, client.settings.local), { body });
48
55
  else
49
- rest.put(Routes.applicationCommands(client.user?.id), { body });
56
+ return rest.put(Routes.applicationCommands(client.user?.id), { body });
50
57
  }
@@ -1,10 +1,12 @@
1
1
  /** @format */
2
+ import { ActivityType } from 'discord.js';
3
+ import { Style } from 'dumfunctions';
2
4
  export default function setPresence(client, options) {
3
5
  const presence = () => client.user?.setPresence({
4
6
  activities: [
5
7
  {
6
8
  name: options.text,
7
- type: options.type,
9
+ type: ActivityType[Style.titleCase(options.type || 'Custom')],
8
10
  url: options.url,
9
11
  },
10
12
  ],
@@ -2,7 +2,8 @@
2
2
  export async function xernerxUser(event, client) {
3
3
  const author = event.author || event.user;
4
4
  author.owner = isOwner(client, author);
5
- author.voted = client.util.hasVoted ? await client.util.hasVoted(author.id) : null;
5
+ if (client.dbl.validate)
6
+ author.voted = await client?.dbl?.validate(author);
6
7
  return author;
7
8
  }
8
9
  function isOwner(client, user) {
@@ -0,0 +1,15 @@
1
+ /** @format */
2
+ import XernerxClient from '../client/XernerxClient.js';
3
+ import Handler from './Handler.js';
4
+ import dbl from 'dbl-sdk';
5
+ export default class IntegrationHandler extends Handler {
6
+ readonly readyTimestamp: number;
7
+ readonly dbl: dbl;
8
+ constructor(client: XernerxClient);
9
+ loadIntegrations(options?: DBLOptions): Promise<void>;
10
+ }
11
+ interface DBLOptions {
12
+ post?: boolean;
13
+ votes?: boolean;
14
+ }
15
+ export {};
@@ -0,0 +1,25 @@
1
+ /** @format */
2
+ // import XernerxLog from '../tools/XernerxLog.js';
3
+ import Handler from './Handler.js';
4
+ import dbl from 'dbl-sdk';
5
+ export default class IntegrationHandler extends Handler {
6
+ constructor(client) {
7
+ super(client);
8
+ this.dbl = new dbl(client, client.config);
9
+ this.readyTimestamp = Number(Date.now());
10
+ }
11
+ async loadIntegrations(options = { votes: true }) {
12
+ this.client.once('ready', async (client) => {
13
+ this.client.dbl.validate = (user) => this.dbl.validate(user);
14
+ if (options.post) {
15
+ this.dbl.post();
16
+ }
17
+ if (options.votes) {
18
+ this.dbl.votes();
19
+ this.client.on('dbl-sync', (client, responses) => {
20
+ this.client.stats.voteCount = responses.voteCount;
21
+ });
22
+ }
23
+ });
24
+ }
25
+ }
@@ -1,11 +1,8 @@
1
1
  /** @format */
2
2
  import XernerxClient from '../client/XernerxClient.js';
3
3
  import Handler from './Handler.js';
4
- export default class WebhookHandler extends Handler {
4
+ export default class IntegrationHandler extends Handler {
5
5
  readonly readyTimestamp: number;
6
6
  constructor(client: XernerxClient);
7
- loadWebhooks(options: {
8
- token: string;
9
- }): Promise<void>;
10
- private post;
7
+ loadIntegrations(options: any): Promise<void>;
11
8
  }
@@ -1,49 +1,10 @@
1
1
  /** @format */
2
- import XernerxLog from '../tools/XernerxLog.js';
2
+ // import XernerxLog from '../tools/XernerxLog.js';
3
3
  import Handler from './Handler.js';
4
- export default class WebhookHandler extends Handler {
4
+ export default class IntegrationHandler extends Handler {
5
5
  constructor(client) {
6
6
  super(client);
7
7
  this.readyTimestamp = Number(Date.now());
8
8
  }
9
- async loadWebhooks(options) {
10
- this.client.once('ready', async (client) => {
11
- this.post(options.token);
12
- setInterval(() => {
13
- this.post(client.token);
14
- }, 60000 * 30);
15
- this.client.util.hasVoted = async (userId) => {
16
- return !!(await (await fetch(`https://top.gg/api/bots/${this.client.user?.id}/check?userId=${userId}`, {
17
- headers: { 'Authorization': options.token, 'Content-Type': 'application/json' },
18
- })).json()).voted;
19
- };
20
- });
21
- }
22
- async post(token) {
23
- const guilds = await this.client.guilds.fetch();
24
- this.client.stats.guildCount = this.client.guilds.cache.size;
25
- this.client.stats.userCount = (await Promise.all(guilds.map(async (guild) => (await this.client.guilds.fetch(guild.id)).memberCount))).reduce((a, b) => (a += b));
26
- this.client.stats.shardId = this.client.options.shards?.at(0) || 0;
27
- this.client.stats.shardCount = this.client.options.shardCount || this.client.options.shards?.length || 1;
28
- try {
29
- new XernerxLog(this.client).info(`Posted Stats to Top.gg!`);
30
- this.client.emit('webhookCreate', this.client, this.client.stats);
31
- return await fetch(`https://top.gg/api/bots/stats`, {
32
- method: 'POST',
33
- headers: {
34
- 'Authorization': token,
35
- 'Content-Type': 'application/json',
36
- },
37
- body: JSON.stringify({
38
- server_count: this.client.stats.guildCount,
39
- shard_id: this.client.stats.shardId,
40
- shard_count: this.client.stats.shardCount,
41
- }),
42
- });
43
- }
44
- catch (error) {
45
- new XernerxLog(this.client).error(`An error occurred while posting stats to Top.gg`, error);
46
- return this.client.emit('webhookError', this.client, this.client.stats);
47
- }
48
- }
9
+ async loadIntegrations(options) { }
49
10
  }
@@ -3,7 +3,7 @@ import { ActivityType, ChannelType, Collection, PresenceStatusData } from 'disco
3
3
  import CommandHandler from '../handlers/CommandHandler.js';
4
4
  import EventHandler from '../handlers/EventHandler.js';
5
5
  import InhibitorHandler from '../handlers/InhibitorHandler.js';
6
- import WebhookHandler from '../handlers/WebhookHandler.js';
6
+ import IntegrationHandler from '../handlers/IntegrationHandler.js';
7
7
  import XernerxContextCommand from '../build/XernerxContextCommand.js';
8
8
  import MessageCommandBuilder from '../build/XernerxMessageCommand.js';
9
9
  import XernerxSlashCommand from '../build/XernerxSlashCommand.js';
@@ -53,7 +53,7 @@ export interface ModuleOptions {
53
53
  commandHandler: CommandHandler;
54
54
  eventHandler: EventHandler;
55
55
  inhibitorHandler: InhibitorHandler;
56
- webhookHandler: WebhookHandler;
56
+ integrationHandler: IntegrationHandler;
57
57
  extensionHandler: ExtensionHandler;
58
58
  }
59
59
  export interface XernerxCommands {
@@ -233,7 +233,7 @@ export interface XernerxInhibitorOptions {
233
233
  }
234
234
  export interface PresenceOptions {
235
235
  text: string;
236
- type?: ActivityType.Playing | ActivityType.Streaming | ActivityType.Listening | ActivityType.Watching | ActivityType.Competing;
236
+ type?: keyof typeof ActivityType;
237
237
  url: string;
238
238
  status?: PresenceStatusData;
239
239
  interval?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xernerx",
3
- "version": "4.10.0",
3
+ "version": "4.12.0",
4
4
  "description": "A bot framework for discord.js.",
5
5
  "main": "dist/main.js",
6
6
  "type": "module",
@@ -40,11 +40,11 @@
40
40
  "url": "https://github.com/xernerx/xernerx/issues"
41
41
  },
42
42
  "dependencies": {
43
- "dbl-sdk": "1.2.0",
43
+ "dbl-sdk": "^2.0.2",
44
44
  "discord.js": "^14.14.1",
45
45
  "dumfunctions": "2.1.2",
46
46
  "xernerx-extension-builder": "0.0.16",
47
- "zod": "3.22.2"
47
+ "zod": "^3.22.4"
48
48
  },
49
49
  "devDependencies": {
50
50
  "prettier": "3.0.0",