Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 8ceca32

Browse files
committed
Added more to the readme.
1 parent 9ae8b88 commit 8ceca32

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,32 @@ docker-compose -p javabot up
1414
For your convenience, the docker-compose file also includes admin tools that can be useful for debugging.
1515
- MongoExpress is available at [localhost:5050](http://localhost:5050)
1616
- PgAdmin is available at [locahost:5051](http://localhost:5051)
17+
18+
Once those services are in order, you can run the bot as you would any Java program, and it will generate a `config` directory. Stop the bot, and set all the necessary properties in `systems.json`.
19+
20+
## Commands
21+
Commands are defined in YAML files located in `src/main/resources/commands`. The data in these files are transformed into an array of `CommandConfig` objects using JSON deserialization. These commands are then used in `SlashCommandListener#registerSlashCommands` to register all slash commands.
22+
23+
**Each command MUST define a `handler` property whose value is the fully-qualified class name of a class implementing `SlashCommandHandler`**. When registering commands, the bot will look for such a class, and attempt to create a new instance of it using a no-args constructor. Therefore, make sure your handler class has a no-args constructor.
24+
25+
## Privileges
26+
To specify that a command should only be allowed to be executed by certain people, you can specify a list of privileges. For example:
27+
```yaml
28+
- name: jam-admin
29+
description: Administrator actions for configuring the Java Jam.
30+
handler: com.javadiscord.javabot2.jam.JamAdminCommandHandler
31+
enabledByDefault: false
32+
privileges:
33+
- type: ROLE
34+
id: jam.adminRoleId
35+
- type: USER
36+
id: 235439851263098880
37+
```
38+
In this example, we define that the `jam-admin` command is first of all, *not enabled by default*, and also we say that anyone from the `jam.adminRoleId` role (as found using `Bot.config.getJam().getAdminRoleId()`). Additionally, we also say that the user whose id is `235439851263098880` is allowed to use this command. See `BotConfig#resolve(String)` for more information about how role names are resolved at runtime.
39+
40+
# Configuration
41+
The bot's configuration consists of a collection of simple JSON files:
42+
- `systems.json` contains global settings for the bot's core systems.
43+
- For every guild, a `{guildId}.json` file exists, which contains any guild-specific configuration settings.
44+
45+
At startup, the bot will initially start by loading just the global settings, and then when the Discord ready event is received, the bot will add configuration for each guild it's in, loading it from the matching JSON file, or creating a new file if needed.

src/main/java/net/javadiscord/javabot2/Bot.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ public static void main(String[] args) {
4141
initDataSources();
4242
asyncPool = Executors.newScheduledThreadPool(config.getSystems().getAsyncPoolSize());
4343
DiscordApi api = new DiscordApiBuilder().setToken(config.getSystems().getDiscordBotToken()).login().join();
44-
config.loadGuilds(api.getServers());
45-
config.flush();
46-
SlashCommandListener commandListener = new SlashCommandListener(api);
44+
config.loadGuilds(api.getServers()); // Once we've logged in, load all guild config files.
45+
config.flush(); // Flush to save any new config files that are generated for new guilds.
46+
SlashCommandListener commandListener = new SlashCommandListener(
47+
api,
48+
"commands/moderation.yaml"
49+
);
4750
api.addSlashCommandCreateListener(commandListener);
4851
}
4952

src/main/java/net/javadiscord/javabot2/command/SlashCommandListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
public final class SlashCommandListener implements SlashCommandCreateListener {
2222
private final Map<Long, SlashCommandHandler> commandHandlers = new HashMap<>();
2323

24-
public SlashCommandListener(DiscordApi api) {
25-
registerSlashCommands(api, "commands/moderation.yaml")
24+
public SlashCommandListener(DiscordApi api, String... resources) {
25+
registerSlashCommands(api, resources)
2626
.thenAcceptAsync(commandHandlers::putAll);
2727
}
2828

0 commit comments

Comments
 (0)