diff --git a/Database.py b/Database.py index b9490af9..c315d801 100644 --- a/Database.py +++ b/Database.py @@ -112,24 +112,10 @@ class ServerSettings(Table): [server_id, setting.lower()]) class ChannelSettings(Table): - def jsonKeys2int(self, x): - if isinstance(x, dict): - hold = {} - for k, v in x.items(): - key = int(k) if k.isdigit() else k - val = int(v) if v.isdigit() else v - - hold[key] = val - return hold - else: - return x - def set(self, channel_id, setting, value): - converted_json = self.jsonKeys2int(value) - self.database.execute( "INSERT OR REPLACE INTO channel_settings VALUES (?, ?, ?)", - [channel_id, setting.lower(), converted_json]) + [channel_id, setting.lower(), json.dumps(value)]) def get(self, channel_id, setting, default=None): value = self.database.execute_fetchone( """SELECT value FROM channel_settings WHERE @@ -368,4 +354,4 @@ class Database(object): DELETE CASCADE, PRIMARY KEY (user_id, channel_id, setting))""") self.execute("""CREATE INDEX user_channel_settings_index - ON user_channel_settings (user_id, channel_id, setting)""") + ON user_channel_settings (user_id, channel_id, setting)""") \ No newline at end of file diff --git a/modules/ducks.py b/modules/ducks.py index f71220bc..6e897c10 100644 --- a/modules/ducks.py +++ b/modules/ducks.py @@ -52,12 +52,17 @@ class Module(object): for server in self.bot.servers.values(): for channel in server.channels.values(): ducks_enabled = channel.get_setting("ducks-enabled", 0) + ducks_enabled = int(ducks_enabled) if isinstance(ducks_enabled, str) else ducks_enabled + min_time = "min-duck-time-%s" % channel.name max_time = "max-duck-time-%s" % channel.name min_duck_time = channel.get_setting("min-duck-time", 240) max_duck_time = channel.get_setting("max-duck-time", 1200) + min_duck_time = int(min_duck_time) if isinstance(min_duck_time, str) else min_duck_time + max_duck_time = int(max_duck_time) if isinstance(max_duck_time, str) else max_duck_time + self.duck_times[min_time] = min_duck_time self.duck_times[max_time] = max_duck_time @@ -82,7 +87,10 @@ class Module(object): def duck_bef(self, event): target = event["user"].nickname - if event["target"].get_setting("active-duck", 0) == 0: + active_duck = event["target"].get_setting("active-duck", 0) + active_duck = int(active_duck) if isinstance(active_duck, str) else active_duck + + if active_duck == 0: event["stderr"].set_prefix("Kick") if event["server"].has_user(target): if not event["server"].is_own_nickname(target): @@ -135,11 +143,13 @@ class Module(object): for server in self.bot.servers.values(): for channel in server.channels.values(): ducks_enabled = channel.get_setting("ducks-enabled", 0) + ducks_enabled = int(ducks_enabled) if isinstance(ducks_enabled, str) else ducks_enabled if ducks_enabled == 0: continue self.bot.log.info("Ducks enabled for %s: %s", [str(channel.name), str(ducks_enabled)]) active_duck = channel.get_setting("active-duck", 0) + active_duck = int(active_duck) if isinstance(active_duck, str) else active_duck if ducks_enabled == 1 and active_duck == 0: ducks = [