diff --git a/bot.py b/bot.py index 3e430c9..59305df 100644 --- a/bot.py +++ b/bot.py @@ -61,7 +61,7 @@ async def on_ready(): async def on_message(message: discord.Message): global last_loeh if message.guild is not None and not message.author.bot: - if config_get('loeh-enable') and LOEH_REGEX.match(message.content): + if config_get('loeh-enable', message.guild.id) and LOEH_REGEX.match(message.content): if message.author.id == LOEH_ID: await message.channel.send("https://siphalor.de/img/spidy-is-that-you.jpg") else: @@ -88,7 +88,7 @@ async def on_message(message: discord.Message): except (discord.Forbidden, discord.HTTPException): await message.channel.send('Failed to complete your command, Sir') return - elif config_get('inf19x-insiders-enable'): + elif config_get('inf19x-insiders-enable', message.guild.id): if PING_REGEX.search(message.content): embed = discord.Embed( title="*pinken, schwaches Verb*", diff --git a/lib/config.py b/lib/config.py index 8ca0293..4d1348a 100644 --- a/lib/config.py +++ b/lib/config.py @@ -48,11 +48,11 @@ def config_save(): def config_get(key: str, guild: Optional[int] = None): - guild = str(guild) - if guild in config: - guild = config[guild] - if key in guild: - return guild[key] + if guild is None: + return config[key] + guild = _get_guild_config(guild) + if key in guild: + return guild[key] return config[key] @@ -61,7 +61,7 @@ def config_set(key: str, value, guild: Optional[int] = None) -> str: return _config_set_in_scope(config, key, value, type(config[key])) else: if config_meta[key][0]: - return _config_set_in_scope(config[str(guild)], key, value, type(config[key])) + return _config_set_in_scope(_get_guild_config(guild), key, value, type(config[key])) else: return 'This config can only be changed globally by the bot owner!' @@ -70,6 +70,12 @@ def config_get_descriptions() -> iter: return map(lambda entry: (entry[0], entry[1]), config_meta.items()) +def _get_guild_config(guild: int) -> dict: + config.setdefault('guilds', {}) + config['guilds'].setdefault(str(guild), {}) + return config['guilds'][str(guild)] + + def _config_set_in_scope(scope: dict, key: str, value, cfg_type: type) -> str: success = False try: