mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-13 06:15:08 +01:00
Fix format parsing in various discord commands
This commit is contained in:
parent
d307279b3b
commit
139db29782
@ -10,6 +10,13 @@ public interface InteractionEvent {
|
||||
*/
|
||||
void reply(String message);
|
||||
|
||||
/**
|
||||
* Appends the given string to the initial response message and creates one if it doesn't exist.
|
||||
* @param tlKey The tlKey of the message to append.
|
||||
* @param args The args for the message to append.
|
||||
*/
|
||||
void replyTl(String tlKey, Object... args);
|
||||
|
||||
/**
|
||||
* Gets the member which caused this event.
|
||||
* @return the member which caused the event.
|
||||
|
@ -61,7 +61,7 @@ public class InteractionControllerImpl extends ListenerAdapter implements Intera
|
||||
final InteractionEvent interactionEvent = new InteractionEventImpl(event);
|
||||
final List<String> commandSnowflakes = jda.getSettings().getCommandSnowflakes(command.getName());
|
||||
if (commandSnowflakes != null && !DiscordUtil.hasRoles(event.getMember(), commandSnowflakes)) {
|
||||
interactionEvent.reply(tlLiteral("noAccessCommand"));
|
||||
interactionEvent.replyTl("noAccessCommand");
|
||||
return;
|
||||
}
|
||||
jda.getPlugin().getEss().scheduleSyncDelayedTask(() -> command.onCommand(interactionEvent));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.essentialsx.discord.interactions;
|
||||
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
@ -18,6 +19,8 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
|
||||
/**
|
||||
* A class which provides information about what triggered an interaction event.
|
||||
*/
|
||||
@ -45,6 +48,11 @@ public class InteractionEventImpl implements InteractionEvent {
|
||||
.queue(null, error -> logger.log(Level.SEVERE, "Error while editing command interaction response", error));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replyTl(String tlKey, Object... args) {
|
||||
reply(AdventureUtil.miniToLegacy(tlLiteral(tlKey, args)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionMember getMember() {
|
||||
return member;
|
||||
|
@ -21,7 +21,7 @@ public class ExecuteCommand extends InteractionCommandImpl {
|
||||
@Override
|
||||
public void onCommand(final InteractionEvent event) {
|
||||
final String command = event.getStringArgument("command");
|
||||
event.reply(tlLiteral("discordCommandExecuteReply", command));
|
||||
event.replyTl("discordCommandExecuteReply", command);
|
||||
Bukkit.getScheduler().runTask(jda.getPlugin(), () -> {
|
||||
try {
|
||||
Bukkit.dispatchCommand(new DiscordCommandSender(jda, Bukkit.getConsoleSender(), message -> event.reply(MessageUtil.sanitizeDiscordMarkdown(message))).getSender(), command);
|
||||
|
@ -31,26 +31,26 @@ public class MessageCommand extends InteractionCommandImpl {
|
||||
try {
|
||||
user = jda.getPlugin().getEss().matchUser(Bukkit.getServer(), null, event.getStringArgument("username"), getHidden, false);
|
||||
} catch (PlayerNotFoundException e) {
|
||||
event.reply(tlLiteral("errorWithMessage", e.getMessage()));
|
||||
event.replyTl("errorWithMessage", e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getHidden && user.isIgnoreMsg()) {
|
||||
event.reply(tlLiteral("msgIgnore", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName())));
|
||||
event.replyTl("msgIgnore", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.isAfk()) {
|
||||
if (user.getAfkMessage() != null) {
|
||||
event.reply(tlLiteral("userAFKWithMessage", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()), MessageUtil.sanitizeDiscordMarkdown(user.getAfkMessage())));
|
||||
event.replyTl("userAFKWithMessage", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()), MessageUtil.sanitizeDiscordMarkdown(user.getAfkMessage()));
|
||||
} else {
|
||||
event.reply(tlLiteral("userAFK", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName())));
|
||||
event.replyTl("userAFK", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
final String message = event.getMember().hasRoles(jda.getSettings().getPermittedFormattingRoles()) ?
|
||||
FormatUtil.replaceFormat(event.getStringArgument("message")) : FormatUtil.stripFormat(event.getStringArgument("message"));
|
||||
event.reply(tlLiteral("msgFormat", tlLiteral("meSender"), MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()), MessageUtil.sanitizeDiscordMarkdown(message)));
|
||||
event.replyTl("msgFormat", tlLiteral("meSender"), MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()), MessageUtil.sanitizeDiscordMarkdown(message));
|
||||
|
||||
user.sendTl("msgFormat", event.getMember().getTag(), AdventureUtil.parsed(user.playerTl("meRecipient")), message);
|
||||
// We use an atomic reference here so that java will garbage collect the recipient
|
||||
|
@ -53,14 +53,14 @@ public class AccountInteractionCommand implements InteractionCommand {
|
||||
final InteractionMember effectiveUser = userArg == null ? event.getMember() : userArg;
|
||||
final IUser user = accounts.getUser(effectiveUser.getId());
|
||||
if (user == null) {
|
||||
event.reply(tlLiteral(event.getMember().getId().equals(effectiveUser.getId()) ? "discordCommandAccountResponseNotLinked" : "discordCommandAccountResponseNotLinkedOther", effectiveUser.getAsMention()));
|
||||
event.replyTl(event.getMember().getId().equals(effectiveUser.getId()) ? "discordCommandAccountResponseNotLinked" : "discordCommandAccountResponseNotLinkedOther", effectiveUser.getAsMention());
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getMember().getId().equals(effectiveUser.getId())) {
|
||||
event.reply(tlLiteral("discordCommandAccountResponseLinked", user.getName()));
|
||||
event.replyTl("discordCommandAccountResponseLinked", user.getName());
|
||||
return;
|
||||
}
|
||||
event.reply(tlLiteral("discordCommandAccountResponseLinkedOther", effectiveUser.getAsMention(), user.getName()));
|
||||
event.replyTl("discordCommandAccountResponseLinkedOther", effectiveUser.getAsMention(), user.getName());
|
||||
}
|
||||
}
|
||||
|
@ -25,18 +25,18 @@ public class LinkInteractionCommand implements InteractionCommand {
|
||||
@Override
|
||||
public void onCommand(InteractionEvent event) {
|
||||
if (accounts.isLinked(event.getMember().getId())) {
|
||||
event.reply(tlLiteral("discordCommandLinkHasAccount"));
|
||||
event.replyTl("discordCommandLinkHasAccount");
|
||||
return;
|
||||
}
|
||||
|
||||
final UUID uuid = accounts.getPendingUUID(event.getStringArgument("code"));
|
||||
if (uuid == null) {
|
||||
event.reply(tlLiteral("discordCommandLinkInvalidCode"));
|
||||
event.replyTl("discordCommandLinkInvalidCode");
|
||||
return;
|
||||
}
|
||||
|
||||
accounts.registerAccount(uuid, event.getMember(), DiscordLinkStatusChangeEvent.Cause.SYNC_PLAYER);
|
||||
event.reply(tlLiteral("discordCommandLinkLinked"));
|
||||
event.replyTl("discordCommandLinkLinked");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,10 +20,10 @@ public class UnlinkInteractionCommand implements InteractionCommand {
|
||||
@Override
|
||||
public void onCommand(InteractionEvent event) {
|
||||
if (!accounts.removeAccount(event.getMember(), DiscordLinkStatusChangeEvent.Cause.UNSYNC_PLAYER)) {
|
||||
event.reply(tlLiteral("discordCommandUnlinkInvalidCode"));
|
||||
event.replyTl("discordCommandUnlinkInvalidCode");
|
||||
return;
|
||||
}
|
||||
event.reply(tlLiteral("discordCommandUnlinkUnlinked"));
|
||||
event.replyTl("discordCommandUnlinkUnlinked");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user