@somehiddenkey/discord-command-utils 2.1.2 → 2.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/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.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",
@@ -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,17 +22,34 @@ 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
+ /** @type {GuildBasedChannel} */
36
+ general;
37
+ /** @type {GuildBasedChannel} */
38
+ com_requests;
39
+ /** @type {GuildBasedChannel} */
40
+ managers;
41
+ /** @type {GuildBasedChannel} */
42
+ staff;
43
+ }
35
44
 
36
- class LogsCommunity extends ChannelBased {}
45
+ class LogsCommunity extends ChannelBased {
46
+ /** @type {GuildBasedChannel} */
47
+ communities;
48
+ }
37
49
 
38
- class RolesCommunity extends RoleBased {}
50
+ class RolesCommunity extends RoleBased {
51
+ /** @type {Role} */
52
+ staff;
53
+ /** @type {Role} */
54
+ com_manager;
55
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import ConfigError from "../ConfigError.js";
6
- import pkg from 'discord.js';
6
+ import pkg, { Role } from 'discord.js';
7
7
  import { GuildBased, ChannelBased, RoleBased } from '../NestedGlobalConfig.js';
8
8
  const { GuildBasedChannel } = pkg;
9
9
 
@@ -114,52 +114,50 @@ class LogsMain extends ChannelBased {
114
114
  invites;
115
115
  /** @type {GuildBasedChannel} */
116
116
  command;
117
- /** @type {GuildBasedChannel} */
118
- communities;
119
117
  }
120
118
 
121
119
  class RolesMain extends RoleBased {
122
- /** @type {Snowflake} */
120
+ /** @type {Role} */
123
121
  cuckoo_ping;
124
- /** @type {Snowflake} */
122
+ /** @type {Role} */
125
123
  developer
126
- /** @type {Snowflake} */
124
+ /** @type {Role} */
127
125
  forest_ping;
128
- /** @type {Snowflake} */
126
+ /** @type {Role} */
129
127
  helper;
130
- /** @type {Snowflake} */
128
+ /** @type {Role} */
131
129
  member;
132
- /** @type {Snowflake} */
130
+ /** @type {Role} */
133
131
  music;
134
- /** @type {Snowflake} */
132
+ /** @type {Role} */
135
133
  muted;
136
- /** @type {Snowflake} */
134
+ /** @type {Role} */
137
135
  no_pc;
138
- /** @type {Snowflake} */
136
+ /** @type {Role} */
139
137
  screen_cam;
140
- /** @type {Snowflake} */
138
+ /** @type {Role} */
141
139
  studying;
142
- /** @type {Snowflake} */
140
+ /** @type {Role} */
143
141
  timer_25;
144
- /** @type {Snowflake} */
142
+ /** @type {Role} */
145
143
  timer_50;
146
- /** @type {Snowflake} */
144
+ /** @type {Role} */
147
145
  tutor;
148
- /** @type {Snowflake} */
146
+ /** @type {Role} */
149
147
  verified_com;
150
- /** @type {Snowflake} */
148
+ /** @type {Role} */
151
149
  water_ping;
152
- /** @type {Snowflake} */
150
+ /** @type {Role} */
153
151
  deepfocus;
154
- /** @type {Snowflake} */
152
+ /** @type {Role} */
155
153
  sr_staff;
156
- /** @type {Snowflake} */
154
+ /** @type {Role} */
157
155
  staff;
158
- /** @type {Snowflake} */
156
+ /** @type {Role} */
159
157
  jr_staff;
160
- /** @type {Snowflake} */
158
+ /** @type {Role} */
161
159
  st_team;
162
- /** @type {Snowflake} */
160
+ /** @type {Role} */
163
161
  coordinator;
164
162
 
165
163
  /** @type {Set<Snowflake>} */
@@ -168,6 +166,6 @@ class RolesMain extends RoleBased {
168
166
 
169
167
  constructor(data, guild) {
170
168
  super(data, guild);
171
- this.all_staff = [this.jr_staff, this.sr_staff, this.st_team, this.coordinator];
169
+ this.all_staff = new Set([data.jr_staff, data.sr_staff, data.st_team, data.coordinator]);
172
170
  }
173
171
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import ConfigError from "../ConfigError.js";
6
- import pkg from 'discord.js';
6
+ import pkg, {Role} from 'discord.js';
7
7
  import { GuildBased, ChannelBased, RoleBased } from '../NestedGlobalConfig.js';
8
8
  const { GuildBasedChannel } = pkg;
9
9
 
@@ -22,17 +22,49 @@ 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
 
32
- class CategoriesStaff extends ChannelBased {}
33
-
34
- class ChannelsStaff extends ChannelBased {}
32
+ class CategoriesStaff extends ChannelBased {
33
+ /** @type {GuildBasedChannel} */
34
+ modmail;
35
+ }
35
36
 
37
+ class ChannelsStaff extends ChannelBased {
38
+ /** @type {GuildBasedChannel} */
39
+ staff;
40
+ /** @type {GuildBasedChannel} */
41
+ sr_staff;
42
+ /** @type {GuildBasedChannel} */
43
+ developer;
44
+ /** @type {GuildBasedChannel} */
45
+ commands;
46
+ }
36
47
  class LogsStaff extends ChannelBased {}
37
48
 
38
- class RolesStaff extends RoleBased {}
49
+ class RolesStaff extends RoleBased {
50
+ /** @type {Role} */
51
+ int_coordinator;
52
+ /** @type {Role} */
53
+ ext_coordinator;
54
+ /** @type {Role} */
55
+ modmail_access;
56
+ /** @type {Role} */
57
+ sr_staff;
58
+ /** @type {Role} */
59
+ staff;
60
+ /** @type {Role} */
61
+ jr_staff;
62
+ /** @type {Role} */
63
+ developer;
64
+ /** @type {Role} */
65
+ sr_developer;
66
+ /** @type {Role} */
67
+ helper;
68
+ /** @type {Role} */
69
+ events;
70
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import ConfigError from "../ConfigError.js";
6
- import pkg from 'discord.js';
6
+ import pkg, {Role} from 'discord.js';
7
7
  import { GuildBased, ChannelBased, RoleBased } from '../NestedGlobalConfig.js';
8
8
  const { GuildBasedChannel } = pkg;
9
9
 
@@ -22,17 +22,38 @@ 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
 
32
- class CategoriesTutor extends ChannelBased {}
32
+ class CategoriesTutor extends ChannelBased {
33
+ /** @type {GuildBasedChannel} */
34
+ staff;
35
+ }
33
36
 
34
- class ChannelsTutor extends ChannelBased {}
37
+ class ChannelsTutor extends ChannelBased {
38
+ /** @type {GuildBasedChannel} */
39
+ general;
40
+ /** @type {GuildBasedChannel} */
41
+ commands;
42
+ /** @type {GuildBasedChannel} */
43
+ staff_commands;
44
+ /** @type {GuildBasedChannel} */
45
+ applications;
46
+ }
35
47
 
36
48
  class LogsTutor extends ChannelBased {}
37
49
 
38
- class RolesTutor extends RoleBased {}
50
+ class RolesTutor extends RoleBased {
51
+ /** @type {Role} */
52
+ staff;
53
+ /** @type {Role} */
54
+ dev;
55
+ /** @type {Role} */
56
+ tutor;
57
+ /** @type {Role} */
58
+ sr_tutor;
59
+ }
@@ -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
  }