Fix a bunch of config issues
This commit is contained in:
4
bot.py
4
bot.py
@@ -61,7 +61,7 @@ async def on_ready():
|
|||||||
async def on_message(message: discord.Message):
|
async def on_message(message: discord.Message):
|
||||||
global last_loeh
|
global last_loeh
|
||||||
if message.guild is not None and not message.author.bot:
|
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:
|
if message.author.id == LOEH_ID:
|
||||||
await message.channel.send("https://siphalor.de/img/spidy-is-that-you.jpg")
|
await message.channel.send("https://siphalor.de/img/spidy-is-that-you.jpg")
|
||||||
else:
|
else:
|
||||||
@@ -88,7 +88,7 @@ async def on_message(message: discord.Message):
|
|||||||
except (discord.Forbidden, discord.HTTPException):
|
except (discord.Forbidden, discord.HTTPException):
|
||||||
await message.channel.send('Failed to complete your command, Sir')
|
await message.channel.send('Failed to complete your command, Sir')
|
||||||
return
|
return
|
||||||
elif config_get('inf19x-insiders-enable'):
|
elif config_get('inf19x-insiders-enable', message.guild.id):
|
||||||
if PING_REGEX.search(message.content):
|
if PING_REGEX.search(message.content):
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="*pinken, schwaches Verb*",
|
title="*pinken, schwaches Verb*",
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ def config_save():
|
|||||||
|
|
||||||
|
|
||||||
def config_get(key: str, guild: Optional[int] = None):
|
def config_get(key: str, guild: Optional[int] = None):
|
||||||
guild = str(guild)
|
if guild is None:
|
||||||
if guild in config:
|
return config[key]
|
||||||
guild = config[guild]
|
guild = _get_guild_config(guild)
|
||||||
if key in guild:
|
if key in guild:
|
||||||
return guild[key]
|
return guild[key]
|
||||||
return config[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]))
|
return _config_set_in_scope(config, key, value, type(config[key]))
|
||||||
else:
|
else:
|
||||||
if config_meta[key][0]:
|
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:
|
else:
|
||||||
return 'This config can only be changed globally by the bot owner!'
|
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())
|
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:
|
def _config_set_in_scope(scope: dict, key: str, value, cfg_type: type) -> str:
|
||||||
success = False
|
success = False
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user