irc icon indicating copy to clipboard operation
irc copied to clipboard

irccat and irccat2 fail pong

Open AiyionPrime opened this issue 4 years ago • 2 comments

Hey there, I really like the framework, and especially the numerous examples which give a good understanding of what the limits of it are.

I just stumbled upon the frameworks quality:

Handles server PONGing transparently.

I haven't checked all four, but at least the examples irccat and irccat2 are written in a way, that apparently blocks this feature.

I tested this on freenode: env/bin/python irccat2.py irc.freenode.net beloved_test "#irccattest"

write something, make sure it works and then don't do anything for about four minutes and eight seconds (maybe a few more). Freenode will kick you for not having responded in quite a while.

Maybe it would be possible to rewrite the examples, that they don't get kicked while their external input function (bash input) stays silent for a while?

Thanks for the read, aiyion.

AiyionPrime avatar May 25 '20 12:05 AiyionPrime

If I understand it correctly, this could be done by registering an event to call a 'read-all-available-from-stdin' function on a time basis (e.g. every few seconds). This could then also resolve #167 ?

AiyionPrime avatar May 28 '20 23:05 AiyionPrime

The problem with both irccat scripts is they're not written for asynchronous programming. They either bypass the event loop (in the case of irccat2) or hijack it (in the case of irccat).

If I understand it correctly, [handling blocking input] could be done by registering an event to call.

Yes, that sounds suitable, and may be the best approach.

For another example, in the pmxbot.webhooks project, an HTTP server runs in a separate thread and when it receives new messages over the HTTP API, it adds those messages to a queue and then in the IRC bot, relays messages from the queue every .3 seconds. Something similar could be written for to address this need.

Alternatively, one could write a custom event loop that's aware of stdin as one of the file descriptors to monitor and handles that directly.

I welcome investigations and contributions on the matter.

jaraco avatar Jul 18 '20 18:07 jaraco