mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-12 02:11:29 +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);
|
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.
|
* Gets the member which caused this event.
|
||||||
* @return the member which caused the 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 InteractionEvent interactionEvent = new InteractionEventImpl(event);
|
||||||
final List<String> commandSnowflakes = jda.getSettings().getCommandSnowflakes(command.getName());
|
final List<String> commandSnowflakes = jda.getSettings().getCommandSnowflakes(command.getName());
|
||||||
if (commandSnowflakes != null && !DiscordUtil.hasRoles(event.getMember(), commandSnowflakes)) {
|
if (commandSnowflakes != null && !DiscordUtil.hasRoles(event.getMember(), commandSnowflakes)) {
|
||||||
interactionEvent.reply(tlLiteral("noAccessCommand"));
|
interactionEvent.replyTl("noAccessCommand");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
jda.getPlugin().getEss().scheduleSyncDelayedTask(() -> command.onCommand(interactionEvent));
|
jda.getPlugin().getEss().scheduleSyncDelayedTask(() -> command.onCommand(interactionEvent));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.essentialsx.discord.interactions;
|
package net.essentialsx.discord.interactions;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.utils.AdventureUtil;
|
||||||
import com.earth2me.essentials.utils.FormatUtil;
|
import com.earth2me.essentials.utils.FormatUtil;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
@ -18,6 +19,8 @@ import java.util.List;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which provides information about what triggered an interaction event.
|
* 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));
|
.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
|
@Override
|
||||||
public InteractionMember getMember() {
|
public InteractionMember getMember() {
|
||||||
return member;
|
return member;
|
||||||
|
@ -21,7 +21,7 @@ public class ExecuteCommand extends InteractionCommandImpl {
|
|||||||
@Override
|
@Override
|
||||||
public void onCommand(final InteractionEvent event) {
|
public void onCommand(final InteractionEvent event) {
|
||||||
final String command = event.getStringArgument("command");
|
final String command = event.getStringArgument("command");
|
||||||
event.reply(tlLiteral("discordCommandExecuteReply", command));
|
event.replyTl("discordCommandExecuteReply", command);
|
||||||
Bukkit.getScheduler().runTask(jda.getPlugin(), () -> {
|
Bukkit.getScheduler().runTask(jda.getPlugin(), () -> {
|
||||||
try {
|
try {
|
||||||
Bukkit.dispatchCommand(new DiscordCommandSender(jda, Bukkit.getConsoleSender(), message -> event.reply(MessageUtil.sanitizeDiscordMarkdown(message))).getSender(), command);
|
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 {
|
try {
|
||||||
user = jda.getPlugin().getEss().matchUser(Bukkit.getServer(), null, event.getStringArgument("username"), getHidden, false);
|
user = jda.getPlugin().getEss().matchUser(Bukkit.getServer(), null, event.getStringArgument("username"), getHidden, false);
|
||||||
} catch (PlayerNotFoundException e) {
|
} catch (PlayerNotFoundException e) {
|
||||||
event.reply(tlLiteral("errorWithMessage", e.getMessage()));
|
event.replyTl("errorWithMessage", e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getHidden && user.isIgnoreMsg()) {
|
if (!getHidden && user.isIgnoreMsg()) {
|
||||||
event.reply(tlLiteral("msgIgnore", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName())));
|
event.replyTl("msgIgnore", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.isAfk()) {
|
if (user.isAfk()) {
|
||||||
if (user.getAfkMessage() != null) {
|
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 {
|
} 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()) ?
|
final String message = event.getMember().hasRoles(jda.getSettings().getPermittedFormattingRoles()) ?
|
||||||
FormatUtil.replaceFormat(event.getStringArgument("message")) : FormatUtil.stripFormat(event.getStringArgument("message"));
|
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);
|
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
|
// 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 InteractionMember effectiveUser = userArg == null ? event.getMember() : userArg;
|
||||||
final IUser user = accounts.getUser(effectiveUser.getId());
|
final IUser user = accounts.getUser(effectiveUser.getId());
|
||||||
if (user == null) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getMember().getId().equals(effectiveUser.getId())) {
|
if (event.getMember().getId().equals(effectiveUser.getId())) {
|
||||||
event.reply(tlLiteral("discordCommandAccountResponseLinked", user.getName()));
|
event.replyTl("discordCommandAccountResponseLinked", user.getName());
|
||||||
return;
|
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
|
@Override
|
||||||
public void onCommand(InteractionEvent event) {
|
public void onCommand(InteractionEvent event) {
|
||||||
if (accounts.isLinked(event.getMember().getId())) {
|
if (accounts.isLinked(event.getMember().getId())) {
|
||||||
event.reply(tlLiteral("discordCommandLinkHasAccount"));
|
event.replyTl("discordCommandLinkHasAccount");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final UUID uuid = accounts.getPendingUUID(event.getStringArgument("code"));
|
final UUID uuid = accounts.getPendingUUID(event.getStringArgument("code"));
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
event.reply(tlLiteral("discordCommandLinkInvalidCode"));
|
event.replyTl("discordCommandLinkInvalidCode");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
accounts.registerAccount(uuid, event.getMember(), DiscordLinkStatusChangeEvent.Cause.SYNC_PLAYER);
|
accounts.registerAccount(uuid, event.getMember(), DiscordLinkStatusChangeEvent.Cause.SYNC_PLAYER);
|
||||||
event.reply(tlLiteral("discordCommandLinkLinked"));
|
event.replyTl("discordCommandLinkLinked");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,10 +20,10 @@ public class UnlinkInteractionCommand implements InteractionCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void onCommand(InteractionEvent event) {
|
public void onCommand(InteractionEvent event) {
|
||||||
if (!accounts.removeAccount(event.getMember(), DiscordLinkStatusChangeEvent.Cause.UNSYNC_PLAYER)) {
|
if (!accounts.removeAccount(event.getMember(), DiscordLinkStatusChangeEvent.Cause.UNSYNC_PLAYER)) {
|
||||||
event.reply(tlLiteral("discordCommandUnlinkInvalidCode"));
|
event.replyTl("discordCommandUnlinkInvalidCode");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.reply(tlLiteral("discordCommandUnlinkUnlinked"));
|
event.replyTl("discordCommandUnlinkUnlinked");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user