luk3yx / miniirc

A mini IRC framework.
MIT License
11 stars 1 forks source link

Handle to irc object #9

Closed impredicative closed 5 years ago

impredicative commented 5 years ago

Let's say I want to send a message to channel that is not in response to any IRC event or callback. How would I do this? It's easy for me to do when it is in response to a callback, as I am then supplied the irc object.

How would I persistently and independently have a handle to the irc object which also remains usable despite any reconnections? I basically want to send some messages to a channel that are not in any response to any IRC events.

I would rather not use a hacky workaround like using a calback for a PING.

Thanks.

luk3yx commented 5 years ago

The irc object can be used at any time, it's just passed to handlers for convenience and better scalability (and possibly irc.reply in the future).

impredicative commented 5 years ago

Yes. How do I get the irc object in the first place though? I can then cache and reuse it, but how do I get it just once? This is independent of any other handlers I have, such as for PRIVMSG.

luk3yx commented 5 years ago

Yes. How do I get the irc object in the first place though? I can then cache and reuse it, but how do I get it just once? This is independent of any other handlers I have.

miniirc.IRC is a class and returns the irc object:

irc = miniirc.IRC(...)
impredicative commented 5 years ago

The way I've initialized miniirc.IRC, it never returns. It serves forever. Here is an example.

luk3yx commented 5 years ago

You could possibly create a global irc variable and set it from serve() (or set self.irc if you're going to use it inside the Bot class).

impredicative commented 5 years ago

Yes, but miniirc.IRC never returns, so I can't set it.

On seconds thoughts, please disregard this issue altogether. I will obtain a handle to the irc object when the channel is joined using a handler. I will then cache the object if I need to, or I can keep using it in that callback thread.

luk3yx commented 5 years ago

Yes, but miniirc.IRC never returns, so I can't set it.

On seconds thoughts, please disregard this issue altogether. I will obtain a handle to the irc object when the channel is joined. I will then cache the object if I need to, or I can keep using it in that callback thread.

miniirc.IRC returns after the TCP socket is initialised, the main loop is then run in a thread (that isn't marked as daemon so the script doesn't exit).

impredicative commented 5 years ago

Ah, that's right. Pardon my misunderstanding, and thank you so much.

impredicative commented 5 years ago

I made a new bot (irc-rss-feed-bot) using miniirc.

luk3yx commented 5 years ago

@impredicative Do you mind if I add your bots to the working implementations list?

impredicative commented 5 years ago

Please feel free to add.