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):
|
||||
activities = []
|
||||
for setting, (content, timestamp) in self.bot.find_settings_prefix(
|
||||
ACTIVITY_SETTING_PREFIX):
|
||||
for setting, (content, timestamp) in self.bot.find_settings(
|
||||
prefix=ACTIVITY_SETTING_PREFIX):
|
||||
activity_id = setting.replace(ACTIVITY_SETTING_PREFIX, "", 1)
|
||||
activities.append([activity_id, content, timestamp])
|
||||
return activities
|
||||
|
|
|
@ -89,7 +89,7 @@ class Module(ModuleManager.BaseModule):
|
|||
def relay_group(self, event):
|
||||
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 = {}
|
||||
for setting, value in group_settings:
|
||||
name = setting.replace("relay-group-", "", 1)
|
||||
|
|
|
@ -203,7 +203,7 @@ class Module(ModuleManager.BaseModule):
|
|||
alias_lower = alias.lower()
|
||||
|
||||
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
|
||||
if alias and value["comment"].lower() == alias_lower:
|
||||
alias = value["comment"]
|
||||
|
|
|
@ -64,7 +64,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
def _open_votes(self, channel):
|
||||
open = []
|
||||
for setting, vote in channel.find_settings_prefix("vote-"):
|
||||
for setting, vote in channel.find_setting(prefix="vote-"):
|
||||
if vote["open"]:
|
||||
open.append(vote)
|
||||
return open
|
||||
|
|
|
@ -238,13 +238,15 @@ class Bot(object):
|
|||
self.database.bot_settings.set(setting, value)
|
||||
def get_setting(self, setting: str, default: typing.Any=None) -> typing.Any:
|
||||
return self.database.bot_settings.get(setting, default)
|
||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.database.bot_settings.find(pattern, default)
|
||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.database.bot_settings.find_prefix(
|
||||
prefix, default)
|
||||
def find_settings(self, pattern: str=None, prefix: str=None,
|
||||
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||
if not pattern == None:
|
||||
return self.database.bot_settings.find(pattern, default)
|
||||
elif not prefix == None:
|
||||
return self.database.bot_settings.find_prefix(prefix, default)
|
||||
else:
|
||||
raise ValueError("Please provide 'pattern' or 'prefix'")
|
||||
|
||||
def del_setting(self, setting: str):
|
||||
self.database.bot_settings.delete(setting)
|
||||
|
||||
|
|
|
@ -162,14 +162,17 @@ class Channel(IRCObject.Object):
|
|||
else:
|
||||
return value
|
||||
|
||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.bot.database.channel_settings.find(self.id, pattern,
|
||||
default)
|
||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.bot.database.channel_settings.find_prefix(self.id,
|
||||
prefix, default)
|
||||
def find_settings(self, pattern: str=None, prefix: str=None,
|
||||
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||
if not pattern == None:
|
||||
return self.bot.database.channel_settings.find(self.id, pattern,
|
||||
default)
|
||||
elif not prefix == None:
|
||||
return self.bot.database.channel_settings.find_prefix(self.id,
|
||||
prefix, default)
|
||||
else:
|
||||
raise ValueError("Please provide 'pattern' or 'prefix'")
|
||||
|
||||
def del_setting(self, setting: str):
|
||||
self.bot.database.channel_settings.delete(self.id, setting)
|
||||
|
||||
|
|
|
@ -116,14 +116,16 @@ class Server(IRCObject.Object):
|
|||
) -> typing.Any:
|
||||
return self.bot.database.server_settings.get(self.id,
|
||||
setting, default)
|
||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.bot.database.server_settings.find(self.id,
|
||||
pattern, default)
|
||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.bot.database.server_settings.find_prefix(
|
||||
self.id, prefix, default)
|
||||
def find_settings(self, pattern: str=None, prefix: str=None,
|
||||
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||
if not pattern == None:
|
||||
return self.bot.database.server_settings.find(self.id, pattern,
|
||||
default)
|
||||
elif not prefix == None:
|
||||
return self.bot.database.server_settings.find_prefix(self.id,
|
||||
prefix, default)
|
||||
else:
|
||||
raise ValueError("Please provide 'pattern' or 'prefix'")
|
||||
def del_setting(self, setting: str):
|
||||
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:
|
||||
return self.bot.database.user_settings.get(self.get_id(), setting,
|
||||
default)
|
||||
def find_settings(self, pattern: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.bot.database.user_settings.find(self.get_id(), pattern,
|
||||
default)
|
||||
def find_settings_prefix(self, prefix: str, default: typing.Any=[]
|
||||
) -> typing.List[typing.Any]:
|
||||
return self.bot.database.user_settings.find_prefix(self.get_id(),
|
||||
prefix, default)
|
||||
|
||||
def find_setting(self, pattern: str=None, prefix: str=None,
|
||||
default: typing.Any=[]) -> typing.List[typing.Any]:
|
||||
if not pattern == None:
|
||||
return self.bot.database.user_settings.find(self.get_id(), pattern,
|
||||
default)
|
||||
elif not prefix == None:
|
||||
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):
|
||||
self.bot.database.user_settings.delete(self.get_id(), setting)
|
||||
def get_channel_settings_per_setting(self, setting: str,
|
||||
|
|
Loading…
Reference in a new issue