@somehiddenkey/discord-command-utils 2.1.0 → 2.1.1
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 +1 -1
- package/package.json +1 -1
- package/src/Configs/GlobalConfig/GlobalConfig.js +11 -10
- package/src/Configs/GlobalConfig/GlobalConfigMain.js +6 -6
- package/src/Configs/GlobalConfig/GlobalConfigStaff.js +2 -2
- package/src/Configs/GlobalConfig/GlobalConfigTutor.js +2 -2
- package/src/Configs/NestedGlobalConfig.js +4 -4
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ Your local configuration JSON file should look like this:
|
|
|
62
62
|
### Global configuration
|
|
63
63
|
Loads the global configuration that contains information related to all bot instances, like snowflake IDs of channels, categories, guild, etc. Load a new instance of your global config through the following code:
|
|
64
64
|
```js
|
|
65
|
-
export const globalConfig = GlobalConfig.load("../global_config.json");
|
|
65
|
+
export const globalConfig = GlobalConfig.load("../global_config.json", bot);
|
|
66
66
|
```
|
|
67
67
|
It contains the IDs of the following sections: guilds, categories, channels, log channels and roles. These can be used as constant values throughout your code, making sure that if an ID ever changes, that all bot instances would take the new updated value by simply updating the json once.
|
|
68
68
|
|
package/package.json
CHANGED
|
@@ -10,21 +10,22 @@ import {default as GuildCommunity} from './GlobalConfigCommunity.js';
|
|
|
10
10
|
import {default as GuildTutor} from './GlobalConfigTutor.js';
|
|
11
11
|
import {default as GuildStaff} from './GlobalConfigStaff.js';
|
|
12
12
|
import { GuildBased } from '../NestedGlobalConfig.js';
|
|
13
|
+
import { Client } from 'discord.js';
|
|
13
14
|
|
|
14
15
|
export default class GlobalConfig {
|
|
15
16
|
main
|
|
16
17
|
community
|
|
17
18
|
tutor
|
|
18
19
|
staff
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
/**
|
|
21
22
|
* Loads the JSON file and returns a GlobalConfig instance.
|
|
22
23
|
* @param {string} path
|
|
23
|
-
* @param {
|
|
24
|
+
* @param {Client} bot
|
|
24
25
|
* @returns {GlobalConfig}
|
|
25
26
|
*/
|
|
26
|
-
static async load(path) {
|
|
27
|
-
var json
|
|
27
|
+
static async load(path, bot) {
|
|
28
|
+
var json;
|
|
28
29
|
try {
|
|
29
30
|
const raw = fs.readFileSync(path, { encoding: 'utf8', flag: 'r' });
|
|
30
31
|
json = JSON.parse(raw);
|
|
@@ -32,7 +33,7 @@ export default class GlobalConfig {
|
|
|
32
33
|
consola.error(`Failed to load GlobalConfig from path: ${path}`, error);
|
|
33
34
|
throw error;
|
|
34
35
|
}
|
|
35
|
-
return new GlobalConfig(json.guilds);
|
|
36
|
+
return new GlobalConfig(json.guilds, bot);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -73,11 +74,11 @@ export default class GlobalConfig {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
constructor(data) {
|
|
77
|
-
this.main = new GuildMain(data.main);
|
|
78
|
-
this.community = new GuildCommunity(data.community);
|
|
79
|
-
this.tutor = new GuildTutor(data.tutor);
|
|
80
|
-
this.staff = new GuildStaff(data.staff);
|
|
77
|
+
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);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -17,11 +17,11 @@ export default class Guild extends GuildBased {
|
|
|
17
17
|
/** @type {Roles} */
|
|
18
18
|
roles;
|
|
19
19
|
|
|
20
|
-
constructor(data) {
|
|
20
|
+
constructor(data, bot) {
|
|
21
21
|
if (!data)
|
|
22
22
|
throw new ConfigError('No data initialized for GlobalConfig');
|
|
23
23
|
|
|
24
|
-
super(data);
|
|
24
|
+
super(data, bot);
|
|
25
25
|
this.categories = new Categories(data.categories, this.guild);
|
|
26
26
|
this.channels = new Channels(data.channels, this.guild);
|
|
27
27
|
this.logs = new Logs(data.logs, this.guild);
|
|
@@ -65,8 +65,8 @@ class Categories extends ChannelBased {
|
|
|
65
65
|
/** @type {Set<Snowflake>} */
|
|
66
66
|
study_rooms;
|
|
67
67
|
|
|
68
|
-
constructor(data) {
|
|
69
|
-
super(data);
|
|
68
|
+
constructor(data, guild) {
|
|
69
|
+
super(data, guild);
|
|
70
70
|
this.custom_study_rooms = new Set(data.custom_rooms.concat(data.verified_com));
|
|
71
71
|
this.study_rooms = new Set([...this.custom_study_rooms, data.music, data.timer_25, data.timer_50, data.screen_cam]);
|
|
72
72
|
}
|
|
@@ -166,8 +166,8 @@ class Roles extends RoleBased {
|
|
|
166
166
|
all_staff;
|
|
167
167
|
|
|
168
168
|
|
|
169
|
-
constructor(data) {
|
|
170
|
-
|
|
169
|
+
constructor(data, guild) {
|
|
170
|
+
super(data, guild);
|
|
171
171
|
this.all_staff = [this.jr_staff, this.sr_staff, this.st_team, this.coordinator];
|
|
172
172
|
}
|
|
173
173
|
}
|
|
@@ -17,11 +17,11 @@ export default class Guild extends GuildBased {
|
|
|
17
17
|
/** @type {Roles} */
|
|
18
18
|
roles;
|
|
19
19
|
|
|
20
|
-
constructor(data) {
|
|
20
|
+
constructor(data, bot) {
|
|
21
21
|
if (!data)
|
|
22
22
|
throw new ConfigError('No data initialized for GlobalConfig');
|
|
23
23
|
|
|
24
|
-
super(data);
|
|
24
|
+
super(data, bot);
|
|
25
25
|
this.categories = new Categories(data.categories, data.id);
|
|
26
26
|
this.channels = new Channels(data.channels, data.id);
|
|
27
27
|
this.logs = new Logs(data.logs, data.id);
|
|
@@ -17,11 +17,11 @@ export default class Guild extends GuildBased {
|
|
|
17
17
|
/** @type {Roles} */
|
|
18
18
|
roles;
|
|
19
19
|
|
|
20
|
-
constructor(data) {
|
|
20
|
+
constructor(data, bot) {
|
|
21
21
|
if (!data)
|
|
22
22
|
throw new ConfigError('No data initialized for GlobalConfig');
|
|
23
23
|
|
|
24
|
-
super(data);
|
|
24
|
+
super(data, bot);
|
|
25
25
|
this.categories = new Categories(data.categories, data.id);
|
|
26
26
|
this.channels = new Channels(data.channels, data.id);
|
|
27
27
|
this.logs = new Logs(data.logs, data.id);
|
|
@@ -17,12 +17,12 @@ export class GuildBased extends Fetchable {
|
|
|
17
17
|
* @param {Snowflake} id
|
|
18
18
|
* @returns {Proxy}
|
|
19
19
|
*/
|
|
20
|
-
_createLazyObject(id) {
|
|
20
|
+
_createLazyObject(id, bot) {
|
|
21
21
|
return super._createLazyObject(id, async (id) => await bot.guilds.fetch(id));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
constructor(data){
|
|
25
|
-
this.guild = this._createLazyObject(data.id);
|
|
24
|
+
constructor(data, bot) {
|
|
25
|
+
this.guild = this._createLazyObject(data.id, bot);
|
|
26
26
|
this._config_keys = Object.keys(data).filter(k => k !== 'id').push('guild');
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -49,7 +49,7 @@ export class RoleBased extends Fetchable {
|
|
|
49
49
|
/** @type {Guild} */
|
|
50
50
|
#guild;
|
|
51
51
|
|
|
52
|
-
constructor(data) {
|
|
52
|
+
constructor(data, guild) {
|
|
53
53
|
this.#guild = guild;
|
|
54
54
|
super(data);
|
|
55
55
|
}
|