@somehiddenkey/discord-command-utils 2.1.2 → 2.2.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/README.md CHANGED
@@ -27,27 +27,14 @@ export const localConfig = LocalConfig.load("./configs/local_config.json");
27
27
  Your local configuration JSON file should look like this:
28
28
  ```json
29
29
  {
30
- "production": {
31
- "prefix": "!",
32
- "client_id": "123456789123456789",
33
- "local": {
34
- "any_local_configuration": "any values"
35
- },
36
- "rest_options" : {
37
- "version": "10",
38
- "rejectOnRateLimit": ["/channels"]
39
- }
30
+ "prefix": "!",
31
+ "client_id": "123456789123456789",
32
+ "local": {
33
+ "any_local_configuration": "any values"
40
34
  },
41
- "development": {
42
- "prefix": "!",
43
- "client_id": "123456789123456789",
44
- "local": {
45
- "any_local_configuration": "any values"
46
- },
47
- "rest_options" : {
48
- "version": "10",
49
- "rejectOnRateLimit": ["/channels"]
50
- }
35
+ "rest_options" : {
36
+ "version": "10",
37
+ "rejectOnRateLimit": ["/channels"]
51
38
  },
52
39
  "activity": {
53
40
  "name": "the communities",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@somehiddenkey/discord-command-utils",
3
- "version": "2.1.2",
3
+ "version": "2.2.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",
@@ -3,7 +3,6 @@
3
3
  */
4
4
 
5
5
  import fs from 'fs';
6
- import consola from 'consola';
7
6
  import { InteractionScope } from "../../Utils/enums.js";
8
7
  import GuildMain from './GlobalConfigMain.js';
9
8
  import GuildCommunity from './GlobalConfigCommunity.js';
@@ -33,11 +32,10 @@ export default class GlobalConfig {
33
32
  try {
34
33
  const raw = fs.readFileSync(path, { encoding: 'utf8', flag: 'r' });
35
34
  json = JSON.parse(raw);
35
+ return new GlobalConfig(json.guilds, bot);
36
36
  } catch (error) {
37
- consola.error(`Failed to load GlobalConfig from path: ${path}`, error);
38
- throw error;
37
+ throw new ConfigError(`Failed to load GlobalConfig from path: ${path}`, error);
39
38
  }
40
- return new GlobalConfig(json.guilds, bot);
41
39
  }
42
40
 
43
41
  /**
@@ -79,10 +77,14 @@ export default class GlobalConfig {
79
77
  }
80
78
 
81
79
  constructor(data, bot) {
82
- this.main = new GuildMain(data.main, bot);
83
- this.community = new GuildCommunity(data.community, bot);
84
- this.tutor = new GuildTutor(data.tutor, bot);
85
- this.staff = new GuildStaff(data.staff, bot);
80
+ const { main, community, tutor, staff } = data;
81
+ if (!main || !community || !tutor || !staff)
82
+ throw new ConfigError('All guild sections (main, community, tutor, staff) are required to initialize GlobalConfig');
83
+
84
+ this.main = new GuildMain(main, bot);
85
+ this.community = new GuildCommunity(community, bot);
86
+ this.tutor = new GuildTutor(tutor, bot);
87
+ this.staff = new GuildStaff(staff, bot);
86
88
  }
87
89
  }
88
90
 
@@ -22,16 +22,16 @@ export default class GuildCommunity extends GuildBased {
22
22
  throw new ConfigError('No data initialized for GlobalConfig');
23
23
 
24
24
  super(data);
25
- this.categories = new CategoriesCommunity(data.categories, data.id);
26
- this.channels = new ChannelsCommunity(data.channels, data.id);
27
- this.logs = new LogsCommunity(data.logs, data.id);
28
- this.roles = new RolesCommunity(data.roles, data.id);
25
+ this.categories = new CategoriesCommunity(data.categories, this.guild);
26
+ this.channels = new ChannelsCommunity(data.channels, this.guild);
27
+ this.logs = new LogsCommunity(data.logs, this.guild);
28
+ this.roles = new RolesCommunity(data.roles, this.guild);
29
29
  }
30
30
  }
31
31
 
32
32
  class CategoriesCommunity extends ChannelBased {}
33
33
 
34
- class Channels extends ChannelBased {}
34
+ class ChannelsCommunity extends ChannelBased {}
35
35
 
36
36
  class LogsCommunity extends ChannelBased {}
37
37
 
@@ -22,10 +22,10 @@ export default class GuildStaff extends GuildBased {
22
22
  throw new ConfigError('No data initialized for GlobalConfig');
23
23
 
24
24
  super(data, bot);
25
- this.categories = new CategoriesStaff(data.categories, data.id);
26
- this.channels = new ChannelsStaff(data.channels, data.id);
27
- this.logs = new LogsStaff(data.logs, data.id);
28
- this.roles = new RolesStaff(data.roles, data.id);
25
+ this.categories = new CategoriesStaff(data.categories, this.guild);
26
+ this.channels = new ChannelsStaff(data.channels, this.guild);
27
+ this.logs = new LogsStaff(data.logs, this.guild);
28
+ this.roles = new RolesStaff(data.roles, this.guild);
29
29
  }
30
30
  }
31
31
 
@@ -22,10 +22,10 @@ export default class GuildTutor extends GuildBased {
22
22
  throw new ConfigError('No data initialized for GlobalConfig');
23
23
 
24
24
  super(data, bot);
25
- this.categories = new CategoriesTutor(data.categories, data.id);
26
- this.channels = new ChannelsTutor(data.channels, data.id);
27
- this.logs = new LogsTutor(data.logs, data.id);
28
- this.roles = new RolesTutor(data.roles, data.id);
25
+ this.categories = new CategoriesTutor(data.categories, this.guild);
26
+ this.channels = new ChannelsTutor(data.channels, this.guild);
27
+ this.logs = new LogsTutor(data.logs, this.guild);
28
+ this.roles = new RolesTutor(data.roles, this.guild);
29
29
  }
30
30
  }
31
31
 
@@ -33,21 +33,16 @@ export default class LocalConfig {
33
33
  /**
34
34
  * Loads the JSON file and returns a GlobalConfig instance.
35
35
  * @param {string} path
36
- * @param {string} environment
37
36
  * @returns {LocalConfig}
38
37
  */
39
- static async load(path, environment) {
38
+ static async load(path) {
40
39
  var json
41
40
  try {
42
41
  const raw = fs.readFileSync(path, { encoding: 'utf8', flag: 'r' });
43
42
  json = JSON.parse(raw);
43
+ return new LocalConfig(json);
44
44
  } catch (error) {
45
- consola.error(`Failed to load LocalConfig from path: ${path}`, error);
46
- throw error;
45
+ throw new ConfigError(`Failed to load LocalConfig from path: ${path}`, error);
47
46
  }
48
- if (environment == "production")
49
- return new LocalConfig({...json.production || json.activity});
50
- else
51
- return new LocalConfig({...json.development || json.activity});
52
47
  }
53
48
  }