mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-27 01:40:48 +08:00
Fix places where Discord formatting wasn't sanitized (#4945)
Fixes #4891
This commit is contained in:
parent
9147d1036d
commit
0931b21f6d
@ -6,6 +6,7 @@ import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
|||||||
import net.essentialsx.discord.JDADiscordService;
|
import net.essentialsx.discord.JDADiscordService;
|
||||||
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
||||||
import net.essentialsx.discord.util.DiscordCommandSender;
|
import net.essentialsx.discord.util.DiscordCommandSender;
|
||||||
|
import net.essentialsx.discord.util.MessageUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandException;
|
import org.bukkit.command.CommandException;
|
||||||
|
|
||||||
@ -18,12 +19,12 @@ public class ExecuteCommand extends InteractionCommandImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(InteractionEvent event) {
|
public void onCommand(final InteractionEvent event) {
|
||||||
final String command = event.getStringArgument("command");
|
final String command = event.getStringArgument("command");
|
||||||
event.reply(tl("discordCommandExecuteReply", command));
|
event.reply(tl("discordCommandExecuteReply", command));
|
||||||
Bukkit.getScheduler().runTask(jda.getPlugin(), () -> {
|
Bukkit.getScheduler().runTask(jda.getPlugin(), () -> {
|
||||||
try {
|
try {
|
||||||
Bukkit.dispatchCommand(new DiscordCommandSender(jda, Bukkit.getConsoleSender(), event::reply).getSender(), command);
|
Bukkit.dispatchCommand(new DiscordCommandSender(jda, Bukkit.getConsoleSender(), message -> event.reply(MessageUtil.sanitizeDiscordMarkdown(message))).getSender(), command);
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
// Check if this is a vanilla command, in which case we have to use a vanilla command sender :(
|
// Check if this is a vanilla command, in which case we have to use a vanilla command sender :(
|
||||||
if (e.getMessage().contains("a vanilla command listener") || (e.getCause() != null && e.getCause().getMessage().contains("a vanilla command listener"))) {
|
if (e.getMessage().contains("a vanilla command listener") || (e.getCause() != null && e.getCause().getMessage().contains("a vanilla command listener"))) {
|
||||||
|
@ -8,6 +8,7 @@ import net.essentialsx.api.v2.services.discord.InteractionCommandArgumentType;
|
|||||||
import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
||||||
import net.essentialsx.discord.JDADiscordService;
|
import net.essentialsx.discord.JDADiscordService;
|
||||||
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
||||||
|
import net.essentialsx.discord.util.MessageUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -46,6 +47,6 @@ public class ListCommand extends InteractionCommandImpl {
|
|||||||
for (final String str : output) {
|
for (final String str : output) {
|
||||||
stringBuilder.append(str).append("\n");
|
stringBuilder.append(str).append("\n");
|
||||||
}
|
}
|
||||||
event.reply(stringBuilder.substring(0, stringBuilder.length() - 2));
|
event.reply(MessageUtil.sanitizeDiscordMarkdown(stringBuilder.substring(0, stringBuilder.length() - 2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
|||||||
import net.essentialsx.discord.JDADiscordService;
|
import net.essentialsx.discord.JDADiscordService;
|
||||||
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
import net.essentialsx.discord.interactions.InteractionCommandImpl;
|
||||||
import net.essentialsx.discord.util.DiscordMessageRecipient;
|
import net.essentialsx.discord.util.DiscordMessageRecipient;
|
||||||
|
import net.essentialsx.discord.util.MessageUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@ -34,21 +35,21 @@ public class MessageCommand extends InteractionCommandImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!getHidden && user.isIgnoreMsg()) {
|
if (!getHidden && user.isIgnoreMsg()) {
|
||||||
event.reply(tl("msgIgnore", user.getDisplayName()));
|
event.reply(tl("msgIgnore", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.isAfk()) {
|
if (user.isAfk()) {
|
||||||
if (user.getAfkMessage() != null) {
|
if (user.getAfkMessage() != null) {
|
||||||
event.reply(tl("userAFKWithMessage", user.getDisplayName(), user.getAfkMessage()));
|
event.reply(tl("userAFKWithMessage", MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()), MessageUtil.sanitizeDiscordMarkdown(user.getAfkMessage())));
|
||||||
} else {
|
} else {
|
||||||
event.reply(tl("userAFK", user.getDisplayName()));
|
event.reply(tl("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(tl("msgFormat", tl("meSender"), user.getDisplayName(), message));
|
event.reply(tl("msgFormat", tl("meSender"), MessageUtil.sanitizeDiscordMarkdown(user.getDisplayName()), MessageUtil.sanitizeDiscordMarkdown(message)));
|
||||||
|
|
||||||
user.sendMessage(tl("msgFormat", event.getMember().getTag(), tl("meRecipient"), message));
|
user.sendMessage(tl("msgFormat", event.getMember().getTag(), tl("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
|
||||||
|
Loading…
Reference in New Issue
Block a user