@somehiddenkey/discord-command-utils 2.1.1 → 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.1",
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,19 +3,22 @@
3
3
  */
4
4
 
5
5
  import fs from 'fs';
6
- import consola from 'consola';
7
6
  import { InteractionScope } from "../../Utils/enums.js";
8
- import {default as GuildMain} from './GlobalConfigMain.js';
9
- import {default as GuildCommunity} from './GlobalConfigCommunity.js';
10
- import {default as GuildTutor} from './GlobalConfigTutor.js';
11
- import {default as GuildStaff} from './GlobalConfigStaff.js';
7
+ import GuildMain from './GlobalConfigMain.js';
8
+ import GuildCommunity from './GlobalConfigCommunity.js';
9
+ import GuildTutor from './GlobalConfigTutor.js';
10
+ import GuildStaff from './GlobalConfigStaff.js';
12
11
  import { GuildBased } from '../NestedGlobalConfig.js';
13
12
  import { Client } from 'discord.js';
14
13
 
15
14
  export default class GlobalConfig {
15
+ /** @type {GuildMain} */
16
16
  main
17
+ /** @type {GuildCommunity} */
17
18
  community
19
+ /** @type {GuildTutor} */
18
20
  tutor
21
+ /** @type {GuildStaff} */
19
22
  staff
20
23
 
21
24
  /**
@@ -29,11 +32,10 @@ export default class GlobalConfig {
29
32
  try {
30
33
  const raw = fs.readFileSync(path, { encoding: 'utf8', flag: 'r' });
31
34
  json = JSON.parse(raw);
35
+ return new GlobalConfig(json.guilds, bot);
32
36
  } catch (error) {
33
- consola.error(`Failed to load GlobalConfig from path: ${path}`, error);
34
- throw error;
37
+ throw new ConfigError(`Failed to load GlobalConfig from path: ${path}`, error);
35
38
  }
36
- return new GlobalConfig(json.guilds, bot);
37
39
  }
38
40
 
39
41
  /**
@@ -75,10 +77,14 @@ export default class GlobalConfig {
75
77
  }
76
78
 
77
79
  constructor(data, bot) {
78
- this.main = new GuildMain(data.main, bot);
79
- this.community = new GuildCommunity(data.community, bot);
80
- this.tutor = new GuildTutor(data.tutor, bot);
81
- 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);
82
88
  }
83
89
  }
84
90
 
@@ -7,14 +7,14 @@ import pkg from 'discord.js';
7
7
  import { GuildBased, ChannelBased, RoleBased } from '../NestedGlobalConfig.js';
8
8
  const { GuildBasedChannel } = pkg;
9
9
 
10
- export default class Guild extends GuildBased {
11
- /** @type {Categories} */
10
+ export default class GuildCommunity extends GuildBased {
11
+ /** @type {CategoriesCommunity} */
12
12
  categories;
13
- /** @type {Channels} */
13
+ /** @type {ChannelsCommunity} */
14
14
  channels;
15
- /** @type {Logs} */
15
+ /** @type {LogsCommunity} */
16
16
  logs;
17
- /** @type {Roles} */
17
+ /** @type {RolesCommunity} */
18
18
  roles;
19
19
 
20
20
  constructor(data) {
@@ -22,17 +22,17 @@ export default class Guild extends GuildBased {
22
22
  throw new ConfigError('No data initialized for GlobalConfig');
23
23
 
24
24
  super(data);
25
- this.categories = new Categories(data.categories, data.id);
26
- this.channels = new Channels(data.channels, data.id);
27
- this.logs = new Logs(data.logs, data.id);
28
- this.roles = new Roles(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
- class Categories extends ChannelBased {}
32
+ class CategoriesCommunity extends ChannelBased {}
33
33
 
34
- class Channels extends ChannelBased {}
34
+ class ChannelsCommunity extends ChannelBased {}
35
35
 
36
- class Logs extends ChannelBased {}
36
+ class LogsCommunity extends ChannelBased {}
37
37
 
38
- class Roles extends RoleBased {}
38
+ class RolesCommunity extends RoleBased {}
@@ -7,14 +7,14 @@ import pkg from 'discord.js';
7
7
  import { GuildBased, ChannelBased, RoleBased } from '../NestedGlobalConfig.js';
8
8
  const { GuildBasedChannel } = pkg;
9
9
 
10
- export default class Guild extends GuildBased {
11
- /** @type {Categories} */
10
+ export default class GuildMain extends GuildBased {
11
+ /** @type {CategoriesMain} */
12
12
  categories;
13
- /** @type {Channels} */
13
+ /** @type {ChannelsMain} */
14
14
  channels;
15
- /** @type {Logs} */
15
+ /** @type {LogsMain} */
16
16
  logs;
17
- /** @type {Roles} */
17
+ /** @type {RolesMain} */
18
18
  roles;
19
19
 
20
20
  constructor(data, bot) {
@@ -22,14 +22,14 @@ export default class Guild extends GuildBased {
22
22
  throw new ConfigError('No data initialized for GlobalConfig');
23
23
 
24
24
  super(data, bot);
25
- this.categories = new Categories(data.categories, this.guild);
26
- this.channels = new Channels(data.channels, this.guild);
27
- this.logs = new Logs(data.logs, this.guild);
28
- this.roles = new Roles(data.roles, this.guild);
25
+ this.categories = new CategoriesMain(data.categories, this.guild);
26
+ this.channels = new ChannelsMain(data.channels, this.guild);
27
+ this.logs = new LogsMain(data.logs, this.guild);
28
+ this.roles = new RolesMain(data.roles, this.guild);
29
29
  }
30
30
  }
31
31
 
32
- class Categories extends ChannelBased {
32
+ class CategoriesMain extends ChannelBased {
33
33
  /** @type {Set<Snowflake>} */
34
34
  custom_rooms;
35
35
  /** @type {Set<Snowflake>} */
@@ -72,7 +72,7 @@ class Categories extends ChannelBased {
72
72
  }
73
73
  }
74
74
 
75
- class Channels extends ChannelBased {
75
+ class ChannelsMain extends ChannelBased {
76
76
  /** @type {GuildBasedChannel} */
77
77
  timer_control;
78
78
  /** @type {GuildBasedChannel} */
@@ -101,7 +101,7 @@ class Channels extends ChannelBased {
101
101
  welcome;
102
102
  }
103
103
 
104
- class Logs extends ChannelBased {
104
+ class LogsMain extends ChannelBased {
105
105
  /** @type {GuildBasedChannel} */
106
106
  error;
107
107
  /** @type {GuildBasedChannel} */
@@ -118,7 +118,7 @@ class Logs extends ChannelBased {
118
118
  communities;
119
119
  }
120
120
 
121
- class Roles extends RoleBased {
121
+ class RolesMain extends RoleBased {
122
122
  /** @type {Snowflake} */
123
123
  cuckoo_ping;
124
124
  /** @type {Snowflake} */
@@ -7,14 +7,14 @@ import pkg from 'discord.js';
7
7
  import { GuildBased, ChannelBased, RoleBased } from '../NestedGlobalConfig.js';
8
8
  const { GuildBasedChannel } = pkg;
9
9
 
10
- export default class Guild extends GuildBased {
11
- /** @type {Categories} */
10
+ export default class GuildStaff extends GuildBased {
11
+ /** @type {CategoriesStaff} */
12
12
  categories;
13
- /** @type {Channels} */
13
+ /** @type {ChannelsStaff} */
14
14
  channels;
15
- /** @type {Logs} */
15
+ /** @type {LogsStaff} */
16
16
  logs;
17
- /** @type {Roles} */
17
+ /** @type {RolesStaff} */
18
18
  roles;
19
19
 
20
20
  constructor(data, bot) {
@@ -22,17 +22,17 @@ export default class Guild extends GuildBased {
22
22
  throw new ConfigError('No data initialized for GlobalConfig');
23
23
 
24
24
  super(data, bot);
25
- this.categories = new Categories(data.categories, data.id);
26
- this.channels = new Channels(data.channels, data.id);
27
- this.logs = new Logs(data.logs, data.id);
28
- this.roles = new Roles(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
 
32
- class Categories extends ChannelBased {}
32
+ class CategoriesStaff extends ChannelBased {}
33
33
 
34
- class Channels extends ChannelBased {}
34
+ class ChannelsStaff extends ChannelBased {}
35
35
 
36
- class Logs extends ChannelBased {}
36
+ class LogsStaff extends ChannelBased {}
37
37
 
38
- class Roles extends RoleBased {}
38
+ class RolesStaff extends RoleBased {}
@@ -7,14 +7,14 @@ import pkg from 'discord.js';
7
7
  import { GuildBased, ChannelBased, RoleBased } from '../NestedGlobalConfig.js';
8
8
  const { GuildBasedChannel } = pkg;
9
9
 
10
- export default class Guild extends GuildBased {
11
- /** @type {Categories} */
10
+ export default class GuildTutor extends GuildBased {
11
+ /** @type {CategoriesTutor} */
12
12
  categories;
13
- /** @type {Channels} */
13
+ /** @type {ChannelsTutor} */
14
14
  channels;
15
- /** @type {Logs} */
15
+ /** @type {LogsTutor} */
16
16
  logs;
17
- /** @type {Roles} */
17
+ /** @type {RolesTutor} */
18
18
  roles;
19
19
 
20
20
  constructor(data, bot) {
@@ -22,17 +22,17 @@ export default class Guild extends GuildBased {
22
22
  throw new ConfigError('No data initialized for GlobalConfig');
23
23
 
24
24
  super(data, bot);
25
- this.categories = new Categories(data.categories, data.id);
26
- this.channels = new Channels(data.channels, data.id);
27
- this.logs = new Logs(data.logs, data.id);
28
- this.roles = new Roles(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
 
32
- class Categories extends ChannelBased {}
32
+ class CategoriesTutor extends ChannelBased {}
33
33
 
34
- class Channels extends ChannelBased {}
34
+ class ChannelsTutor extends ChannelBased {}
35
35
 
36
- class Logs extends ChannelBased {}
36
+ class LogsTutor extends ChannelBased {}
37
37
 
38
- class Roles extends RoleBased {}
38
+ class RolesTutor extends RoleBased {}
@@ -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
  }
@@ -27,7 +27,7 @@ export default class SecretConfig {
27
27
  this.token = env.TOKEN;
28
28
 
29
29
  var databaseConfigs = [];
30
- for (let index = 0, section = "DATABASE__"+index; !!env[section+"__NAME"]; index++) {
30
+ for (let index = 0, section = "DATABASE__"+index; !!env[section+"__NAME"]; index++, section = "DATABASE__"+index) {
31
31
  try {
32
32
  let db_config = {
33
33
  client: 'mysql',