Revert the god awful database edits I made and make ducks.py convert to int. Might be an idea to make a make_int function?
This commit is contained in:
parent
a635b1f0a0
commit
301d3cb45a
2 changed files with 13 additions and 17 deletions
16
Database.py
16
Database.py
|
@ -112,24 +112,10 @@ class ServerSettings(Table):
|
||||||
[server_id, setting.lower()])
|
[server_id, setting.lower()])
|
||||||
|
|
||||||
class ChannelSettings(Table):
|
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):
|
def set(self, channel_id, setting, value):
|
||||||
converted_json = self.jsonKeys2int(value)
|
|
||||||
|
|
||||||
self.database.execute(
|
self.database.execute(
|
||||||
"INSERT OR REPLACE INTO channel_settings VALUES (?, ?, ?)",
|
"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):
|
def get(self, channel_id, setting, default=None):
|
||||||
value = self.database.execute_fetchone(
|
value = self.database.execute_fetchone(
|
||||||
"""SELECT value FROM channel_settings WHERE
|
"""SELECT value FROM channel_settings WHERE
|
||||||
|
|
|
@ -52,12 +52,17 @@ class Module(object):
|
||||||
for server in self.bot.servers.values():
|
for server in self.bot.servers.values():
|
||||||
for channel in server.channels.values():
|
for channel in server.channels.values():
|
||||||
ducks_enabled = channel.get_setting("ducks-enabled", 0)
|
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
|
min_time = "min-duck-time-%s" % channel.name
|
||||||
max_time = "max-duck-time-%s" % channel.name
|
max_time = "max-duck-time-%s" % channel.name
|
||||||
|
|
||||||
min_duck_time = channel.get_setting("min-duck-time", 240)
|
min_duck_time = channel.get_setting("min-duck-time", 240)
|
||||||
max_duck_time = channel.get_setting("max-duck-time", 1200)
|
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[min_time] = min_duck_time
|
||||||
self.duck_times[max_time] = max_duck_time
|
self.duck_times[max_time] = max_duck_time
|
||||||
|
|
||||||
|
@ -82,7 +87,10 @@ class Module(object):
|
||||||
|
|
||||||
def duck_bef(self, event):
|
def duck_bef(self, event):
|
||||||
target = event["user"].nickname
|
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")
|
event["stderr"].set_prefix("Kick")
|
||||||
if event["server"].has_user(target):
|
if event["server"].has_user(target):
|
||||||
if not event["server"].is_own_nickname(target):
|
if not event["server"].is_own_nickname(target):
|
||||||
|
@ -135,11 +143,13 @@ class Module(object):
|
||||||
for server in self.bot.servers.values():
|
for server in self.bot.servers.values():
|
||||||
for channel in server.channels.values():
|
for channel in server.channels.values():
|
||||||
ducks_enabled = channel.get_setting("ducks-enabled", 0)
|
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:
|
if ducks_enabled == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.bot.log.info("Ducks enabled for %s: %s", [str(channel.name), str(ducks_enabled)])
|
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 = 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:
|
if ducks_enabled == 1 and active_duck == 0:
|
||||||
ducks = [
|
ducks = [
|
||||||
|
|
Loading…
Reference in a new issue