-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port log analyzer command to bot command (#571)
- Loading branch information
1 parent
c5ea8cb
commit acce259
Showing
5 changed files
with
122 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/de/chojo/repbot/commands/bot/handler/log/Analyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
* | ||
* Copyright (C) RainbowDashLabs and Contributor | ||
*/ | ||
package de.chojo.repbot.commands.bot.handler.log; | ||
|
||
import de.chojo.jdautil.interactions.slash.structure.handler.SlashHandler; | ||
import de.chojo.jdautil.parsing.ValueParser; | ||
import de.chojo.jdautil.wrapper.EventContext; | ||
import de.chojo.repbot.commands.log.handler.BaseAnalyzer; | ||
import de.chojo.repbot.dao.provider.Guilds; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
|
||
public class Analyzer extends BaseAnalyzer implements SlashHandler { | ||
private final Guilds guilds; | ||
|
||
public Analyzer(Guilds guilds) { | ||
this.guilds = guilds; | ||
} | ||
|
||
@Override | ||
public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context) { | ||
var guild_id = ValueParser.parseLong(event.getOption("guild_id").getAsString()); | ||
onSlashCommand(event, context, guilds.byId(guild_id.get()).reputation()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/de/chojo/repbot/commands/log/handler/BaseAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
* | ||
* Copyright (C) RainbowDashLabs and Contributor | ||
*/ | ||
package de.chojo.repbot.commands.log.handler; | ||
|
||
import de.chojo.jdautil.localization.util.LocalizedEmbedBuilder; | ||
import de.chojo.jdautil.localization.util.Replacement; | ||
import de.chojo.jdautil.parsing.ValueParser; | ||
import de.chojo.jdautil.wrapper.EventContext; | ||
import de.chojo.repbot.dao.access.guild.reputation.Reputation; | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; | ||
|
||
public class BaseAnalyzer { | ||
public void onSlashCommand(SlashCommandInteractionEvent event, EventContext context, Reputation reputation) { | ||
var optMessageId = ValueParser.parseLong(event.getOption("message_id").getAsString()); | ||
if (optMessageId.isEmpty()) { | ||
event.reply(context.localize("error.invalidMessage")).setEphemeral(true).queue(); | ||
return; | ||
} | ||
|
||
var resultEntry = reputation.analyzer() | ||
.get(optMessageId.get()); | ||
|
||
if (resultEntry.isEmpty()) { | ||
event.reply(context.localize("command.log.analyzer.notanalyzed")).setEphemeral(true).queue(); | ||
return; | ||
} | ||
|
||
var embed = resultEntry.get().embed(event.getGuild(), context); | ||
|
||
var reputationLogEntries = reputation.log().messageLog(optMessageId.get(), 10); | ||
|
||
var entries = LogFormatter.mapMessageLogEntry(context, reputationLogEntries); | ||
|
||
var builder = new LocalizedEmbedBuilder(context.guildLocalizer()) | ||
.setTitle("command.log.message.message.log", Replacement.create("ID", optMessageId.get())); | ||
|
||
LogFormatter.buildFields(entries, builder); | ||
|
||
embed.add(builder.build()); | ||
|
||
event.replyEmbeds(embed).setEphemeral(true).queue(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters