jaraco / irc

Full-featured Python IRC library for Python.
MIT License
390 stars 84 forks source link

IRC Bot reconn strategy question #222

Open accedic opened 5 months ago

accedic commented 5 months ago

HI, I see theres a startegy based on disconnect. If it disconnect the bot try's to reconnect. However, in my case i'm using this i want the bot to stop reconnecting if i send it a specific command. How would i go about this? I want it to reconnect when something fails, but not when i want it to stop, as i am starting it in a seperate thread.

Thanks

accedic commented 5 months ago

I found a work around to do it, but i would like to no have to modify the code for ExponentialBackoff if possible. If theres already a way somewhere in the code which i missed. I would like the module to stay as stock as possible so i deploy this easy without modifying or forking it. Thanks in advance.

jaraco commented 3 months ago

Agreed, you shouldn't have to modify ExponentialBackoff in order to disconnect.

I presume you're using the irc.bot.SingleServerIRCBot. Why not override _on_disconnect in a subclass? Or you could set your bot's .recon to a strategy that does nothing:

class DoNotReconnect(ReconnectStrategy):
    def run(self, but):
        pass

Then when you've decided not to reconnect, set bot.recon = DoNotReconnect().

Let me know how that goes.