Add Database.UserChannelSettings.find_all_by_setting

This commit is contained in:
jesopo 2018-08-31 15:13:56 +01:00
parent a3f48c0844
commit 8a80d8e67d
2 changed files with 19 additions and 4 deletions

View file

@ -207,13 +207,25 @@ class UserChannelSettings(Table):
def find_prefix(self, user_id, channel_id, prefix, default=[]):
return self.find_user_settings(user_id, channel_id, "%s%" % prefix,
default)
def find_by_setting(self, server_id, user_id, setting, default=[]):
def find_by_setting(self, user_id, setting, default=[]):
values = self.database.execute_fetchall(
"""SELECT channels.name, user_channel_settings.value FROM
user_channel_settings INNER JOIN channels ON
user_channel_settings.channel_id=channels.channel_id
WHERE channels.server_id=? AND
user_channel_settings.user_id=?""", [server_id, user_id])
WHERE user_channel_settings.setting=?
AND user_channel_settings.user_id=?""", [setting, user_id])
if values:
for i, value in enumerate(values):
values[i] = value[0], json.loads(value[1])
return values
return default
def find_all_by_setting(self, channel_id, setting, default=[]):
values = self.database.execute_fetchall(
"""SELECT users.name, user_channel_settings.value FROM
user_channel_settings INNER JOIN users ON
user_channel_settings.user_id=users.user_id
WHERE user_channel_setting.setting=?
AND user_channel_settings.channel_id=?""", [setting, channel_id])
if values:
for i, value in enumerate(values):
values[i] = value[0], json.loads(value[1])

View file

@ -99,6 +99,9 @@ class Channel(object):
def del_user_setting(self, user_id, setting):
self.bot.database.user_channel_settings.delete(user_id, self.id,
setting)
def find_all_by_setting(self, setting, default=[]):
return self.bot.database.user_channel_settings.find_all_by_setting(
self.id, setting, default)
def send_message(self, text, prefix=None):
self.server.send_message(self.name, text, prefix=prefix)