Skip to content

DIH4JDA, Sentry & Major Cleanup #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 209 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 136 commits
Commits
Show all changes
209 commits
Select commit Hold shift + click to select a range
0eb1f8d
First Pass on implementing DIH4JDA
jasonlessenich May 27, 2022
f772199
Further implementation of DIH4JDA and added Sentry
jasonlessenich May 27, 2022
30a1bd3
Even more DIH4JDA stuff
jasonlessenich May 27, 2022
bdf9e72
DIH4JDA-ified most user commands
jasonlessenich May 28, 2022
957b0a3
Cleaed up `/leaderboard`
jasonlessenich May 28, 2022
0e67ae6
Updated QOTWNotificationService
jasonlessenich May 28, 2022
2cc6d0b
Fixed `/config` commands
jasonlessenich May 28, 2022
72fd17b
Added missing annotations
jasonlessenich May 28, 2022
6b1edec
Started work on re-implementing help-commands
jasonlessenich May 28, 2022
161a62f
Improved HelpChannelInteractionManager by implement the ComponentHandler
jasonlessenich May 28, 2022
b847c65
Re-implemented `/jam` & `/jam-admin` commands
jasonlessenich May 29, 2022
d69011d
Added `/server-lock status` and refactored all other moderation commands
jasonlessenich May 29, 2022
55f2669
Merge remote-tracking branch 'origin/main' into dynxsty/dih4jda
jasonlessenich Jun 12, 2022
2d9a839
Upgraded JDA & DIH4JDA and added CommandPermissions
jasonlessenich Jun 12, 2022
a2666fd
Further implemented DIH4JDA
jasonlessenich Jun 12, 2022
2ac3e07
Merge branch 'main' into dynxsty/dih4jda
jasonlessenich Jun 17, 2022
43f4536
Refactored `/db-admin` commands and upgraded DIH4JDA
jasonlessenich Jun 17, 2022
25c005b
Refactored `/warn` commands & `/warns`
jasonlessenich Jun 17, 2022
11b46e6
Added guild checks
jasonlessenich Jun 17, 2022
188af5b
Refactored `/suggestion` commands
jasonlessenich Jun 17, 2022
3149acd
Refactored `/say` & `/redeploy` and moved `self_roles` out of the `st…
jasonlessenich Jun 17, 2022
e43d477
Started work on refactoring `/embeds`
jasonlessenich Jun 17, 2022
bc2c542
Re-implemented Custom Commands
jasonlessenich Jun 20, 2022
ecb19c6
Added missing annotations
jasonlessenich Jun 20, 2022
db348ec
Removed Guild-based Slash Command Colors & refactored some more commands
jasonlessenich Jun 20, 2022
8f16349
Refactored even more commands
jasonlessenich Jun 20, 2022
25615fa
Introduction of `ExceptionLogger#capture`
jasonlessenich Jun 21, 2022
0aaa9f9
Added `ExceptionLogger#capture` to most catch phrases
jasonlessenich Jun 21, 2022
d25b1d2
Refactored even more commands
jasonlessenich Jun 21, 2022
7d8c302
Removed `/self-role enable` & replaced it with `/self-role status`
jasonlessenich Jun 21, 2022
8c6e65a
Added some missing annotations and cleaned up some more things
jasonlessenich Jun 21, 2022
83dcee9
Merge branch 'main' into dynxsty/dih4jda
jasonlessenich Jun 21, 2022
6d6f2ca
Re-implemented and cleaned Search Commands
jasonlessenich Jun 21, 2022
696233d
Added missing annotation
jasonlessenich Jun 21, 2022
04c0324
even more cleanup
jasonlessenich Jun 21, 2022
065fa54
Fixed some user commands
jasonlessenich Jun 21, 2022
8d4fc9c
Fixed all checkstyle problems
jasonlessenich Jun 21, 2022
32cc766
Fixed some more compiling issues
jasonlessenich Jun 21, 2022
0f6af94
Added some missing try-with-resources blocks
jasonlessenich Jun 21, 2022
6cc94a8
Removed all the remaining .yaml files
jasonlessenich Jun 21, 2022
3257ccb
Removed old assets and migrations
jasonlessenich Jun 21, 2022
0188b9f
added `/db-admin quick-migrate`
jasonlessenich Jun 21, 2022
a1229e9
Further improved `/db-admin quick-migrate` by using Modals
jasonlessenich Jun 21, 2022
4c748a4
optimized imports
jasonlessenich Jun 21, 2022
4281f64
Removed ReportManager constructor (for now)
jasonlessenich Jun 21, 2022
6d8e9d0
Added missing SlashCommandData
jasonlessenich Jun 21, 2022
b8163a2
Added missing setGuildOnly methods and upgraded DIH4JDA
jasonlessenich Jun 21, 2022
4b292b1
Removed `InteractionListener.java`
jasonlessenich Jun 21, 2022
e96fd06
Updated README.md
jasonlessenich Jun 21, 2022
3033827
Update README.md
jasonlessenich Jun 21, 2022
5cde7b6
Restructured /resources/
jasonlessenich Jun 29, 2022
397e18f
Merge remote-tracking branch 'origin/dynxsty/dih4jda' into dynxsty/di…
jasonlessenich Jun 29, 2022
45ed9cf
Upgraded JDA & DIH4JDA
jasonlessenich Jun 29, 2022
0f58918
Removed deprecated method
jasonlessenich Jun 29, 2022
17a5af0
Upgraded H2; Introduction of `DatabaseRepository.java`
jasonlessenich Jun 29, 2022
d415901
Fixed `DbHelper#initializeSchema` not working correctly after the H2 …
jasonlessenich Jun 29, 2022
f9775ed
added missing null-check for MessageVoteListener
jasonlessenich Jul 9, 2022
a60096e
Renamed `ServerLock` to `ServerLockManager` & upgraded Sentry
jasonlessenich Jul 16, 2022
b784860
Merge remote-tracking branch 'origin/main' into dynxsty/dih4jda
jasonlessenich Jul 16, 2022
7c30cc6
Fixed and cleaned up `SelfRoleInteractionManager.java`
jasonlessenich Jul 16, 2022
5891429
Some cleanup for `CreateSelfRoleSubcommand.java`
jasonlessenich Jul 16, 2022
d574788
Renamed StatsUpdater & Made ImageCache static
jasonlessenich Jul 16, 2022
eefb77a
Added missing `/suggestion on-hold`
jasonlessenich Jul 16, 2022
26b5b73
Fixed `IdCalculatorCommand.java`
jasonlessenich Jul 16, 2022
cdcfa66
Fixed HelpAccountRepository using a negative offset
jasonlessenich Jul 16, 2022
64bc6a8
Upgraded `/help-guidelines` and added null-check for MessageCache#sen…
jasonlessenich Jul 16, 2022
906df2b
Reformatted Schema; Removed Java Jam Relations
jasonlessenich Jul 16, 2022
0034754
Removed all Jam Commands
jasonlessenich Jul 16, 2022
067feb8
Fix checkstyle
jasonlessenich Jul 16, 2022
ecb1fa8
Added SQL to `/format-code`
jasonlessenich Jul 16, 2022
7f5f5dc
Removed JamConfig
jasonlessenich Jul 16, 2022
b4eb4bd
Renamed `/customcommands-admin` to `/customcmds-admin`
jasonlessenich Jul 16, 2022
18d5615
Added query to Search The Web
jasonlessenich Jul 16, 2022
3da2433
Fixed CustomCommandManager not loading commands properly
jasonlessenich Jul 16, 2022
9edc053
Upgraded DIH4JDA
jasonlessenich Jul 16, 2022
40aa244
Fixed compiling issues
jasonlessenich Jul 16, 2022
2e8c0be
Upgraded JDA
jasonlessenich Jul 16, 2022
c1b0941
Added missing allowedMentions for CustomCommands
jasonlessenich Jul 16, 2022
cdd589d
Added missing return
jasonlessenich Jul 16, 2022
fb8b121
Fixed `/customcmds-admin edit` & added fixed logs for `/serverlock st…
jasonlessenich Jul 16, 2022
c5b0995
made `text` option required
jasonlessenich Jul 16, 2022
9b57eee
Fixed `/warns` & `Show Warns`
jasonlessenich Jul 16, 2022
5159abf
Made `/ban` accept users which aren't a part of the server.
jasonlessenich Jul 16, 2022
b739ed7
Upgraded DIH4JDA (and JDA)
jasonlessenich Jul 21, 2022
12c9cdb
Added missing options to custom commands & added message gateway intent
jasonlessenich Jul 21, 2022
b48c22d
Fixed inverted checks
jasonlessenich Jul 21, 2022
e5c5be8
Fixed even more wrong checks
jasonlessenich Jul 21, 2022
d9ed90c
Set Connection Leak Threshold & Added DEBUG Logs logging
jasonlessenich Jul 21, 2022
19bb11b
Fixed some more stuff
jasonlessenich Jul 21, 2022
df1120d
Merge branch 'main' into dynxsty/dih4jda
jasonlessenich Jul 21, 2022
6b5dd23
Fixed HugListener to support ChannelUnions
jasonlessenich Jul 21, 2022
599de71
removed unused imports
jasonlessenich Jul 21, 2022
a5ada55
First pass on implementing custom tags
jasonlessenich Jul 22, 2022
efb03fa
fix checkstyle
jasonlessenich Jul 22, 2022
718eb19
bump dih4jda
jasonlessenich Jul 22, 2022
089f6cd
update comment to better reflect what jda version the bot is using
jasonlessenich Jul 22, 2022
5c2fa61
bump sentry
jasonlessenich Jul 22, 2022
8daed31
Fixed some things regarding custom tags
jasonlessenich Jul 22, 2022
e1e4a2b
fix checkstyle
jasonlessenich Jul 22, 2022
186d54d
Beefed up `Responses` by adding optional args for String formatting &…
jasonlessenich Jul 22, 2022
a338df4
checkstyle's a bitch
jasonlessenich Jul 22, 2022
70db82c
Renamed some methods & added `Responses#replyMissingMember`
jasonlessenich Jul 22, 2022
d5d377a
Significantly cleaned up `/timeout add` & `/timeout remove`
jasonlessenich Jul 22, 2022
ddf4fb1
GOD I HATE CHECKSTYLE AH
jasonlessenich Jul 22, 2022
093e7c5
Re-implemented permission checks to ModerateUserCommand while staying…
jasonlessenich Jul 22, 2022
21c6ad4
fix checkstyle
jasonlessenich Jul 22, 2022
b70597d
Moved admin users into their own config
jasonlessenich Jul 22, 2022
0e88063
Added staff-role checks for ModerateCommand
jasonlessenich Jul 22, 2022
e68191e
Added even more permission checks
jasonlessenich Jul 22, 2022
84d4634
Fixed `/say` & added Staff-Role check
jasonlessenich Jul 23, 2022
9b77fdc
fix checkstyle
jasonlessenich Jul 23, 2022
25adb89
Refactored MetricsUpdater
jasonlessenich Jul 23, 2022
a241639
Renamed multiple config & renamed StatsConfig to MetricsConfig
jasonlessenich Jul 23, 2022
1cd1a98
added default values to config
jasonlessenich Jul 23, 2022
5e85677
fixed connection leaks in StarboardManager
jasonlessenich Jul 23, 2022
85b2dd8
Removed ExceptionLogger from AutoMod
jasonlessenich Jul 23, 2022
74d578f
removed "from" from footer
jasonlessenich Jul 23, 2022
42906b7
Introduction of the `/move-conversation` command
jasonlessenich Jul 23, 2022
8222561
Added spaces between constants
jasonlessenich Jul 23, 2022
88f2802
Removed `MoveConversationCommand#REQUIRED_PERMISSIONS`
jasonlessenich Jul 23, 2022
9867704
Added Report Presence Message
jasonlessenich Jul 23, 2022
b9c242d
First pass on implementing Webhook Message Links
jasonlessenich Jul 23, 2022
f307da9
Added Webhook button (doesnt work atm)
jasonlessenich Jul 24, 2022
2107a01
bumped `DynxstyGIT/discord-webhooks`
jasonlessenich Jul 24, 2022
2e525d6
optimize imports
jasonlessenich Jul 24, 2022
ebfe7d0
Merge pull request #320 from Java-Discord/dynxsty/report_presence
jasonlessenich Jul 24, 2022
0d51e76
Merge pull request #321 from Java-Discord/dynxsty/webhook_message_links
jasonlessenich Jul 24, 2022
824ca9a
Made it more clear that this is only _suggesting_ to move the convers…
jasonlessenich Jul 24, 2022
829dff9
Adjusted command description to better reflect that this is just a su…
jasonlessenich Jul 24, 2022
f4f112a
Moved the order the messages are sent to ensure that the message whic…
jasonlessenich Jul 24, 2022
8eeb0b8
Added SelfMember Permission Checks & Error Consumer
jasonlessenich Jul 24, 2022
39c29df
Added boolean option to enable/disable the Recent Transactions Sectio…
jasonlessenich Jul 24, 2022
4f98cc5
Added Buttons
jasonlessenich Jul 24, 2022
2d8c01d
Removed button from the "Move To" Message
jasonlessenich Jul 24, 2022
d30e168
Added Credits to README.md
jasonlessenich Jul 24, 2022
0db7958
fix checkstyle
jasonlessenich Jul 24, 2022
088b870
Merge pull request #323 from Java-Discord/dynxsty/help_transactions
jasonlessenich Jul 24, 2022
c4009db
Added check for slowmode
jasonlessenich Jul 24, 2022
8a86f3b
Added explicit admin checks
jasonlessenich Jul 24, 2022
1717012
Added `ModerateCommand#setModerationSlashCommandData`
jasonlessenich Jul 24, 2022
a124139
Moved `ModerateCommand#setModerationSlashCommandData` to an interface…
jasonlessenich Jul 24, 2022
4651412
Added some javadoc
jasonlessenich Jul 24, 2022
39f9820
fix checkstyle
jasonlessenich Jul 24, 2022
a8d5ba0
Finalized `/embed create`
jasonlessenich Jul 24, 2022
d4d46e7
Added missing modals
jasonlessenich Jul 24, 2022
b47a3d0
Added the rest of the embed-editing interface
jasonlessenich Jul 24, 2022
c822c50
Added `/embed add-field` & `/embed remove-field`
jasonlessenich Jul 24, 2022
7c6b74a
Fixed DatabaseRepository.java & removed already-completed TODO
jasonlessenich Jul 24, 2022
68ffc4f
Removed GuildUtils & made MetricsUpdater use ExceptionLogger#capture(…
jasonlessenich Jul 24, 2022
9c67cde
Merge pull request #318 from Java-Discord/dynxsty/move_conversation
MoonTM-GIT Jul 25, 2022
124a74b
Added missing staff check for `/serverlock-admin status`
jasonlessenich Jul 25, 2022
8a823dd
Merge remote-tracking branch 'origin/dynxsty/dih4jda' into dynxsty/di…
jasonlessenich Jul 25, 2022
4ce6340
Removed unnecessary `DatabaseRepository#close` method
jasonlessenich Jul 25, 2022
daaf932
Added missing command-section in readme
jasonlessenich Jul 25, 2022
2e37755
Added `try-finally` block to properly close Graphics2D
jasonlessenich Jul 25, 2022
d4521a5
Added missing `try-with-resources`
jasonlessenich Jul 25, 2022
9c7645b
Added missing `try-with-resources` in DbHelper.java
jasonlessenich Jul 25, 2022
2ac20ee
Used `Collectors.joining` instead of StringBuilder
jasonlessenich Jul 25, 2022
832a6a3
Used `PreparedStatement` instead
jasonlessenich Jul 25, 2022
1670bb8
Used ExceptionLogger#capture(Throwable, String) instead
jasonlessenich Jul 25, 2022
d6299f7
Made `/config` require admin users
jasonlessenich Jul 25, 2022
d61bce3
Renamed `ListConfigSubcommand` to `ExportConfigSubcommand`
jasonlessenich Jul 25, 2022
24cbece
Replaced all occurrences of `var` & added MANY missing `try-with-reso…
jasonlessenich Jul 25, 2022
d733dcd
Made some requested changes
jasonlessenich Jul 25, 2022
ba56114
Removed member instance from HelpPingCommand#lastPingTimes
jasonlessenich Jul 25, 2022
9880403
Removed unnecessary Statement#close calls
jasonlessenich Jul 25, 2022
a4be72a
Removed TODOs
jasonlessenich Jul 25, 2022
08846a3
Made `/prune` admin-only
jasonlessenich Jul 25, 2022
f2fc390
Refactored `/unban` to take a reason option
jasonlessenich Jul 25, 2022
e48c844
Added missing occurrence of ExceptionLogger
jasonlessenich Jul 25, 2022
4d02c6a
Added `/serverlock-admin check-status` & added missing unban reason
jasonlessenich Jul 25, 2022
81d1035
Added `Constants#INVITE_URL`
jasonlessenich Jul 25, 2022
bd4f5b0
Added channel mentions to `/say`
jasonlessenich Jul 25, 2022
fc91a65
Fixed MessageChannel check
jasonlessenich Jul 25, 2022
eff9540
Added missing null checks
jasonlessenich Jul 25, 2022
6e0af58
Added the clearReaction method to SuggestionSubcommand
jasonlessenich Jul 25, 2022
577c879
implemented missing CommandModerationPermissions
jasonlessenich Jul 25, 2022
bf4cedc
implemented missing CommandModerationPermissions
jasonlessenich Jul 25, 2022
4b7995e
Removed ListenerAdapter from CustomTagManager.java
jasonlessenich Jul 25, 2022
b1a1393
Added missing ExceptionLogger#capture
jasonlessenich Jul 25, 2022
10ac817
Some more cleanup
jasonlessenich Jul 25, 2022
dc0c5eb
Removed duplicate method
jasonlessenich Jul 25, 2022
4f27fc6
Fixed possible NPE
jasonlessenich Jul 25, 2022
cbd558f
Used InteractionHook instead
jasonlessenich Jul 25, 2022
177421f
removed unused import && added support for mod-commands in voice chan…
jasonlessenich Jul 25, 2022
d028cc5
Replaced Paths.get with Path.of
jasonlessenich Jul 25, 2022
18025ab
Removed overrides
jasonlessenich Jul 25, 2022
4a09731
deleted `subcommands` package
jasonlessenich Jul 25, 2022
352999c
Added missing subcommand to ServerLockCommand
jasonlessenich Jul 25, 2022
126e78f
Removed unnecessary overrides
jasonlessenich Jul 25, 2022
263808b
moved `tags` & `self_roles` into the `staff_commands` package
jasonlessenich Jul 25, 2022
ed0671f
Added null-check
jasonlessenich Jul 25, 2022
612a979
fix javadoc
jasonlessenich Jul 25, 2022
db2bf9b
replaced `Member#getUser#getEffectiveAvatarUrl` with `Member#getEffec…
jasonlessenich Jul 25, 2022
a908feb
Made `FormatCodeCommand#buildActionRow` package-private
jasonlessenich Jul 25, 2022
db8cea0
fixed serverlock status settings
jasonlessenich Jul 25, 2022
44f77e0
combined ModerateUserCommand logic with `requireStaff`
jasonlessenich Jul 25, 2022
104f88c
Fixed channel comparing
jasonlessenich Jul 25, 2022
836c1dd
Added status check for `/serverlock-admin set-status`
jasonlessenich Jul 25, 2022
f8cbd6a
fix checkstyle
jasonlessenich Jul 25, 2022
396ced8
fixed config permission checks
jasonlessenich Jul 25, 2022
a4fb476
Fixed HelpChannelInteractionManager#handleHelpThankButton not getting…
jasonlessenich Jul 25, 2022
9adc24c
fix checkstyle
jasonlessenich Jul 25, 2022
c74c58a
added `/tags list` & `/tags view`
jasonlessenich Jul 25, 2022
36b19ad
fix checkstyle
jasonlessenich Jul 25, 2022
b72d0c2
removed params
jasonlessenich Jul 25, 2022
d1a2811
Added check for selfuser when updating starboard messages
jasonlessenich Jul 25, 2022
6c8440a
Added missing ExceptionLogger
jasonlessenich Jul 25, 2022
70ba555
Check if the url really starts with "https" or "http"
jasonlessenich Jul 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build/
/config.json
/config
/purgeArchives
/logs

# Eclipse settings
.classpath
Expand Down
64 changes: 6 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# JavaBot
# JavaBot — General Utility Bot for the [JavaDiscord Community](https://join.javadiscord.net/)

General utility bot for the [JavaDiscord Community](https://join.javadiscord.net/)
![Banner](https://user-images.githubusercontent.com/48297101/174893242-c8fc553a-e36b-4c5f-91d3-9c3bc659a7c9.png)

# Usage

To start up, run the bot once, and it will generate a `config` directory. Stop the bot, and set the up **all of the following values**:
- in `systems.json`
- `jdaBotToken` to your bot's token
- (some `adminUsers` which, e.g., can manipulate the database)
- in `{guildId}.json`
- `moderation.logChannelId` to a channelId
- `moderation.staffRoleId` to a roleId
Expand All @@ -15,65 +16,12 @@ To start up, run the bot once, and it will generate a `config` directory. Stop t

Note that this is just what is required for the bot to start. Certain features may require other values to be set.


# Commands
Commands are defined in this bot using a `.yaml` configuration file located in `src/main/resources/commands`. The data in this file is transformed at startup time into an array of `net.javadiscord.javabot.command.data.slash_commands.SlashCommandConfig` objects using JSON deserialization.

These commands are then used by `net.javadiscord.javabot.command.InteractionHandler#registerSlashCommands(Guild)` to register the defined commands as Discord slash commands which become available to users in guilds and private messages with the bot.

**Each command MUST define a `handler` property, whose name is the fully-qualified class name of a `SlashCommand`.** 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 that your handler class has a no-args constructor.

### Privileges
To specify that a command should only be allowed to be executed by certain people, you can specify a list of privileges. For example:
```yaml
- name: jam-admin
description: Administrator actions for configuring the Java Jam.
handler: net.javadiscord.javabot.systems.jam.JamAdminCommandHandler
enabledByDefault: false
privileges:
- type: ROLE
id: jam.adminRoleId
- type: USER
id: 235439851263098880
```
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.

*Context-Commands work in almost the same way, follow the steps above but replace `SlashCommand` with `MessageContextCommand` or `UserContextCommand`.*

### Autocomplete
To enable Autocomplete for a certain Slash Command Option, head to the command's entry in the corresponding
YAML-File and set the `autocomplete` value.

```yaml
- name: remove
description: Removes a question from the queue.
options:
- name: id
description: The id of the question to remove.
required: true
autocomplete: true
type: INTEGER
```

Now, you just need to implement `Autocompletable` in your handler class.

```java
@Override
public AutoCompleteCallbackAction handleAutocomplete(CommandAutoCompleteInteractionEvent event) {
return switch (event.getSubcommandName()) {
case "remove" -> ListQuestionsSubcommand.replyQuestions(event);
default -> event.replyChoices();
};
}
```

The `handleAutocomplete` method of your handler class now gets fired once someone is focusing any Slash Command Option that has the `autocomplete`
property set to true.


# Configuration
The bot's configuration consists of a collection of simple JSON files:
- `systems.json` contains global settings for the bot's core systems.
- For every guild, a `{guildId}.json` file exists, which contains any guild-specific configuration settings.

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.

# Commands
_Work in Progress_
13 changes: 9 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")

implementation("net.dv8tion:JDA:5.0.0-alpha.12")
// DIH4JDA (Interaction Framework) (includes JDA (jda5.0.0-alpha.17))
implementation("com.github.DynxstyGIT:DIH4JDA:f87f54eb42")

implementation("com.google.code.gson:gson:2.9.0")
implementation("org.yaml:snakeyaml:1.30")
implementation("com.google.re2j:re2j:1.6")
Expand All @@ -32,20 +34,23 @@ dependencies {
implementation("com.mashape.unirest:unirest-java:1.4.9")

// H2 Database
implementation("com.h2database:h2:1.4.200")
implementation("com.h2database:h2:2.1.212")
implementation("com.zaxxer:HikariCP:5.0.1")

// Quartz scheduler
// Quartz Scheduler
implementation("org.quartz-scheduler:quartz:2.3.2")

// Webhooks
implementation("club.minnced:discord-webhooks:0.8.0")
implementation("com.github.DynxstyGIT:discord-webhooks:74301a46a0")

// Lombok Annotations
compileOnly("org.projectlombok:lombok:1.18.24")
annotationProcessor("org.projectlombok:lombok:1.18.24")
testCompileOnly("org.projectlombok:lombok:1.18.24")
testAnnotationProcessor("org.projectlombok:lombok:1.18.24")

// Sentry
implementation("io.sentry:sentry:6.3.0")
}

tasks.withType<Jar> {
Expand Down
136 changes: 101 additions & 35 deletions src/main/java/net/javadiscord/javabot/Bot.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package net.javadiscord.javabot;

import com.dynxsty.dih4jda.DIH4JDA;
import com.dynxsty.dih4jda.DIH4JDABuilder;
import com.dynxsty.dih4jda.interactions.commands.RegistrationType;
import com.zaxxer.hikari.HikariDataSource;
import io.sentry.Sentry;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
Expand All @@ -11,25 +15,41 @@
import net.dv8tion.jda.api.utils.ChunkingFilter;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import net.javadiscord.javabot.command.InteractionHandler;
import net.javadiscord.javabot.data.config.BotConfig;
import net.javadiscord.javabot.data.h2db.DbHelper;
import net.javadiscord.javabot.data.h2db.commands.QuickMigrateSubcommand;
import net.javadiscord.javabot.data.h2db.message_cache.MessageCache;
import net.javadiscord.javabot.data.h2db.message_cache.MessageCacheListener;
import net.javadiscord.javabot.listener.*;
import net.javadiscord.javabot.systems.staff_commands.embeds.AddEmbedFieldSubcommand;
import net.javadiscord.javabot.systems.tags.CustomTagManager;
import net.javadiscord.javabot.systems.tags.commands.CreateCustomTagSubcommand;
import net.javadiscord.javabot.systems.help.HelpChannelInteractionManager;
import net.javadiscord.javabot.systems.help.HelpChannelListener;
import net.javadiscord.javabot.systems.moderation.AutoMod;
import net.javadiscord.javabot.systems.moderation.ServerLock;
import net.javadiscord.javabot.systems.moderation.report.ReportManager;
import net.javadiscord.javabot.systems.moderation.server_lock.ServerLockManager;
import net.javadiscord.javabot.systems.qotw.commands.questions_queue.AddQuestionSubcommand;
import net.javadiscord.javabot.systems.qotw.submissions.SubmissionInteractionManager;
import net.javadiscord.javabot.systems.self_roles.SelfRoleInteractionManager;
import net.javadiscord.javabot.systems.staff_commands.embeds.CreateEmbedSubcommand;
import net.javadiscord.javabot.systems.staff_commands.embeds.EditEmbedSubcommand;
import net.javadiscord.javabot.systems.starboard.StarboardManager;
import net.javadiscord.javabot.systems.tags.commands.EditCustomTagSubcommand;
import net.javadiscord.javabot.systems.user_commands.leaderboard.ExperienceLeaderboardSubcommand;
import net.javadiscord.javabot.tasks.PresenceUpdater;
import net.javadiscord.javabot.tasks.ScheduledTasks;
import net.javadiscord.javabot.tasks.StatsUpdater;
import net.javadiscord.javabot.util.ImageCacheUtils;
import net.javadiscord.javabot.tasks.MetricsUpdater;
import net.javadiscord.javabot.util.ExceptionLogger;
import net.javadiscord.javabot.util.InteractionUtils;
import org.jetbrains.annotations.NotNull;
import org.quartz.SchedulerException;

import java.nio.file.Path;
import java.time.ZoneOffset;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -44,36 +64,44 @@ public class Bot {
* The set of configuration properties that this bot uses.
*/
public static BotConfig config;
/**
* A reference to the slash command listener that's the main point of
* interaction for users with this bot. It's marked as a publicly accessible
* reference so that {@link InteractionHandler#registerCommands} can
* be called wherever it's needed.
*/
public static InteractionHandler interactionHandler;

/**
* An instance of {@link AutoMod}.
* */
*/
public static AutoMod autoMod;

/**
* A reference to the Bot's {@link DIH4JDA}.
*/
public static DIH4JDA dih4jda;

/**
* The Bots {@link MessageCache}, which handles logging of deleted and edited messages.
*/
public static MessageCache messageCache;

/**
* A reference to the Bot's {@link ServerLockManager}.
*/
public static ServerLockManager serverLockManager;

/**
* A static reference to the {@link CustomTagManager} which handles and loads all registered Custom Commands.
*/
public static CustomTagManager customTagManager;

/**
* A reference to the data source that provides access to the relational
* database that this bot users for certain parts of the application. Use
* this to obtain a connection and perform transactions.
*/
public static HikariDataSource dataSource;

/**
* A general-purpose thread pool that can be used by the bot to execute
* tasks outside the main event processing thread.
*/
public static ScheduledExecutorService asyncPool;
/**
* A reference to the Bot's {@link ImageCacheUtils}.
*/
public static ImageCacheUtils imageCache;

private Bot() {
}
Expand All @@ -83,8 +111,8 @@ private Bot() {
* <ol>
* <li>Setting the time zone to UTC, to keep our sanity when working with times.</li>
* <li>Loading the configuration JSON file.</li>
* <li>Initializing the {@link InteractionHandler} listener (which reads command data from a YAML file).</li>
* <li>Creating and configuring the {@link JDA} instance that enables the bot's Discord connectivity.</li>
* <li>Initializing the {@link DIH4JDA} instance.</li>
* <li>Adding event listeners to the bot.</li>
* </ol>
*
Expand All @@ -95,56 +123,94 @@ public static void main(String[] args) throws Exception {
TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.UTC));
config = new BotConfig(Path.of("config"));
dataSource = DbHelper.initDataSource(config);
interactionHandler = new InteractionHandler();
messageCache = new MessageCache();
autoMod = new AutoMod();
imageCache = new ImageCacheUtils();
asyncPool = Executors.newScheduledThreadPool(config.getSystems().getAsyncPoolSize());
var jda = JDABuilder.createDefault(config.getSystems().getJdaBotToken())
autoMod = new AutoMod();
JDA jda = JDABuilder.createDefault(config.getSystems().getJdaBotToken())
.setStatus(OnlineStatus.DO_NOT_DISTURB)
.setChunkingFilter(ChunkingFilter.ALL)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.enableCache(CacheFlag.ACTIVITY)
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES)
.addEventListeners(interactionHandler, autoMod)
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES, GatewayIntent.MESSAGE_CONTENT)
.addEventListeners(autoMod, new StateListener())
.build();
AllowedMentions.setDefaultMentions(EnumSet.of(Message.MentionType.ROLE, Message.MentionType.CHANNEL, Message.MentionType.USER, Message.MentionType.EMOTE));
addEventListeners(jda);
AllowedMentions.setDefaultMentions(EnumSet.of(Message.MentionType.ROLE, Message.MentionType.CHANNEL, Message.MentionType.USER, Message.MentionType.EMOJI));
dih4jda = DIH4JDABuilder.setJDA(jda)
.setCommandsPackage("net.javadiscord.javabot")
.setDefaultCommandType(RegistrationType.GUILD)
.build();
customTagManager = new CustomTagManager(jda, dataSource);
messageCache = new MessageCache();
serverLockManager = new ServerLockManager(jda);
addEventListeners(jda, dih4jda);
addComponentHandler(dih4jda);
// initialize Sentry
Sentry.init(options -> {
options.setDsn(config.getSystems().getSentryDsn());
options.setTracesSampleRate(1.0);
options.setDebug(false);
});
try {
ScheduledTasks.init(jda);
log.info("Initialized scheduled tasks.");
} catch (SchedulerException e) {
ExceptionLogger.capture(e, Bot.class.getSimpleName());
log.error("Could not initialize all scheduled tasks.", e);
jda.shutdown();
}
}

/**
* Adds all the bot's event listeners to the JDA instance, except for the
* main {@link InteractionHandler} listener and {@link AutoMod}.
* Adds all the bot's event listeners to the JDA instance, except for
* the {@link AutoMod} instance.
*
* @param jda The JDA bot instance to add listeners to.
* @param jda The JDA bot instance to add listeners to.
* @param dih4jda The {@link DIH4JDA} instance.
*/
private static void addEventListeners(JDA jda) {
private static void addEventListeners(@NotNull JDA jda, @NotNull DIH4JDA dih4jda) {
jda.addEventListener(
customTagManager,
serverLockManager,
PresenceUpdater.standardActivities(),
new MessageCacheListener(),
new GitHubLinkListener(),
new MessageLinkListener(),
new GuildJoinListener(),
new ServerLock(jda),
new UserLeaveListener(),
new StartupListener(),
PresenceUpdater.standardActivities(),
new StatsUpdater(),
new MetricsUpdater(),
new SuggestionListener(),
new StarboardManager(),
new InteractionListener(),
new HelpChannelListener(),
new ShareKnowledgeVoteListener(),
new JobChannelVoteListener(),
new PingableNameListener(),
new HugListener()
);
dih4jda.addListener(new DIH4JDAListener());
}

private static void addComponentHandler(@NotNull DIH4JDA dih4jda) {
dih4jda.addButtonHandlers(Map.of(
List.of("experience-leaderboard"), new ExperienceLeaderboardSubcommand(),
List.of("utils"), new InteractionUtils(),
List.of("resolve-report"), new ReportManager(),
List.of("self-role"), new SelfRoleInteractionManager(),
List.of("qotw-submission"), new SubmissionInteractionManager(),
List.of("help-channel", "help-thank"), new HelpChannelInteractionManager()
));
dih4jda.addModalHandlers(Map.of(
List.of("qotw-add-question"), new AddQuestionSubcommand(),
List.of("embed-create"), new CreateEmbedSubcommand(),
List.of(EditEmbedSubcommand.EDIT_EMBED_ID), new EditEmbedSubcommand(),
List.of("embed-addfield"), new AddEmbedFieldSubcommand(),
List.of("quick-migrate"), new QuickMigrateSubcommand(),
List.of("report"), new ReportManager(),
List.of("self-role"), new SelfRoleInteractionManager(),
List.of("tag-create"), new CreateCustomTagSubcommand(),
List.of("tag-edit"), new EditCustomTagSubcommand()
));
dih4jda.addSelectMenuHandlers(Map.of(
List.of("qotw-submission-select"), new SubmissionInteractionManager()
));
}
}

Loading