From 7046e084d2a15ac8b64cb35d6dbeb979383e636d Mon Sep 17 00:00:00 2001 From: Siphalor Date: Wed, 27 Jan 2021 15:32:12 +0100 Subject: [PATCH] Add remaining seconds of cooldown to cooldown message --- bot.py | 12 ++++++------ lib/config.py | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bot.py b/bot.py index 977e685..c69ce1c 100644 --- a/bot.py +++ b/bot.py @@ -81,9 +81,9 @@ async def on_message(message: discord.Message): if message.author.id == LOEH_ID: await message.channel.send("https://siphalor.de/img/spidy-is-that-you.jpg") else: - t = time.time() - if t - config_get('och-cooldown', message.guild.id) <= _get_last_och_time(message.guild): - await message.channel.send('429: Too many requests') + t = time.time() - config_get('och-cooldown', message.guild.id) + if t <= _get_last_och_time(message.guild): + await message.channel.send('429: Too many requests - Wait ' + str(t) + ' more seconds!') return _set_last_och_time(message.guild) @@ -115,9 +115,9 @@ async def on_message(message: discord.Message): return elif config_get('och-anyone-enable', message.guild.id) and ( match := OCH_ANYONE_REGEX.search(message.content)) is not None: - t = time.time() - if t - config_get('och-cooldown', message.guild.id) <= _get_last_och_time(message.guild): - await message.channel.send('429: Too many requests') + t = time.time() - config_get('och-cooldown', message.guild.id) + if t <= _get_last_och_time(message.guild): + await message.channel.send('429: Too many requests - Wait ' + str(t) + ' more seconds!') return _set_last_och_time(message.guild) diff --git a/lib/config.py b/lib/config.py index c8f0dd6..f4dd0a5 100644 --- a/lib/config.py +++ b/lib/config.py @@ -1,6 +1,6 @@ import json import os -from typing import Optional +from typing import Optional, Any CONFIG = 'data/config.json' config: dict = { @@ -60,13 +60,15 @@ def config_save(): json.dump(config, config_file) -def config_get(key: str, guild: Optional[int] = None): +def config_get(key: str, guild: Optional[int] = None) -> Optional[Any]: if guild is None: return config[key] guild = _get_guild_config(guild) if key in guild: return guild[key] - return config[key] + if key in config: + return config[key] + return None def config_set(key: str, value, guild: Optional[int] = None) -> str: