DiscordSRV

DiscordSRV

86.8k Downloads

Events are ignored when users send attachments without also sending text.

RezzedUp opened this issue · 2 comments

commented

All discord message broadcasts should be cancelled with the following code:

@Subscribe
public void testReceive(DiscordGuildMessageReceivedEvent event)
{
    getLogger().info("Received: " + event.getMessage().getContent());
}

@Subscribe
public void testPreProcess(DiscordGuildMessagePreProcessEvent event)
{
    getLogger().info("PreProcessed (CANCELLED): " + event.getMessage().getContent());
    event.setCancelled(true);
}

@Subscribe
public void testPostProcess(DiscordGuildMessagePostProcessEvent event)
{
    getLogger().info("PostProcessed (POST-CANCELLED): " + event.getProcessedMessage());
}

However, when a user sends a pure attachment message (i.e. upload a picture without any text), the result of these events are ignored and DiscordGuildMessagePostProcessEvent isn't called at all.

Testing the code

I tested three scenarios with the code above:

  • A regular message
  • An attachment with text in the same message
  • An uploaded image (pure attachment)

The first two were cancelled as expected, but the third one was broadcasted to the server despite its DiscordGuildMessagePreProcessEvent being cancelled.

Sending messages from discord:

Receiving messages in-game:

Logging DiscordSRV's events:

[Server] INFO (V) RezzedUp »: Sending test #1
[Server] INFO [Demo] Received: Cancel this. (regular message)
[Server] INFO [Demo] PreProcessed (CANCELLED): Cancel this. (regular message)
[Server] INFO [Demo] PostProcessed (POST-CANCELLED): [Discord | Owner] Rezz » Cancel this. (regular message)
[Server] INFO (V) RezzedUp »: Sending test #2
[Server] INFO [Demo] Received: Cancel this.
[Server] INFO [Demo] PreProcessed (CANCELLED): Cancel this.
[Server] INFO [Demo] PostProcessed (POST-CANCELLED): [Discord | Owner] Rezz » Cancel this.
[Server] INFO (V) RezzedUp »: Sending test #3
[Server] INFO [Demo] Received: 
[Server] INFO [Demo] PreProcessed (CANCELLED): 
[Server] INFO [DiscordSRV] Chat: [Discord | Owner] Rezz > https://cdn.discordapp.com/attachments/337080055987568642/337138801522638850/unknown.png

Notice how test #3's log output completely differs from the previous two: the post-process event was skipped and the message content from the other events are blank.

Versions

  • DiscordSRV version 14.7
  • CraftBukkit version git-Spigot-cd6ba67-f7d14f1 (MC: 1.12) (Implementing API version 1.12-R0.1-SNAPSHOT)
commented

Quality report, thank you

commented