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
|
||||
def find_user_channel_settings(self, server_id, channel, nickname,
|
||||
pattern, default=[]):
|
||||
values = self.cursor().execute(
|
||||
values = self.execute_fetchall(
|
||||
"""SELECT setting, value FROM user_channel_settings WHERE
|
||||
server_id=? AND channel=? AND nickname=? AND setting LIKE '?'""",
|
||||
[server_id, channel.lower(), nickname.lower(), pattern.lower()])
|
||||
|
@ -283,6 +283,17 @@ class Database(object):
|
|||
prefix, default=[]):
|
||||
return self.find_user_settings(server_id, nickname, "%s%" % prefix,
|
||||
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):
|
||||
self.execute(
|
||||
"""DELETE FROM user_channel_settings WHERE
|
||||
|
|
|
@ -34,6 +34,9 @@ class User(object):
|
|||
def del_setting(self, setting):
|
||||
self.bot.database.del_user_setting(self.server.id, self.nickname,
|
||||
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):
|
||||
self.server.send_message(self.nickname, message, prefix=prefix)
|
||||
|
|
|
@ -22,11 +22,11 @@ class Module(object):
|
|||
words = list(filter(None, event["message_split"]))
|
||||
word_count = len(words)
|
||||
|
||||
user_words = event["user"].get_setting("words", {})
|
||||
if not event["channel"].name in user_words:
|
||||
user_words[event["channel"].name] = 0
|
||||
user_words[event["channel"].name] += word_count
|
||||
event["user"].set_setting("words", user_words)
|
||||
user_words = event["channel"].get_user_setting(
|
||||
event["user"].nickname, "words", 0)
|
||||
user_words += word_count
|
||||
event["channel"].set_user_setting(event["user"].nickname,
|
||||
"words", user_words)
|
||||
|
||||
tracked_words = set(event["server"].get_setting(
|
||||
"tracked-words", []))
|
||||
|
@ -43,8 +43,10 @@ class Module(object):
|
|||
][0])
|
||||
else:
|
||||
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)
|
||||
|
||||
total = 0
|
||||
for channel in words:
|
||||
total += words[channel]
|
||||
|
|
Loading…
Reference in a new issue