Fixed embeds in sendMsg & added embedWithHead

This commit is contained in:
Norbi Peti 2017-10-28 20:55:26 +02:00
parent 4ada764a04
commit 541913e2af
2 changed files with 12 additions and 7 deletions

View file

@ -287,7 +287,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
} }
public static void sendMessageToChannel(IChannel channel, String message, EmbedObject embed) { public static void sendMessageToChannel(IChannel channel, String message, EmbedObject embed) {
sendMessageToChannel(channel, message, null, false); sendMessageToChannel(channel, message, embed, false);
} }
public static IMessage sendMessageToChannelWait(IChannel channel, String message) { public static IMessage sendMessageToChannelWait(IChannel channel, String message) {
@ -295,7 +295,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
} }
public static IMessage sendMessageToChannelWait(IChannel channel, String message, EmbedObject embed) { public static IMessage sendMessageToChannelWait(IChannel channel, String message, EmbedObject embed) {
return sendMessageToChannel(channel, message, null, true); return sendMessageToChannel(channel, message, embed, true);
} }
private static IMessage sendMessageToChannel(IChannel channel, String message, EmbedObject embed, boolean wait) { private static IMessage sendMessageToChannel(IChannel channel, String message, EmbedObject embed, boolean wait) {
@ -325,6 +325,10 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
} }
} }
public static EmbedBuilder embedWithHead(EmbedBuilder builder, String playername) {
return builder.withAuthorIcon("https://minotar.net/avatar/" + playername + "/32.png");
}
public static Permission perms; public static Permission perms;
public boolean setupProviders() { public boolean setupProviders() {

View file

@ -44,9 +44,11 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
// embed.appendField("Channel", ((e.getSender() instanceof DiscordSenderBase ? "d|" : "") // embed.appendField("Channel", ((e.getSender() instanceof DiscordSenderBase ? "d|" : "")
// + DiscordPlugin.sanitizeString(e.getChannel().DisplayName)), false); // + DiscordPlugin.sanitizeString(e.getChannel().DisplayName)), false);
if (e.getSender() instanceof Player) if (e.getSender() instanceof Player)
embed.withAuthorIcon("https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png") DiscordPlugin
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=minecraft&id=" .embedWithHead(
+ ((Player) e.getSender()).getUniqueId()); // TODO: Constant/method to get URLs like this embed.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=minecraft&id="
+ ((Player) e.getSender()).getUniqueId()),
((Player) e.getSender()).getName());
else if (e.getSender() instanceof DiscordSenderBase) else if (e.getSender() instanceof DiscordSenderBase)
embed.withAuthorIcon(((DiscordSenderBase) e.getSender()).getUser().getAvatarURL()) embed.withAuthorIcon(((DiscordSenderBase) e.getSender()).getUser().getAvatarURL())
.withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id=" .withAuthorUrl("https://tbmcplugins.github.io/profile.html?type=discord&id="
@ -331,8 +333,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
try { try {
final IReaction reaction = m.getReactionByEmoji(DiscordPlugin.DELIVERED_REACTION); final IReaction reaction = m.getReactionByEmoji(DiscordPlugin.DELIVERED_REACTION);
if (reaction != null) if (reaction != null)
DiscordPlugin DiscordPlugin.perform(() -> m.removeReaction(DiscordPlugin.dc.getOurUser(), reaction));
.performNoWait(() -> m.removeReaction(DiscordPlugin.dc.getOurUser(), reaction));
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e); TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e);
} }