Actually, we do need find_all_by_setting
This commit is contained in:
parent
303cf85ac6
commit
525de94c02
3 changed files with 19 additions and 2 deletions
14
Database.py
14
Database.py
|
@ -219,6 +219,20 @@ class UserChannelSettings(Table):
|
||||||
values[i] = value[0], json.loads(value[1])
|
values[i] = value[0], json.loads(value[1])
|
||||||
return values
|
return values
|
||||||
return default
|
return default
|
||||||
|
def find_all_by_setting(self, server_id, setting, default=[]):
|
||||||
|
values = self.database.execute_fetchall(
|
||||||
|
"""SELECT channels.name, users.nickname,
|
||||||
|
user_channel_settings.value FROM
|
||||||
|
user_channel_settings INNER JOIN channels ON
|
||||||
|
user_channel_settings.channel_id=channels.channel_id
|
||||||
|
INNER JOIN users on user_channel_setting.user_id=users.user_id
|
||||||
|
WHERE user_channel_settings.setting=? AND
|
||||||
|
users.server_id=?""", [setting, server_id])
|
||||||
|
if values:
|
||||||
|
for i, value in enumerate(values):
|
||||||
|
values[i] = value[0], value[1], json.loads(value[2])
|
||||||
|
return values
|
||||||
|
return default
|
||||||
def delete(self, user_id, channel_id, setting):
|
def delete(self, user_id, channel_id, setting):
|
||||||
self.database.execute(
|
self.database.execute(
|
||||||
"""DELETE FROM user_channel_settings WHERE
|
"""DELETE FROM user_channel_settings WHERE
|
||||||
|
|
|
@ -112,9 +112,12 @@ class Server(object):
|
||||||
self.id, prefix, default)
|
self.id, prefix, default)
|
||||||
def del_setting(self, setting):
|
def del_setting(self, setting):
|
||||||
self.bot.database.server_settings.delete(self.id, setting)
|
self.bot.database.server_settings.delete(self.id, setting)
|
||||||
def get_all_user_settings(self, setting, default):
|
def get_all_user_settings(self, setting, default=[]):
|
||||||
return self.bot.database.user_settings.find_all_by_setting(
|
return self.bot.database.user_settings.find_all_by_setting(
|
||||||
self.id, setting, default)
|
self.id, setting, default)
|
||||||
|
def find_all_user_channel_settings(self, setting, default=[]):
|
||||||
|
return self.bot.database.user_channel_settings.find_all_by_setting(
|
||||||
|
self.id, setting, default)
|
||||||
|
|
||||||
def set_own_nickname(self, nickname):
|
def set_own_nickname(self, nickname):
|
||||||
self.nickname = nickname
|
self.nickname = nickname
|
||||||
|
|
|
@ -39,7 +39,7 @@ class User(object):
|
||||||
self.bot.database.user_settings.delete(self.id, setting)
|
self.bot.database.user_settings.delete(self.id, setting)
|
||||||
def get_channel_settings_per_setting(self, setting, default=[]):
|
def get_channel_settings_per_setting(self, setting, default=[]):
|
||||||
return self.bot.database.user_channel_settings.find_by_setting(
|
return self.bot.database.user_channel_settings.find_by_setting(
|
||||||
self.server.id, self.id, setting, default)
|
self.id, 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)
|
||||||
|
|
Loading…
Reference in a new issue