Add replies

This commit is contained in:
Business Goose 2022-03-29 23:39:31 +01:00
parent 0a74b422a0
commit 35dec7ce8d
No known key found for this signature in database
GPG key ID: 77DCA801362E9645

View file

@ -15,6 +15,7 @@ import org.bukkit.ChatColor;
import org.javacord.api.DiscordApi; import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder; import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.entity.channel.TextChannel; import org.javacord.api.entity.channel.TextChannel;
import org.javacord.api.entity.message.Message;
import org.javacord.api.entity.message.MessageAttachment; import org.javacord.api.entity.message.MessageAttachment;
import org.javacord.api.entity.message.MessageAuthor; import org.javacord.api.entity.message.MessageAuthor;
import org.javacord.api.entity.server.Server; import org.javacord.api.entity.server.Server;
@ -65,11 +66,19 @@ public class DiscordBridge {
if (content.toLowerCase().startsWith(prefix)) { if (content.toLowerCase().startsWith(prefix)) {
COMMAND_MANAGER.parse(content, user.get(), server.get(), message.getChannel(), prefix); COMMAND_MANAGER.parse(content, user.get(), server.get(), message.getChannel(), prefix);
} else { } else {
Optional<Message> referenced = message.getMessage().getReferencedMessage();
String reply = "";
if(referenced.isPresent()) {
Message replyingTo = referenced.get();
reply = String.format("┌ %s\t%s\n", replyingTo.getAuthor().getDiscriminatedName(), replyingTo.getReadableContent());
}
String format = MainConfig.getString((isAdmin) ? ConfigurationEntry.DISCORD_ADMIN_FORMAT : ConfigurationEntry.DISCORD_FORMAT); String format = MainConfig.getString((isAdmin) ? ConfigurationEntry.DISCORD_ADMIN_FORMAT : ConfigurationEntry.DISCORD_FORMAT);
format = format.replace("{TAG}", author.getDiscriminatedName()); format = format.replace("{TAG}", author.getDiscriminatedName());
format = format.replace("{USERNAME}", author.getName()); format = format.replace("{USERNAME}", author.getName());
BaseComponent[] components = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', String.format(format, content))); BaseComponent[] components = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', String.format(format, content)));
TextComponent component = new TextComponent(""); TextComponent component = new TextComponent(reply);
for (BaseComponent baseComponent : components) { for (BaseComponent baseComponent : components) {
component.addExtra(baseComponent); component.addExtra(baseComponent);