Fixed removing delivered reactions

This commit is contained in:
Norbi Peti 2018-01-09 19:40:09 +01:00
parent 3af44a053a
commit 1bf0024dc4
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -249,6 +249,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
private BukkitTask rectask; private BukkitTask rectask;
private LinkedBlockingQueue<MessageReceivedEvent> recevents = new LinkedBlockingQueue<>(); private LinkedBlockingQueue<MessageReceivedEvent> recevents = new LinkedBlockingQueue<>();
private IMessage lastmsgfromd; // Last message sent by a Discord user, used for clearing checkmarks
@Override // Discord @Override // Discord
public void handle(MessageReceivedEvent ev) { public void handle(MessageReceivedEvent ev) {
@ -377,15 +378,19 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
} }
} }
if (react) { if (react) {
event.getMessage().getChannel().getMessageHistory(2).stream().forEach(m -> { try {
try { /*
final IReaction reaction = m.getReactionByEmoji(DiscordPlugin.DELIVERED_REACTION); * System.out.println("Got message: " + m.getContent() + " with embeds: " + m.getEmbeds().stream().map(e -> e.getTitle() + " " + e.getDescription())
if (reaction != null) * .collect(Collectors.joining("\n")));
DPUtils.perform(() -> m.removeReaction(DiscordPlugin.dc.getOurUser(), reaction)); */
} catch (Exception e) { if (lastmsgfromd != null) {
TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e); DPUtils.perform(() -> lastmsgfromd.removeReaction(DiscordPlugin.dc.getOurUser(),
DiscordPlugin.DELIVERED_REACTION)); // Remove it no matter what, we know it's there 99.99% of the time
} }
}); } catch (Exception e) {
TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e);
}
lastmsgfromd = event.getMessage();
DPUtils.perform(() -> event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION)); DPUtils.perform(() -> event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION));
} }
} catch (Exception e) { } catch (Exception e) {