changed words.py to use new user_channel_settings table
This commit is contained in:
parent
7114bb7155
commit
6a7369f7de
3 changed files with 23 additions and 7 deletions
13
Database.py
13
Database.py
|
@ -270,7 +270,7 @@ class Database(object):
|
||||||
return default
|
return default
|
||||||
def find_user_channel_settings(self, server_id, channel, nickname,
|
def find_user_channel_settings(self, server_id, channel, nickname,
|
||||||
pattern, default=[]):
|
pattern, default=[]):
|
||||||
values = self.cursor().execute(
|
values = self.execute_fetchall(
|
||||||
"""SELECT setting, value FROM user_channel_settings WHERE
|
"""SELECT setting, value FROM user_channel_settings WHERE
|
||||||
server_id=? AND channel=? AND nickname=? AND setting LIKE '?'""",
|
server_id=? AND channel=? AND nickname=? AND setting LIKE '?'""",
|
||||||
[server_id, channel.lower(), nickname.lower(), pattern.lower()])
|
[server_id, channel.lower(), nickname.lower(), pattern.lower()])
|
||||||
|
@ -283,6 +283,17 @@ class Database(object):
|
||||||
prefix, default=[]):
|
prefix, default=[]):
|
||||||
return self.find_user_settings(server_id, nickname, "%s%" % prefix,
|
return self.find_user_settings(server_id, nickname, "%s%" % prefix,
|
||||||
default)
|
default)
|
||||||
|
def get_user_channel_settings_per_setting(self, server_id, nickname,
|
||||||
|
setting, default=[]):
|
||||||
|
values = self.execute_fetchall(
|
||||||
|
"""SELECT channel, value FROM user_channel_settings WHERE
|
||||||
|
server_id=? AND nickname=? AND setting=?""",
|
||||||
|
[server_id, nickname.lower(), setting])
|
||||||
|
if values:
|
||||||
|
for i, value in enumerate(values):
|
||||||
|
values[i] = value[0], json.loads(value[1])
|
||||||
|
return values
|
||||||
|
return default
|
||||||
def del_user_channel_setting(self, server_id, channel, nickname, setting):
|
def del_user_channel_setting(self, server_id, channel, nickname, setting):
|
||||||
self.execute(
|
self.execute(
|
||||||
"""DELETE FROM user_channel_settings WHERE
|
"""DELETE FROM user_channel_settings WHERE
|
||||||
|
|
|
@ -34,6 +34,9 @@ class User(object):
|
||||||
def del_setting(self, setting):
|
def del_setting(self, setting):
|
||||||
self.bot.database.del_user_setting(self.server.id, self.nickname,
|
self.bot.database.del_user_setting(self.server.id, self.nickname,
|
||||||
setting)
|
setting)
|
||||||
|
def get_channel_settings_per_setting(self, setting, default=[]):
|
||||||
|
return self.bot.database.get_user_channel_settings_per_setting(
|
||||||
|
self.server.id, self.nickname, setting, default)
|
||||||
|
|
||||||
def send_message(self, message, prefix=None):
|
def send_message(self, message, prefix=None):
|
||||||
self.server.send_message(self.nickname, message, prefix=prefix)
|
self.server.send_message(self.nickname, message, prefix=prefix)
|
||||||
|
|
|
@ -22,11 +22,11 @@ class Module(object):
|
||||||
words = list(filter(None, event["message_split"]))
|
words = list(filter(None, event["message_split"]))
|
||||||
word_count = len(words)
|
word_count = len(words)
|
||||||
|
|
||||||
user_words = event["user"].get_setting("words", {})
|
user_words = event["channel"].get_user_setting(
|
||||||
if not event["channel"].name in user_words:
|
event["user"].nickname, "words", 0)
|
||||||
user_words[event["channel"].name] = 0
|
user_words += word_count
|
||||||
user_words[event["channel"].name] += word_count
|
event["channel"].set_user_setting(event["user"].nickname,
|
||||||
event["user"].set_setting("words", user_words)
|
"words", user_words)
|
||||||
|
|
||||||
tracked_words = set(event["server"].get_setting(
|
tracked_words = set(event["server"].get_setting(
|
||||||
"tracked-words", []))
|
"tracked-words", []))
|
||||||
|
@ -43,8 +43,10 @@ class Module(object):
|
||||||
][0])
|
][0])
|
||||||
else:
|
else:
|
||||||
target = event["user"]
|
target = event["user"]
|
||||||
words = target.get_setting("words", {})
|
words = dict(target.get_channel_settings_per_setting(
|
||||||
|
"words", []))
|
||||||
this_channel = words.get(event["target"].name, 0)
|
this_channel = words.get(event["target"].name, 0)
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
for channel in words:
|
for channel in words:
|
||||||
total += words[channel]
|
total += words[channel]
|
||||||
|
|
Loading…
Reference in a new issue