combine find_setting() and find_setting_prefix() on user/channel/server/bot
This commit is contained in:
parent
9ab817ca58
commit
50d1eb6b8c
8 changed files with 47 additions and 36 deletions
|
@ -46,8 +46,8 @@ class Server(object):
|
||||||
|
|
||||||
def _get_activities(self):
|
def _get_activities(self):
|
||||||
activities = []
|
activities = []
|
||||||
for setting, (content, timestamp) in self.bot.find_settings_prefix(
|
for setting, (content, timestamp) in self.bot.find_settings(
|
||||||
ACTIVITY_SETTING_PREFIX):
|
prefix=ACTIVITY_SETTING_PREFIX):
|
||||||
activity_id = setting.replace(ACTIVITY_SETTING_PREFIX, "", 1)
|
activity_id = setting.replace(ACTIVITY_SETTING_PREFIX, "", 1)
|
||||||
activities.append([activity_id, content, timestamp])
|
activities.append([activity_id, content, timestamp])
|
||||||
return activities
|
return activities
|
||||||
|
|
|
@ -89,7 +89,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
def relay_group(self, event):
|
def relay_group(self, event):
|
||||||
subcommand = event["args_split"][0].lower()
|
subcommand = event["args_split"][0].lower()
|
||||||
|
|
||||||
group_settings = self.bot.find_settings_prefix("relay-group-")
|
group_settings = self.bot.find_settings(prefix="relay-group-")
|
||||||
groups = {}
|
groups = {}
|
||||||
for setting, value in group_settings:
|
for setting, value in group_settings:
|
||||||
name = setting.replace("relay-group-", "", 1)
|
name = setting.replace("relay-group-", "", 1)
|
||||||
|
|
|
@ -203,7 +203,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
alias_lower = alias.lower()
|
alias_lower = alias.lower()
|
||||||
|
|
||||||
api_keys = {}
|
api_keys = {}
|
||||||
for key, value in self.bot.find_settings_prefix("api-key-"):
|
for key, value in self.bot.find_settings(prefix="api-key-"):
|
||||||
api_keys[key] = value
|
api_keys[key] = value
|
||||||
if alias and value["comment"].lower() == alias_lower:
|
if alias and value["comment"].lower() == alias_lower:
|
||||||
alias = value["comment"]
|
alias = value["comment"]
|
||||||
|
|
|
@ -64,7 +64,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
def _open_votes(self, channel):
|
def _open_votes(self, channel):
|
||||||
open = []
|
open = []
|
||||||
for setting, vote in channel.find_settings_prefix("vote-"):
|
for setting, vote in channel.find_setting(prefix="vote-"):
|
||||||
if vote["open"]:
|
if vote["open"]:
|
||||||
open.append(vote)
|
open.append(vote)
|
||||||
return open
|
return open
|
||||||
|
|
|
@ -238,13 +238,15 @@ class Bot(object):
|
||||||
self.database.bot_settings.set(setting, value)
|
self.database.bot_settings.set(setting, value)
|
||||||
def get_setting(self, setting: str, default: typing.Any=None) -> typing.Any:
|
def get_setting(self, setting: str, default: typing.Any=None) -> typing.Any:
|
||||||
return self.database.bot_settings.get(setting, default)
|
return self.database.bot_settings.get(setting, default)
|
||||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
def find_settings(self, pattern: str=None, prefix: str=None,
|
||||||
) -> typing.List[typing.Any]:
|
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||||
return self.database.bot_settings.find(pattern, default)
|
if not pattern == None:
|
||||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
return self.database.bot_settings.find(pattern, default)
|
||||||
) -> typing.List[typing.Any]:
|
elif not prefix == None:
|
||||||
return self.database.bot_settings.find_prefix(
|
return self.database.bot_settings.find_prefix(prefix, default)
|
||||||
prefix, default)
|
else:
|
||||||
|
raise ValueError("Please provide 'pattern' or 'prefix'")
|
||||||
|
|
||||||
def del_setting(self, setting: str):
|
def del_setting(self, setting: str):
|
||||||
self.database.bot_settings.delete(setting)
|
self.database.bot_settings.delete(setting)
|
||||||
|
|
||||||
|
|
|
@ -162,14 +162,17 @@ class Channel(IRCObject.Object):
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
def find_settings(self, pattern: str=None, prefix: str=None,
|
||||||
) -> typing.List[typing.Any]:
|
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||||
return self.bot.database.channel_settings.find(self.id, pattern,
|
if not pattern == None:
|
||||||
default)
|
return self.bot.database.channel_settings.find(self.id, pattern,
|
||||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
default)
|
||||||
) -> typing.List[typing.Any]:
|
elif not prefix == None:
|
||||||
return self.bot.database.channel_settings.find_prefix(self.id,
|
return self.bot.database.channel_settings.find_prefix(self.id,
|
||||||
prefix, default)
|
prefix, default)
|
||||||
|
else:
|
||||||
|
raise ValueError("Please provide 'pattern' or 'prefix'")
|
||||||
|
|
||||||
def del_setting(self, setting: str):
|
def del_setting(self, setting: str):
|
||||||
self.bot.database.channel_settings.delete(self.id, setting)
|
self.bot.database.channel_settings.delete(self.id, setting)
|
||||||
|
|
||||||
|
|
|
@ -116,14 +116,16 @@ class Server(IRCObject.Object):
|
||||||
) -> typing.Any:
|
) -> typing.Any:
|
||||||
return self.bot.database.server_settings.get(self.id,
|
return self.bot.database.server_settings.get(self.id,
|
||||||
setting, default)
|
setting, default)
|
||||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
def find_settings(self, pattern: str=None, prefix: str=None,
|
||||||
) -> typing.List[typing.Any]:
|
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||||
return self.bot.database.server_settings.find(self.id,
|
if not pattern == None:
|
||||||
pattern, default)
|
return self.bot.database.server_settings.find(self.id, pattern,
|
||||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
default)
|
||||||
) -> typing.List[typing.Any]:
|
elif not prefix == None:
|
||||||
return self.bot.database.server_settings.find_prefix(
|
return self.bot.database.server_settings.find_prefix(self.id,
|
||||||
self.id, prefix, default)
|
prefix, default)
|
||||||
|
else:
|
||||||
|
raise ValueError("Please provide 'pattern' or 'prefix'")
|
||||||
def del_setting(self, setting: str):
|
def del_setting(self, setting: str):
|
||||||
self.bot.database.server_settings.delete(self.id, setting)
|
self.bot.database.server_settings.delete(self.id, setting)
|
||||||
|
|
||||||
|
|
|
@ -57,14 +57,18 @@ class User(IRCObject.Object):
|
||||||
def get_setting(self, setting: str, default: typing.Any=None) -> typing.Any:
|
def get_setting(self, setting: str, default: typing.Any=None) -> typing.Any:
|
||||||
return self.bot.database.user_settings.get(self.get_id(), setting,
|
return self.bot.database.user_settings.get(self.get_id(), setting,
|
||||||
default)
|
default)
|
||||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
|
||||||
) -> typing.List[typing.Any]:
|
def find_setting(self, pattern: str=None, prefix: str=None,
|
||||||
return self.bot.database.user_settings.find(self.get_id(), pattern,
|
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||||
default)
|
if not pattern == None:
|
||||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
return self.bot.database.user_settings.find(self.get_id(), pattern,
|
||||||
) -> typing.List[typing.Any]:
|
default)
|
||||||
return self.bot.database.user_settings.find_prefix(self.get_id(),
|
elif not prefix == None:
|
||||||
prefix, default)
|
return self.bot.database.user_settings.find_prefix(self.get_id(),
|
||||||
|
prefix, default)
|
||||||
|
else:
|
||||||
|
raise ValueError("Please provide 'pattern' or 'prefix'")
|
||||||
|
|
||||||
def del_setting(self, setting):
|
def del_setting(self, setting):
|
||||||
self.bot.database.user_settings.delete(self.get_id(), setting)
|
self.bot.database.user_settings.delete(self.get_id(), setting)
|
||||||
def get_channel_settings_per_setting(self, setting: str,
|
def get_channel_settings_per_setting(self, setting: str,
|
||||||
|
|
Loading…
Reference in a new issue