@somehiddenkey/discord-command-utils 1.2.2 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@somehiddenkey/discord-command-utils",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "A utility library for building Discord bot commands using discord.js",
5
5
  "author": {
6
6
  "email": "k3y.throwaway@gmail.com",
@@ -6,6 +6,9 @@ import fs from 'fs';
6
6
  import ConfigError from "./ConfigError.js";
7
7
  import consola from 'consola';
8
8
  import { InteractionScope } from "../Utils/enums.js";
9
+ import { Client, Guild } from 'discord.js';
10
+ import pkg from 'discord.js';
11
+ const { GuildBasedChannel } = pkg;
9
12
 
10
13
  export default class GlobalConfig {
11
14
  /** @type {Guilds} */
@@ -34,6 +37,16 @@ export default class GlobalConfig {
34
37
  this.roles = new Roles(data.roles);
35
38
  }
36
39
 
40
+ /**
41
+ * Pre-fetches guilds and log channels
42
+ * @param {Client} bot
43
+ * @returns {Promise<GlobalConfig>}
44
+ */
45
+ async init(bot) {
46
+ await this.guilds.init(bot);
47
+ return this;
48
+ }
49
+
37
50
  /**
38
51
  * Loads the JSON file and returns a GlobalConfig instance.
39
52
  * @param {string} path
@@ -71,9 +84,30 @@ class Guilds {
71
84
  /** @type {Snowflake} */
72
85
  staff;
73
86
 
87
+ /** @type {Guild} */
88
+ main_guild;
89
+ /** @type {Guild} */
90
+ community_guild;
91
+ /** @type {Guild} */
92
+ tutor_guild;
93
+ /** @type {Guild} */
94
+ staff_guild;
95
+
74
96
  constructor(data) {
75
97
  Object.assign(this, data);
76
98
  }
99
+
100
+ /**
101
+ * Pre-fetches guilds
102
+ * @param {Client} bot
103
+ * @returns {Promise<void>}
104
+ */
105
+ async init(bot) {
106
+ this.main_guild = await bot.guilds.fetch(this.main_guild);
107
+ this.community_guild = await bot.guilds.fetch(this.community_guild);
108
+ this.tutor_guild = await bot.guilds.fetch(this.tutor_guild);
109
+ this.staff_guild = await bot.guilds.fetch(this.staff_guild);
110
+ }
77
111
 
78
112
  /**
79
113
  * @param {Snowflake} guild_id
@@ -204,10 +238,43 @@ class Logs {
204
238
  command;
205
239
  /** @type {Snowflake} */
206
240
  communities;
241
+
242
+ /** @type {GuildBasedChannel} */
243
+ error_channel;
244
+ /** @type {GuildBasedChannel} */
245
+ votekick_channel;
246
+ /** @type {GuildBasedChannel} */
247
+ room_commands_channel;
248
+ /** @type {GuildBasedChannel} */
249
+ room_admin_channel;
250
+ /** @type {GuildBasedChannel} */
251
+ invites_channel;
252
+ /** @type {GuildBasedChannel} */
253
+ command_channel;
254
+ /** @type {GuildBasedChannel} */
255
+ communities_channel;
207
256
 
208
257
  constructor(data) {
209
258
  Object.assign(this, data);
210
259
  }
260
+
261
+ /**
262
+ * Pre-fetches log channels
263
+ * @param {Client} bot
264
+ * @returns {Promise<void>}
265
+ */
266
+ async init(bot) {
267
+ if(!this.main_guild)
268
+ return;
269
+
270
+ this.error_channel = await this.main_guild.channels.fetch(this.error_channel);
271
+ this.votekick_channel = await this.main_guild.channels.fetch(this.votekick_channel);
272
+ this.room_commands_channel = await this.main_guild.channels.fetch(this.room_commands_channel);
273
+ this.room_admin_channel = await this.main_guild.channels.fetch(this.room_admin_channel);
274
+ this.invites_channel = await this.main_guild.channels.fetch(this.invites_channel);
275
+ this.command_channel = await this.main_guild.channels.fetch(this.command_channel);
276
+ this.communities_channel = await this.main_guild.channels.fetch(this.communities_channel);
277
+ }
211
278
  }
212
279
 
213
280
  class Roles {