by default, do not prune inactive channels we have modes in

This commit is contained in:
jesopo 2020-02-27 12:37:25 +00:00
parent 4d38639742
commit c3720ce4fa

View file

@ -2,13 +2,20 @@ import datetime
from src import ModuleManager, utils from src import ModuleManager, utils
PRUNE_TIMEDELTA = datetime.timedelta(weeks=2) PRUNE_TIMEDELTA = datetime.timedelta(weeks=2)
SETTING_NAME = "inactive-channels" SETTING_NAME = "inactive-channels"
SETTING = utils.BoolSetting(SETTING_NAME, SETTING = utils.BoolSetting(SETTING_NAME,
"Whether or not to leave inactive channels after 2 weeks") "Whether or not to leave inactive channels after 2 weeks")
MODE_SETTING_NAME = "inactive-channel-modes"
MODE_SETTING = utils.BoolSetting(MODE_SETTING_NAME,
"Whether or not we will leave inactive channels that we have a mode in")
@utils.export("botset", SETTING) @utils.export("botset", SETTING)
@utils.export("serverset", SETTING) @utils.export("serverset", SETTING)
@utils.export("channelset", SETTING) @utils.export("channelset", SETTING)
@utils.export("serverset", MODE_SETTING)
@utils.export("channelset", MODE_SETTING)
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _get_timestamp(self, channel): def _get_timestamp(self, channel):
return channel.get_setting("last-message", None) return channel.get_setting("last-message", None)
@ -29,6 +36,7 @@ class Module(ModuleManager.BaseModule):
parts = [] parts = []
now = utils.datetime.utcnow() now = utils.datetime.utcnow()
botwide_setting = self.bot.get_setting(SETTING_NAME, False) botwide_setting = self.bot.get_setting(SETTING_NAME, False)
botwide_mode_setting = self.bot.get_setting(MODE_SETTING_NAME, False)
for server in self.bot.servers.values(): for server in self.bot.servers.values():
serverwide_setting = server.get_setting( serverwide_setting = server.get_setting(
@ -36,9 +44,15 @@ class Module(ModuleManager.BaseModule):
if not serverwide_setting: if not serverwide_setting:
continue continue
mode_setting = server.get_setting(
MODE_SETTING_NAME, botwide_mode_setting)
our_user = server.get_user(server.nickname)
for channel in server.channels: for channel in server.channels:
if not channel.get_setting(SETTING_NAME, serverwide_setting): if not channel.get_setting(SETTING_NAME, serverwide_setting):
continue continue
if not mode_setting and channel.get_user_modes(our_user):
continue
timestamp = self._get_timestamp(channel) timestamp = self._get_timestamp(channel)
if timestamp: if timestamp: