diff --git a/disco/bot/bot.py b/disco/bot/bot.py index 3fe129a..554db0c 100644 --- a/disco/bot/bot.py +++ b/disco/bot/bot.py @@ -283,7 +283,7 @@ class Bot(LoggingClass): else: self.command_matches_re = None - def get_commands_for_message(self, require_mention, mention_rules, msg_prefix, msg, prefixes=[]): + def get_commands_for_message(self, require_mention, mention_rules, msg_prefix, msg, prefixes=None): """ Generator of all commands that a given message object triggers, based on the bots plugins and configuration. @@ -298,7 +298,7 @@ class Bot(LoggingClass): msg_prefix : str The prefix to check the message starts with. msg : :class:`disco.types.message.Message` - The newly created or updated message object to parse/handle. + The message object to parse and find matching commands for. prefixes : list[string] A list of prefixes to check the message starts with (combines with `prefix`) @@ -411,7 +411,10 @@ class Bot(LoggingClass): bool Whether any commands where successfully triggered by the message. """ - custom_message_prefixes = self.config.commands_prefix_getter(msg) if self.config.commands_prefix_getter else [] + if not self.config.commands_require_mention and self.config.commands_prefix_getter: + custom_message_prefixes = self.config.commands_prefix_getter(msg) + else: + custom_message_prefixes = [] commands = list(self.get_commands_for_message( self.config.commands_require_mention, diff --git a/disco/util/config.py b/disco/util/config.py index 30d2996..5d8d279 100644 --- a/disco/util/config.py +++ b/disco/util/config.py @@ -1,5 +1,6 @@ import os import six +import copy from .serializer import Serializer @@ -7,7 +8,7 @@ from .serializer import Serializer class Config(object): def __init__(self, obj=None): self.__dict__.update({ - k: getattr(self, k) for k in dir(self.__class__) + k: copy.deepcopy(getattr(self, k)) for k in dir(self.__class__) }) if obj: diff --git a/disco/util/runner.py b/disco/util/runner.py index c12a95d..4337c7e 100644 --- a/disco/util/runner.py +++ b/disco/util/runner.py @@ -11,7 +11,7 @@ from disco.bot import Bot, BotConfig # noqa: E402 from disco.util.logging import setup_logging # noqa: E402 -def bot_creator(config: dict = {}, bot: bool = True, autosharded: bool = False, **kwargs): # noqa: E999 +def bot_creator(config: dict = None, bot: bool = True, autosharded: bool = False, **kwargs): # noqa: E999 """ Create a bot object and return it to be run without the cli. @@ -34,7 +34,7 @@ def bot_creator(config: dict = {}, bot: bool = True, autosharded: bool = False, config.update(kwargs) # Change the dictionary configuration to disco's proprietary Config - config = ClientConfig(config) + config = ClientConfig(config or {}) # Magical auto-sharding that you will eventually want if autosharded: