diff --git a/modules/fediverse/ap_server.py b/modules/fediverse/ap_server.py index d4ae9044..df592d4c 100644 --- a/modules/fediverse/ap_server.py +++ b/modules/fediverse/ap_server.py @@ -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 diff --git a/modules/relay.py b/modules/relay.py index 71a45e42..9660f571 100644 --- a/modules/relay.py +++ b/modules/relay.py @@ -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) diff --git a/modules/rest_api.py b/modules/rest_api.py index a1fb66bf..abf947e9 100644 --- a/modules/rest_api.py +++ b/modules/rest_api.py @@ -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"] diff --git a/modules/vote.py b/modules/vote.py index 060c849a..27216392 100644 --- a/modules/vote.py +++ b/modules/vote.py @@ -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 diff --git a/src/IRCBot.py b/src/IRCBot.py index 960755f5..2b81a223 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -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) diff --git a/src/IRCChannel.py b/src/IRCChannel.py index 2404d7af..0449e135 100644 --- a/src/IRCChannel.py +++ b/src/IRCChannel.py @@ -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) diff --git a/src/IRCServer.py b/src/IRCServer.py index 6faedeac..3c7a634d 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -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) diff --git a/src/IRCUser.py b/src/IRCUser.py index 8266febd..7ba334c5 100644 --- a/src/IRCUser.py +++ b/src/IRCUser.py @@ -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,