@somehiddenkey/discord-command-utils 2.1.0 → 2.1.2
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 +19 -14
- package/src/Configs/GlobalConfig/GlobalConfigCommunity.js +12 -12
- package/src/Configs/GlobalConfig/GlobalConfigMain.js +19 -19
- package/src/Configs/GlobalConfig/GlobalConfigStaff.js +15 -15
- package/src/Configs/GlobalConfig/GlobalConfigTutor.js +15 -15
- package/src/Configs/NestedGlobalConfig.js +4 -4
- package/src/Configs/SecretConfig.js +1 -1
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
|
@@ -5,26 +5,31 @@
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import consola from 'consola';
|
|
7
7
|
import { InteractionScope } from "../../Utils/enums.js";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
8
|
+
import GuildMain from './GlobalConfigMain.js';
|
|
9
|
+
import GuildCommunity from './GlobalConfigCommunity.js';
|
|
10
|
+
import GuildTutor from './GlobalConfigTutor.js';
|
|
11
|
+
import 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 {
|
|
16
|
+
/** @type {GuildMain} */
|
|
15
17
|
main
|
|
18
|
+
/** @type {GuildCommunity} */
|
|
16
19
|
community
|
|
20
|
+
/** @type {GuildTutor} */
|
|
17
21
|
tutor
|
|
22
|
+
/** @type {GuildStaff} */
|
|
18
23
|
staff
|
|
19
|
-
|
|
24
|
+
|
|
20
25
|
/**
|
|
21
26
|
* Loads the JSON file and returns a GlobalConfig instance.
|
|
22
27
|
* @param {string} path
|
|
23
|
-
* @param {
|
|
28
|
+
* @param {Client} bot
|
|
24
29
|
* @returns {GlobalConfig}
|
|
25
30
|
*/
|
|
26
|
-
static async load(path) {
|
|
27
|
-
var json
|
|
31
|
+
static async load(path, bot) {
|
|
32
|
+
var json;
|
|
28
33
|
try {
|
|
29
34
|
const raw = fs.readFileSync(path, { encoding: 'utf8', flag: 'r' });
|
|
30
35
|
json = JSON.parse(raw);
|
|
@@ -32,7 +37,7 @@ export default class GlobalConfig {
|
|
|
32
37
|
consola.error(`Failed to load GlobalConfig from path: ${path}`, error);
|
|
33
38
|
throw error;
|
|
34
39
|
}
|
|
35
|
-
return new GlobalConfig(json.guilds);
|
|
40
|
+
return new GlobalConfig(json.guilds, bot);
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
/**
|
|
@@ -73,11 +78,11 @@ export default class GlobalConfig {
|
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
|
|
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);
|
|
81
|
+
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);
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
|
|
@@ -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
|
|
11
|
-
/** @type {
|
|
10
|
+
export default class GuildCommunity extends GuildBased {
|
|
11
|
+
/** @type {CategoriesCommunity} */
|
|
12
12
|
categories;
|
|
13
|
-
/** @type {
|
|
13
|
+
/** @type {ChannelsCommunity} */
|
|
14
14
|
channels;
|
|
15
|
-
/** @type {
|
|
15
|
+
/** @type {LogsCommunity} */
|
|
16
16
|
logs;
|
|
17
|
-
/** @type {
|
|
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
|
|
26
|
-
this.channels = new
|
|
27
|
-
this.logs = new
|
|
28
|
-
this.roles = new
|
|
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);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
class
|
|
32
|
+
class CategoriesCommunity extends ChannelBased {}
|
|
33
33
|
|
|
34
34
|
class Channels extends ChannelBased {}
|
|
35
35
|
|
|
36
|
-
class
|
|
36
|
+
class LogsCommunity extends ChannelBased {}
|
|
37
37
|
|
|
38
|
-
class
|
|
38
|
+
class RolesCommunity extends RoleBased {}
|
|
@@ -7,29 +7,29 @@ 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
|
|
11
|
-
/** @type {
|
|
10
|
+
export default class GuildMain extends GuildBased {
|
|
11
|
+
/** @type {CategoriesMain} */
|
|
12
12
|
categories;
|
|
13
|
-
/** @type {
|
|
13
|
+
/** @type {ChannelsMain} */
|
|
14
14
|
channels;
|
|
15
|
-
/** @type {
|
|
15
|
+
/** @type {LogsMain} */
|
|
16
16
|
logs;
|
|
17
|
-
/** @type {
|
|
17
|
+
/** @type {RolesMain} */
|
|
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);
|
|
25
|
-
this.categories = new
|
|
26
|
-
this.channels = new
|
|
27
|
-
this.logs = new
|
|
28
|
-
this.roles = new
|
|
24
|
+
super(data, bot);
|
|
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
|
|
32
|
+
class CategoriesMain extends ChannelBased {
|
|
33
33
|
/** @type {Set<Snowflake>} */
|
|
34
34
|
custom_rooms;
|
|
35
35
|
/** @type {Set<Snowflake>} */
|
|
@@ -65,14 +65,14 @@ 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
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
class
|
|
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
|
|
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
|
|
121
|
+
class RolesMain extends RoleBased {
|
|
122
122
|
/** @type {Snowflake} */
|
|
123
123
|
cuckoo_ping;
|
|
124
124
|
/** @type {Snowflake} */
|
|
@@ -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
|
}
|
|
@@ -7,32 +7,32 @@ 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
|
|
11
|
-
/** @type {
|
|
10
|
+
export default class GuildStaff extends GuildBased {
|
|
11
|
+
/** @type {CategoriesStaff} */
|
|
12
12
|
categories;
|
|
13
|
-
/** @type {
|
|
13
|
+
/** @type {ChannelsStaff} */
|
|
14
14
|
channels;
|
|
15
|
-
/** @type {
|
|
15
|
+
/** @type {LogsStaff} */
|
|
16
16
|
logs;
|
|
17
|
-
/** @type {
|
|
17
|
+
/** @type {RolesStaff} */
|
|
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);
|
|
25
|
-
this.categories = new
|
|
26
|
-
this.channels = new
|
|
27
|
-
this.logs = new
|
|
28
|
-
this.roles = new
|
|
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);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
class
|
|
32
|
+
class CategoriesStaff extends ChannelBased {}
|
|
33
33
|
|
|
34
|
-
class
|
|
34
|
+
class ChannelsStaff extends ChannelBased {}
|
|
35
35
|
|
|
36
|
-
class
|
|
36
|
+
class LogsStaff extends ChannelBased {}
|
|
37
37
|
|
|
38
|
-
class
|
|
38
|
+
class RolesStaff extends RoleBased {}
|
|
@@ -7,32 +7,32 @@ 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
|
|
11
|
-
/** @type {
|
|
10
|
+
export default class GuildTutor extends GuildBased {
|
|
11
|
+
/** @type {CategoriesTutor} */
|
|
12
12
|
categories;
|
|
13
|
-
/** @type {
|
|
13
|
+
/** @type {ChannelsTutor} */
|
|
14
14
|
channels;
|
|
15
|
-
/** @type {
|
|
15
|
+
/** @type {LogsTutor} */
|
|
16
16
|
logs;
|
|
17
|
-
/** @type {
|
|
17
|
+
/** @type {RolesTutor} */
|
|
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);
|
|
25
|
-
this.categories = new
|
|
26
|
-
this.channels = new
|
|
27
|
-
this.logs = new
|
|
28
|
-
this.roles = new
|
|
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);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
class
|
|
32
|
+
class CategoriesTutor extends ChannelBased {}
|
|
33
33
|
|
|
34
|
-
class
|
|
34
|
+
class ChannelsTutor extends ChannelBased {}
|
|
35
35
|
|
|
36
|
-
class
|
|
36
|
+
class LogsTutor extends ChannelBased {}
|
|
37
37
|
|
|
38
|
-
class
|
|
38
|
+
class RolesTutor extends RoleBased {}
|
|
@@ -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
|
}
|
|
@@ -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',
|