go-twitch-irc icon indicating copy to clipboard operation
go-twitch-irc copied to clipboard

Know when the join attempt is finished

Open GabeDuarteM opened this issue 2 years ago • 5 comments

Hey!! 👋 👋

The client.Join request is a non-blocking request, so there's no way of knowing when it is over (being either successful or not).

I'd like to know that cause I have a list of channels I want to join, and if there's an error on any of them, like for example when the channel does not exist, or if it is suspended at the moment, I'd like to make it visible on the console. Along with that, I also would like to whenever the join attempt is over, display a message on the console (no matter if it was successful or not), to measure how many channels I'm connected, and how many channels are left, to give a sense of progress and to know when it joined all of them.

Is there a way of doing that with the current API?

GabeDuarteM avatar Jun 11 '22 21:06 GabeDuarteM

Listen to the Room state with the room state event hook.

gempir avatar Jun 11 '22 21:06 gempir

But as far as I understood, that would only fire when it was successful right? At least on my tests, it didn't say anything after joining an unexistent or suspended channel

For the successful joins I was using the client.OnNamesMessage method, which seems to fire when we connect to a channel, but the problem is that in the end, I get stuck with a Joined 13/15 message, for example, because there was an error on two of the connections, which I cannot know of. I know one of them is misspelt, and another is suspended, but I only know that because I went after it manually to check... I wanted to make it more evident which channels are wrong, displaying a message with the reason why it couldn't join (or, in the very least, say that there was an error joining those channels)

GabeDuarteM avatar Jun 11 '22 21:06 GabeDuarteM

IRC doesn't support that as far as I am aware joining non existent or banned channels just does nothing or maybe fires a room state Incase of the ban not super sure.

gempir avatar Jun 12 '22 05:06 gempir

I know that twurple (a popular javascript twitch client with IRC support) does that, and looking through its code, according to this part, the way they do it is:

On every join request, they wait for 10 seconds for any of the following:

  1. They register an internal event named _onJoinResult, which is called when the first RoomState event comes in with tags subs-only and slow. If this happens, the join was successful, so they clear the 10 seconds timer. Relevant code
  2. They wait for the NOTICE command, and if it comes with the message type being msg_channel_suspended or msg_banned, they assume the join failed, and return an error with the message type. Relevant code
  3. If we don't get any feedback for 10 seconds, it assumes the join fails, and send a message like Did not receive a reply to join ${channel} in time; assuming that the join failed, with ${channel} being the failed channel name. Relevant code

Its not as straight forward as I first imagined, there's not a specific way to know that directly from twitch, but it does give the tools to know when that happens. With all that, I know I can also do that on my end, but I still think it would be a nice quality of life to have directly on the library, with an event like OnJoinResult, which is called the same way as described above, with the channel name, an ok boolean variable to indicate if it was successful or not, and a message type constant to indicate why the join was not successful (e.g. msg_channel_suspended or msg_banned), or something like that, cause without it, its kinda confusing when you join a channel and it just fails silently, without giving us any error, you might assume its working, when its actually not. In my case, I just noticed that behavior cause I was logging when we get the response out of the OnNamesMessage method, and I noticed I was getting inconsistent results. If not for that, it would be "failing successfully" without noticing...

GabeDuarteM avatar Jun 12 '22 14:06 GabeDuarteM

Sure. It can be implemented I'm not opposed to such a feature. It's a pretty hefty one though and I don't think I will spend any time on it personally, at least not in the foreseeable future.

I'll leave this issue open for any potential contributors

gempir avatar Jun 12 '22 14:06 gempir