Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Presti <dxssucuk@hotmail.com>
  • Loading branch information
DxsSucuk committed Oct 21, 2024
1 parent 321ccf3 commit a5f928e
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 104 deletions.
193 changes: 105 additions & 88 deletions src/main/java/de/presti/ree6/bot/util/WebhookUtil.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/de/presti/ree6/events/MenuEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) {
event.getChannel().getTimeCreated().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)).replace("T", " "),
ZonedDateTime.now().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)).replace("T", " ")).getBytes(StandardCharsets.UTF_8));

WebhookUtil.sendWebhook(null, webhookMessageBuilder.build(), ticketEntity.getLogChannelWebhookId(), ticketEntity.getLogChannelWebhookToken(), false);
WebhookUtil.sendWebhook(null, webhookMessageBuilder.build(), ticketEntity.getLogChannelWebhookId(), ticketEntity.getLogChannelWebhookToken(), WebhookUtil.WebhookTyp.TICKET);

event.getHook().sendMessage(LanguageService.getByGuild(event.getGuild(), "message.ticket.close").block()).queue();
event.getChannel().delete().delay(2, TimeUnit.SECONDS).queue();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/presti/ree6/events/OtherEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
SQLSession.getSqlConnector().getSqlWorker().getWelcomeWebhook(event.getGuild().getIdLong()).subscribe(webhook -> {
if (webhook.isEmpty()) return;

WebhookUtil.sendWebhook(wmb.build(), webhook.get());
WebhookUtil.sendWebhook(wmb.build(), webhook.get(), WebhookUtil.WebhookTyp.WELCOME);
});
});
}
Expand Down Expand Up @@ -237,7 +237,7 @@ public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) {
channel.getTimeCreated().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)).replace("T", " "),
ZonedDateTime.now().format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)).replace("T", " ")).getBytes(StandardCharsets.UTF_8));

WebhookUtil.sendWebhook(null, webhookMessageBuilder.build(), ticketsEntity.getLogChannelId(), ticketsEntity.getLogChannelWebhookToken(), false);
WebhookUtil.sendWebhook(null, webhookMessageBuilder.build(), ticketsEntity.getLogChannelId(), ticketsEntity.getLogChannelWebhookToken(), WebhookUtil.WebhookTyp.TICKET);
channel.delete().queue();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/de/presti/ree6/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public void createCheckerThread() {
WebhookUtil.sendWebhook(new WebhookMessageBuilder()
.setUsername(BotConfig.getBotName() + "-Scheduler")
.setAvatarUrl(BotWorker.getShardManager().getShards().get(0).getSelfUser().getEffectiveAvatarUrl())
.append(scheduledMessage.getMessage()).build(), scheduledMessage.getScheduledMessageWebhook());
.append(scheduledMessage.getMessage()).build(), scheduledMessage.getScheduledMessageWebhook(), WebhookUtil.WebhookTyp.SCHEDULE);

SQLSession.getSqlConnector().getSqlWorker().deleteEntity(scheduledMessage).block();
}
Expand All @@ -626,7 +626,7 @@ public void createCheckerThread() {
WebhookUtil.sendWebhook(new WebhookMessageBuilder()
.setUsername(BotConfig.getBotName() + "-Scheduler")
.setAvatarUrl(BotWorker.getShardManager().getShards().get(0).getSelfUser().getEffectiveAvatarUrl())
.append(scheduledMessage.getMessage()).build(), scheduledMessage.getScheduledMessageWebhook());
.append(scheduledMessage.getMessage()).build(), scheduledMessage.getScheduledMessageWebhook(), WebhookUtil.WebhookTyp.SCHEDULE);

scheduledMessage.setLastExecute(Timestamp.from(Instant.now()));
SQLSession.getSqlConnector().getSqlWorker().updateEntity(scheduledMessage).block();
Expand All @@ -637,7 +637,7 @@ public void createCheckerThread() {
WebhookUtil.sendWebhook(new WebhookMessageBuilder()
.setUsername(BotConfig.getBotName() + "-Scheduler")
.setAvatarUrl(BotWorker.getShardManager().getShards().get(0).getSelfUser().getEffectiveAvatarUrl())
.append(scheduledMessage.getMessage()).build(), scheduledMessage.getScheduledMessageWebhook());
.append(scheduledMessage.getMessage()).build(), scheduledMessage.getScheduledMessageWebhook(), WebhookUtil.WebhookTyp.SCHEDULE);

scheduledMessage.setLastExecute(Timestamp.from(Instant.now()));
SQLSession.getSqlConnector().getSqlWorker().updateEntity(scheduledMessage).block();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/presti/ree6/module/logger/LoggerQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import club.minnced.discord.webhook.send.WebhookMessageBuilder;
import de.presti.ree6.bot.BotConfig;
import de.presti.ree6.bot.util.WebhookUtil;
import de.presti.ree6.language.LanguageService;
import de.presti.ree6.module.logger.events.LogMessageMember;
import de.presti.ree6.module.logger.events.LogMessageRole;
import de.presti.ree6.module.logger.events.LogMessageUser;
import de.presti.ree6.module.logger.events.LogMessageVoice;
import de.presti.ree6.bot.BotConfig;
import de.presti.ree6.utils.others.ThreadUtil;
import net.dv8tion.jda.api.Permission;

Expand Down Expand Up @@ -470,7 +470,7 @@ else if (loggerMessage.getType() == LogTyp.SERVER_LEAVE && loggerMessage instanc
ThreadUtil.createThread(x -> {
// If not canceled, send it.
if (!loggerMessage.isCanceled()) {
WebhookUtil.sendWebhook(loggerMessage, loggerMessage.getWebhookMessage(), loggerMessage.getId(), loggerMessage.getAuthCode(), true);
WebhookUtil.sendWebhook(loggerMessage, loggerMessage.getWebhookMessage(), loggerMessage.getId(), loggerMessage.getAuthCode(), WebhookUtil.WebhookTyp.LOG);
}

// Remove it from the list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void run() {
webhookMessageBuilder.addEmbeds(webhookEmbedBuilder.build());

webhooks.forEach(webhook -> WebhookUtil.sendWebhook(webhookMessageBuilder.setContent(webhook.getMessage()
.replace("%username%", user.getUsername())).build(), webhook));
.replace("%username%", user.getUsername())).build(), webhook, WebhookUtil.WebhookTyp.INSTAGRAM));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void run() {
.replace("#m", "");
}
webhookMessageBuilder.setContent(message);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook, WebhookUtil.WebhookTyp.RSS);
});
});
} else {
Expand Down Expand Up @@ -212,7 +212,7 @@ public void run() {

webhookMessageBuilder.addEmbeds(webhookEmbedBuilder.build());

webhooks.forEach(webhook -> WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook));
webhooks.forEach(webhook -> WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook, WebhookUtil.WebhookTyp.RSS));
});
} catch (Exception exception) {
Sentry.captureException(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void run() {
.replace("%name%", redditPost.getSubreddit())
.replace("%url%", redditPost.getUrl());
webhookMessageBuilder.setContent(message);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook, WebhookUtil.WebhookTyp.REDDIT);
});
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void sendWebhooks(WebhookEmbedBuilder webhookEmbed, String description, S
.replace("%name%", authorName)
.replace("%url%", redirect);
webhookMessageBuilder.setContent(message);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook, WebhookUtil.WebhookTyp.SPOTIFY);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void run() {
.replace("%name%", user.getDisplayName())
.replace("%url%", "https://tiktok.com/share/video/" + post.getId());
webhookMessageBuilder.setContent(message);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook, WebhookUtil.WebhookTyp.TIKTOK);
});
}
limit.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void run() {
.replace("%name%", channelGoLiveEvent.getStream().getUserName())
.replace("%url%", twitchUrl);
wmb.setContent(message);
WebhookUtil.sendWebhook(wmb.build(), webhook);
WebhookUtil.sendWebhook(wmb.build(), webhook, WebhookUtil.WebhookTyp.TWITCH);
});
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void run() {

webhookMessageBuilder.setContent(message);
webhookMessageBuilder.addEmbeds(webhookEmbedBuilder.build());
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook);
WebhookUtil.sendWebhook(webhookMessageBuilder.build(), webhook, WebhookUtil.WebhookTyp.YOUTUBE);
});

break;
Expand Down

0 comments on commit a5f928e

Please sign in to comment.