Skip to content

Commit

Permalink
rename webhook package and classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmakila committed Sep 26, 2024
1 parent b879029 commit e776215
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fi.fabianadrian.webhooklogger.common;

import fi.fabianadrian.webhooklogger.common.client.ClientManager;
import fi.fabianadrian.webhooklogger.common.webhook.WebhookManager;
import fi.fabianadrian.webhooklogger.common.command.CaptionFormatter;
import fi.fabianadrian.webhooklogger.common.command.BaseCommand;
import fi.fabianadrian.webhooklogger.common.command.commands.ReloadCommand;
Expand All @@ -25,7 +25,7 @@ public final class WebhookLogger {
private final Platform platform;
private final CommandManager<Audience> commandManager;
private final ConfigManager configManager;
private final ClientManager clientManager;
private final WebhookManager clientManager;
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private final DependencyManager dependencyManager = new DependencyManager();

Expand All @@ -41,7 +41,7 @@ public WebhookLogger(Platform platform) {
setupCommandManager();
registerCommands();

this.clientManager = new ClientManager(this);
this.clientManager = new WebhookManager(this);
this.clientManager.reload();
}

Expand Down Expand Up @@ -70,7 +70,7 @@ public Logger logger() {
return this.platform.logger();
}

public ClientManager clientManager() {
public WebhookManager clientManager() {
return this.clientManager;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fi.fabianadrian.webhooklogger.common.client;
package fi.fabianadrian.webhooklogger.common.webhook;

import io.github._4drian3d.jdwebhooks.WebHook;
import io.github._4drian3d.jdwebhooks.WebHookClient;
Expand All @@ -8,13 +8,13 @@
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public final class DiscordClient {
public final class WebhookClient {
private final Queue<String> messageQueue = new ConcurrentLinkedQueue<>();
private final WebHookClient client;
private final Logger logger;
private final String url;

public DiscordClient(Logger logger, String url) {
public WebhookClient(Logger logger, String url) {
this.logger = logger;
this.url = url;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fi.fabianadrian.webhooklogger.common.client;
package fi.fabianadrian.webhooklogger.common.webhook;

import dev.vankka.mcdiscordreserializer.discord.DiscordSerializer;
import fi.fabianadrian.webhooklogger.common.WebhookLogger;
Expand All @@ -13,18 +13,18 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class ClientManager {
public final class WebhookManager {
private final WebhookLogger webhookLogger;
private final WebhookRegistry registry = new WebhookRegistry();
private ScheduledFuture<?> scheduledSendMessageTask;
private MainConfig config;

public ClientManager(WebhookLogger webhookLogger) {
public WebhookManager(WebhookLogger webhookLogger) {
this.webhookLogger = webhookLogger;
}

public void send(EventBuilder eventBuilder) {
List<DiscordClient> clients = this.registry.forEventType(eventBuilder.type());
List<WebhookClient> clients = this.registry.forEventType(eventBuilder.type());
if (clients.isEmpty()) {
return;
}
Expand All @@ -51,7 +51,7 @@ public void reload() {
}

this.scheduledSendMessageTask = this.webhookLogger.scheduler().scheduleAtFixedRate(
() -> this.registry.webhooks().forEach(DiscordClient::sendAll),
() -> this.registry.webhooks().forEach(WebhookClient::sendAll),
0,
this.config.sendRate(),
TimeUnit.SECONDS
Expand All @@ -71,7 +71,7 @@ private void parseWebhooks() {
return;
}

this.registry.register(new DiscordClient(logger, webhook.url()), webhook.events());
this.registry.register(new WebhookClient(logger, webhook.url()), webhook.events());
});
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package fi.fabianadrian.webhooklogger.common.client;
package fi.fabianadrian.webhooklogger.common.webhook;

import fi.fabianadrian.webhooklogger.common.event.EventType;

import java.util.*;

public final class WebhookRegistry {
private final Map<EventType, List<DiscordClient>> eventClientMap = new EnumMap<>(EventType.class);
private final Set<DiscordClient> clients = new HashSet<>();
private final Map<EventType, List<WebhookClient>> eventClientMap = new EnumMap<>(EventType.class);
private final Set<WebhookClient> clients = new HashSet<>();

public void register(final DiscordClient client, final List<EventType> events) {
public void register(final WebhookClient client, final List<EventType> events) {
this.clients.add(client);
events.forEach(event -> this.eventClientMap.computeIfAbsent(event, key -> new ArrayList<>()).add(client));
}
Expand All @@ -18,11 +18,11 @@ public void clear() {
this.eventClientMap.clear();
}

public List<DiscordClient> forEventType(EventType type) {
public List<WebhookClient> forEventType(EventType type) {
return this.eventClientMap.get(type);
}

public Set<DiscordClient> webhooks() {
public Set<WebhookClient> webhooks() {
return Set.copyOf(this.clients);
}

Expand Down

0 comments on commit e776215

Please sign in to comment.