Conversation
Implement basic Discord webhook support to send notifications when plugins are successfully downloaded. Uses jdwebhooks 2.0.0 library with Discord's Components V2 API. Changes: - Add jdwebhooks 2.0.0 dependency to common/impl - Create DiscordWebhookNotifier class for sending webhook notifications - Add discord-webhook configuration section to config.yml (disabled by default) - Update ConfigManager to load and reload webhook settings - Integrate webhook notifications in UpdateHandler on successful downloads - Update UpdaterImpl to initialize and manage webhook notifier lifecycle Webhook notifications include: - Plugin name - Version change (old → new) - Update type (MAJOR, MINOR, PATCH, etc.) - Changelog link (if available) Users can enable by setting discord-webhook.enabled to true and providing a webhook-url in config.yml. Closes OakLoaf#157 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@OakLoaf may you do a Review for this one? |
|
I'm afraid I'm a bit limited on time at the moment, but will try and make some time in the coming weeks to work on, review and merge for v5 |
OakLoaf
left a comment
There was a problem hiding this comment.
Thank you very much for this PR, the majority of this looks really good and ready to go, mainly just some nitpick changes.
I've been inspired by this PR to create a notifier system, so this PR will first be merged into the 'notifier' branch which will be later merged into 'v5' following those changes. The main changes from a user perspective will be the configuration but it should allow the ability to create notifications for other platforms in the future.
That doesn't change the direction or scope of this PR, so don't worry about implementing/changing anything other than the things mentioned in the review :)
| Config discordConfig = config.get("discord-webhook"); | ||
| if (discordConfig != null) { | ||
| this.discordWebhookEnabled = discordConfig.getOrElse("enabled", false); | ||
| this.discordWebhookUrl = discordConfig.getOrElse("webhook-url", ""); | ||
| } else { | ||
| this.discordWebhookEnabled = false; | ||
| this.discordWebhookUrl = ""; | ||
| } | ||
|
|
There was a problem hiding this comment.
I think it would be cleaner to merge discordWebhookEnabled into discordWebhookUrl where the url is null or an empty string if disabled. I don't mind keeping the separate options in the config for convenience and clarity.
| try { | ||
| Version currentVersion = pluginData.currentVersion(); | ||
| Optional<Version> latestVersionOpt = pluginData.latestVersion(); | ||
|
|
|
|
||
| try { | ||
| Version currentVersion = pluginData.currentVersion(); | ||
| Optional<Version> latestVersionOpt = pluginData.latestVersion(); |
There was a problem hiding this comment.
To match the rest of the project it should be named latestVersionOptional, or alternatively use the following and do a null check:
| Optional<Version> latestVersionOpt = pluginData.latestVersion(); | |
| Version latestVersion = pluginData.latestVersion().orElse(null); |
| List<ContainerableComponent> components = new ArrayList<>(); | ||
|
|
||
| components.add(Component.textDisplay("**" + pluginName + " Updated**")); | ||
|
|
||
| components.add(Component.textDisplay("**Version:** " + versionString)); |
There was a problem hiding this comment.
We don't need new lines between these lines
| List<ContainerableComponent> components = new ArrayList<>(); | |
| components.add(Component.textDisplay("**" + pluginName + " Updated**")); | |
| components.add(Component.textDisplay("**Version:** " + versionString)); | |
| List<ContainerableComponent> components = new ArrayList<>(); | |
| components.add(Component.textDisplay("**" + pluginName + " Updated**")); | |
| components.add(Component.textDisplay("**Version:** " + versionString)); |
| () -> "Discord webhook returned unsuccessful response. Status code: " | ||
| + statusCode | ||
| + ", response: " | ||
| + response |
There was a problem hiding this comment.
Could we replace this string formatting with similar to the rest of the project like below, we can then inline this log
| () -> "Discord webhook returned unsuccessful response. Status code: " | |
| + statusCode | |
| + ", response: " | |
| + response | |
| () -> "Discord webhook returned unsuccessful response. Status code: %s, response: %s" | |
| .formatted(statusCode, response) |
| String versionDiff = pluginData.versionDifference().name(); | ||
| if (!versionDiff.equals("UNKNOWN")) { | ||
| components.add(Component.textDisplay("**Update Type:** " + versionDiff)); | ||
| } |
There was a problem hiding this comment.
| String versionDiff = pluginData.versionDifference().name(); | |
| if (!versionDiff.equals("UNKNOWN")) { | |
| components.add(Component.textDisplay("**Update Type:** " + versionDiff)); | |
| } | |
| VersionDifference versionDiff = pluginData.versionDifference(); | |
| if (versionDiff != VersionDifference.UNKNOWN)) { | |
| components.add(Component.textDisplay("**Update Type:** " + versionDiff.name())); | |
| } |
| return config; | ||
| } | ||
|
|
||
| public DiscordWebhookNotifier discordWebhookNotifier() { |
There was a problem hiding this comment.
Can we change this to discordWebHookNotifier please.
Additionally, for this method can we return Optional<DiscordWebhookNotifier> and then in places we want to use the notifier we can run #discordWebHookNotifier#ifPresent
| } | ||
| } | ||
|
|
||
| public void close() { |
There was a problem hiding this comment.
Could we rename this to shutdown to be named similarly to other similar methods in this project
|
|
||
| api("io.github.revxrsal:lamp.common:4.0.0-rc.18") | ||
| api("com.electronwill.night-config:yaml:3.9.0") | ||
| api("io.github.4drian3d:jdwebhooks:2.0.0") |
There was a problem hiding this comment.
I don't think we'll need this one outside of this module for the time being so can we set the scope of this to implementation please?
| private final List<PluginDataCollector.Factory> collectors; | ||
| private final UpdateHandler<T> updateHandler; | ||
| private final ConfigManager config; | ||
| private DiscordWebhookNotifier discordWebhookNotifier; |
There was a problem hiding this comment.
| private DiscordWebhookNotifier discordWebhookNotifier; | |
| private DiscordWebhookNotifier discordWebHookNotifier; |
Implement basic Discord webhook support to send notifications when plugins are successfully downloaded. Uses jdwebhooks 2.0.0 library with Discord's Components V2 API.
Changes:
Webhook notifications include:
Infos
Users can enable by setting discord-webhook.enabled to true and providing a webhook-url in config.yml.
Closes #157
AI Disclosure
GitHub Copilot was used for most of the implementation, all code was manually verified & tested on paper. Additional Changes was made to ensure it works correctly.