@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 +7 -20
- package/package.json +1 -1
- package/src/Configs/GlobalConfig/GlobalConfig.js +10 -8
- package/src/Configs/GlobalConfig/GlobalConfigCommunity.js +5 -5
- package/src/Configs/GlobalConfig/GlobalConfigStaff.js +4 -4
- package/src/Configs/GlobalConfig/GlobalConfigTutor.js +4 -4
- package/src/Configs/LocalConfig.js +3 -8
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
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
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
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
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
|
@@ -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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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,
|
|
26
|
-
this.channels = new ChannelsCommunity(data.channels,
|
|
27
|
-
this.logs = new LogsCommunity(data.logs,
|
|
28
|
-
this.roles = new RolesCommunity(data.roles,
|
|
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
|
|
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,
|
|
26
|
-
this.channels = new ChannelsStaff(data.channels,
|
|
27
|
-
this.logs = new LogsStaff(data.logs,
|
|
28
|
-
this.roles = new RolesStaff(data.roles,
|
|
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,
|
|
26
|
-
this.channels = new ChannelsTutor(data.channels,
|
|
27
|
-
this.logs = new LogsTutor(data.logs,
|
|
28
|
-
this.roles = new RolesTutor(data.roles,
|
|
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
|
|
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
|
-
|
|
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
|
}
|