xernerx 4.13.1 → 4.14.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.
@@ -16,6 +16,6 @@ export default class XernerxShardClient extends ShardingManager {
16
16
  };
17
17
  user: ClientUser | null;
18
18
  spawner: Promise<import("@discordjs/collection").Collection<number, import("discord.js").Shard>>;
19
- constructor(file: string, discordOptions: ShardingManagerOptions, xernerxOptions?: XernerxOptions);
19
+ constructor(file: string, discordOptions: ShardingManagerOptions, xernerxOptions?: XernerxOptions, data?: unknown);
20
20
  }
21
21
  export {};
@@ -3,7 +3,7 @@ import { ShardingManager } from 'discord.js';
3
3
  import { Style } from 'dumfunctions';
4
4
  import XernerxLog from '../tools/XernerxLog.js';
5
5
  export default class XernerxShardClient extends ShardingManager {
6
- constructor(file, discordOptions, xernerxOptions) {
6
+ constructor(file, discordOptions, xernerxOptions, data = {}) {
7
7
  super(file, discordOptions);
8
8
  this.stats = { guildCount: 0, userCount: 0, shardCount: 0, voteCount: 0, shards: {} };
9
9
  this.user = null;
@@ -18,6 +18,8 @@ export default class XernerxShardClient extends ShardingManager {
18
18
  this.stats.userCount += stats.userCount;
19
19
  this.stats.shardCount++;
20
20
  this.stats.voteCount = stats.voteCount;
21
+ shard.send({ type: 'xernerx', data: { shardId: shard.id, sharded: true } });
22
+ shard.send({ type: 'client', data });
21
23
  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.` : ''}`);
22
24
  })
23
25
  .on('error', (error) => {
@@ -9,8 +9,14 @@ export default function deploy(client) {
9
9
  const commands = [];
10
10
  function stats() {
11
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));
12
+ client.stats.userCount = client.guilds.cache.map((g) => g.memberCount || g.approximateMemberCount || 0).reduce((a, b) => (a += b), 0);
13
13
  }
14
+ process.on('message', (message) => {
15
+ if (message.type == 'xernerx')
16
+ client.stats.shardId = message?.data?.shardId;
17
+ if (message.type == 'client')
18
+ client.data = message.data;
19
+ });
14
20
  client.on('messageCreate', stats);
15
21
  client.on('interactionCreate', stats);
16
22
  client.prependOnceListener('ready', (client) => {
@@ -10,10 +10,19 @@ export default class XernerxLog {
10
10
  private readonly readyLog;
11
11
  private readonly tableLog;
12
12
  private readonly time;
13
+ private readonly ram;
14
+ private shard;
15
+ private readonly base;
13
16
  constructor(client: XernerxClient | XernerxClientType | true);
14
17
  info(message: string, force?: boolean): void | null;
15
18
  warn(message: string): void | null;
16
19
  update(version: string, url: string): Promise<void>;
17
20
  error(message: string, error?: XernerxError | unknown): void | null;
18
21
  ready(): void;
22
+ private cyan;
23
+ private blue;
24
+ private yellow;
25
+ private purple;
26
+ private red;
27
+ private green;
19
28
  }
@@ -16,41 +16,38 @@ export default class XernerxLog {
16
16
  this.tableLog = client.settings.log?.table;
17
17
  }
18
18
  this.time = () => String(new Date()).split(/ +/)[4];
19
+ this.ram = () => Math.round(process.memoryUsage().rss / 1000000);
20
+ this.shard = '';
21
+ process.on('message', (message) => {
22
+ if (message.type == 'xernerx')
23
+ this.shard = message?.data?.sharded ? `| ${message?.data?.shardId} |` : '';
24
+ });
25
+ this.base = (type, message) => `${type == 'info' ? `✔️ | ${this.purple('Xernerx')}` : type == `error` ? `❗ | ${this.red('Xernerx')}` : type == `update` ? `⬆️ | ${this.blue('Xernerx')}` : `⚠️ | ${this.yellow('Xernerx')}`} | ${this.cyan(this.time())} | ${this.cyan(this.ram())}mb | ${this.client.stats?.shardCount > 1 ? `${this.cyan(this.client.stats.shardId)} | ` : ''}${message}`;
19
26
  }
20
27
  info(message, force = false) {
21
- return this.infoLog || force
22
- ? console.info(`✔️ | ${Style.log('Xernerx', { color: Style.TextColor.Purple })} | ${Style.log(this.time(), {
23
- color: Style.TextColor.Cyan,
24
- })} | ${Math.round(process.memoryUsage().rss / 1000000)}mb | ${message}`)
25
- : null;
28
+ return this.infoLog || force ? console.info(this.base('info', message)) : null;
26
29
  }
27
30
  warn(message) {
28
- return this.warnLog
29
- ? console.warn(`⚠️ | ${Style.log('Xernerx', { color: Style.TextColor.Yellow })} | ${Style.log(this.time(), { color: Style.TextColor.Cyan })} | ${Math.round(process.memoryUsage().rss / 1000000)}mb | ${message}`)
30
- : null;
31
+ return this.warnLog ? console.warn(this.base('warn', message)) : null;
31
32
  }
32
33
  async update(version, url) {
33
34
  const pkg = await fetch(url)
34
35
  .then(async (res) => await res.json())
35
36
  .catch(() => ({ version }));
36
37
  if (version !== pkg.version)
37
- new XernerxLog(true).warn(`A new version for ${pkg.name} is available, you're using version ${Style.log(version, { color: Style.TextColor.Cyan })}, new version is ${Style.log(pkg.version, {
38
- color: Style.TextColor.Cyan,
39
- })}, run ${Style.log(`npm i ${pkg.name}@${pkg.version}`, { color: Style.BackgroundColor.Grey })} to update to the latest version.`);
38
+ console.info(this.base('update', `A new version for ${pkg.name} is available, you're using version ${this.cyan(version)}, new version is ${this.cyan(pkg.version)}, run ${Style.log(`npm i ${pkg.name}@${pkg.version}`, {
39
+ color: Style.BackgroundColor.Grey,
40
+ })} to update to the latest version.`));
40
41
  }
41
42
  error(message, error) {
42
- return this.errorLog
43
- ? console.error(`❗ | ${Style.log('Xernerx', { color: Style.TextColor.Red })} | ${Style.log(this.time(), { color: Style.TextColor.Cyan })} | ${Math.round(process.memoryUsage().rss / 1000000)}mb | ${message}${error ? ` | ${error.stack}` : ''}`)
44
- : null;
43
+ return this.errorLog ? console.error(this.base('error', message), error) : null;
45
44
  }
46
45
  ready() {
47
46
  if (typeof this.client == 'boolean')
48
47
  return;
49
48
  const client = this.client;
50
49
  this.client.prependOnceListener('ready', async (synced) => {
51
- this.info(`${Style.log(synced.user.tag, { color: Style.TextColor.Blue })} is now ${Style.log('online', { color: Style.TextColor.Green })}, watching ${Style.log(String(client.guilds.cache.size), {
52
- color: Style.TextColor.Cyan,
53
- })} guild${client.guilds.cache.size > 1 ? 's' : ''}, using ${client.settings.local ? Style.log((await client.guilds.fetch(client.settings.local))?.name, { color: Style.TextColor.Blue }) : 'none'} as local guild.`, this.readyLog);
50
+ this.info(`${Style.log(synced.user.tag, { color: Style.TextColor.Blue })} is now ${this.green('online')}, watching ${this.cyan(String(client.guilds.cache.size))} guild${client.guilds.cache.size > 1 ? 's' : ''}, using ${client.settings.local ? this.blue((await client.guilds.fetch(client.settings.local))?.name) : 'none'} as local guild.`, this.readyLog);
54
51
  const files = [];
55
52
  for (const [id, data] of client.commands.message) {
56
53
  files.push(data);
@@ -77,4 +74,22 @@ export default class XernerxLog {
77
74
  }
78
75
  });
79
76
  }
77
+ cyan(string) {
78
+ return Style.log(String(string), { color: Style.TextColor.Cyan });
79
+ }
80
+ blue(string) {
81
+ return Style.log(String(string), { color: Style.TextColor.Blue });
82
+ }
83
+ yellow(string) {
84
+ return Style.log(String(string), { color: Style.TextColor.Yellow });
85
+ }
86
+ purple(string) {
87
+ return Style.log(String(string), { color: Style.TextColor.Purple });
88
+ }
89
+ red(string) {
90
+ return Style.log(String(string), { color: Style.TextColor.Red });
91
+ }
92
+ green(string) {
93
+ return Style.log(String(string), { color: Style.TextColor.Green });
94
+ }
80
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xernerx",
3
- "version": "4.13.1",
3
+ "version": "4.14.0",
4
4
  "description": "A bot framework for discord.js.",
5
5
  "main": "dist/main.js",
6
6
  "type": "module",