sm00th / bitlbee-discord

Bitlbee plugin for Discord (http://discordapp.com)
GNU General Public License v2.0
290 stars 27 forks source link

Enable self messages #103

Closed mickael9 closed 6 years ago

mickael9 commented 6 years ago

Messages sent from another discord client will now appear as if you sent them from Bitlbee.

See https://wiki.bitlbee.org/SelfMessages for more information about this feature.

dequis commented 6 years ago

Have you tested this? What are you trying to do? That flag does nothing for groupchat messages

mickael9 commented 6 years ago

I tested this on channels, it allows messages sent by myself from another discord client to appear as self messages on IRC (https://wiki.bitlbee.org/SelfMessages)

dequis commented 6 years ago

Nevermind the flag does do something, confused it with something else.

It's not strictly correct to apply it to all messages, but I guess it doesn't hurt either.

mickael9 commented 6 years ago

Yes, I noticed that, I'm trying to improve it now since I'm not actually sure it doesn't hurt having it unconditionally. I'd also like it to work with private messages!

sm00th commented 6 years ago

The patch I had for this was a bit more complicated. The problem I had with this is described in #7: this results in echoed messages when sending from bitlbee which I see as the main usecase.

mickael9 commented 6 years ago

I see what this is trying to do but it seems to have a race conditon between the HTTP post response and the echo from the gateway (in the debug log, the gateway echo appears first).

I see there is a nonce field that can be set when sending a message which gets repeated in the echo from the gateway. We could set it to a random string and use that instead of the message id which can't be predicted.

Perhaps we could do even simpler, setting the nonce to a fixed value per connection so we can ignore all self messages that we generated ourselves without having to keep track of them.

sm00th commented 6 years ago

I see what this is trying to do but it seems you have a race conditon between the time you receive the message info (with its id) from the HTTP POST request and the time you receive the message from the gateway (in the debug log, the gateway response appears first).

Yeah, that was written a while ago, things probably have changed.

I see there is a nonce field that you can set in the message (and which gets repeated in the echo), we could set this to a random string and use that instead of the message id which we can't predict.

Oh so they did add something we can use for this, nice. Haven't looked at discord's API in a while. I think that at this point we don't even need the nonce string to be unique per-session, it can just be hardcoded as "bitblee" or something like that. It could be later changed to random ids if it is decided to use this field for it's original purpose.

mickael9 commented 6 years ago

PR updated with some inspiration from @sm00th's patch

For some reason, self messages don't work in private chats, but I think this might be an issue on the bitlbee side

Edit: actually, this was my mistake, it seems to work flawlessly now ! :tada: