From b3857cd96eec4a728f5b10d74ca86f00a3fd4801 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 9 May 2019 13:05:00 -0400 Subject: [PATCH] channel parting --- sopel_modules/SpiceBot_Channels/Channels.py | 29 +++++++++---------- .../SpiceBot_Channels/Channels_Command.py | 3 ++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sopel_modules/SpiceBot_Channels/Channels.py b/sopel_modules/SpiceBot_Channels/Channels.py index 7e972d5..482d5b8 100644 --- a/sopel_modules/SpiceBot_Channels/Channels.py +++ b/sopel_modules/SpiceBot_Channels/Channels.py @@ -53,16 +53,10 @@ def shutdown(bot): def trigger_channel_list_initial(bot, trigger): bot_events_recieved(bot, trigger.event) - ignorepartlist = [] - if bot.config.SpiceBot_Logs.logging_channel: - ignorepartlist.append(bot.config.SpiceBot_Logs.logging_channel) - # Unkickable bot.write(('SAMODE', bot.nick, '+q')) - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) bot.write(['LIST']) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -89,16 +83,12 @@ def trigger_channel_list_initial(bot, trigger): if "*" in bot.memory['SpiceBot_Channels']['channels']: del bot.memory['SpiceBot_Channels']['channels']["*"] - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) while True: try: time.sleep(1800) - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) oldlist = list(bot.memory['SpiceBot_Channels']['channels'].keys()) bot.write(['LIST']) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -118,13 +108,20 @@ def trigger_channel_list_initial(bot, trigger): if "*" in bot.memory['SpiceBot_Channels']['channels']: del bot.memory['SpiceBot_Channels']['channels']["*"] - for channel in bot.channels.keys(): - if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: - bot.part(channel, "Leaving Empty Channel") + bot_part_empty(bot) except KeyError: return +def bot_part_empty(bot): + ignorepartlist = [] + if bot.config.SpiceBot_Logs.logging_channel: + ignorepartlist.append(bot.config.SpiceBot_Logs.logging_channel) + for channel in bot.channels.keys(): + if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist: + bot.part(channel, "Leaving Empty Channel") + + @sopel.module.event('2001') @sopel.module.rule('.*') def bot_events_setup(bot, trigger): diff --git a/sopel_modules/SpiceBot_Channels/Channels_Command.py b/sopel_modules/SpiceBot_Channels/Channels_Command.py index 0914447..65858f9 100644 --- a/sopel_modules/SpiceBot_Channels/Channels_Command.py +++ b/sopel_modules/SpiceBot_Channels/Channels_Command.py @@ -11,6 +11,7 @@ from sopel_modules.SpiceBot_SBTools import ( sopel_triggerargs, inlist, channel_privs, join_all_channels, channel_list_current, ) +from .Channels import bot_part_empty @sopel.module.nickname_commands('channels', 'channel') @@ -56,6 +57,7 @@ def nickname_comand_channels(bot, trigger): if not trigger.admin: bot.osd("You do not have permission to update the channel listing.") return + bot_part_empty(bot) bot.write(['LIST']) bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."]) bot.memory['SpiceBot_Channels']['ProcessLock'] = True @@ -64,6 +66,7 @@ def nickname_comand_channels(bot, trigger): join_all_channels(bot) foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys()) bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.") + bot_part_empty(bot) return elif commandused == 'topic':