Add remaining seconds of cooldown to cooldown message

This commit is contained in:
2021-01-27 15:32:12 +01:00
parent 84b0362b9f
commit 7046e084d2
2 changed files with 11 additions and 9 deletions

12
bot.py
View File

@@ -81,9 +81,9 @@ async def on_message(message: discord.Message):
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:
t = time.time() t = time.time() - config_get('och-cooldown', message.guild.id)
if t - config_get('och-cooldown', message.guild.id) <= _get_last_och_time(message.guild): if t <= _get_last_och_time(message.guild):
await message.channel.send('429: Too many requests') await message.channel.send('429: Too many requests - Wait ' + str(t) + ' more seconds!')
return return
_set_last_och_time(message.guild) _set_last_och_time(message.guild)
@@ -115,9 +115,9 @@ async def on_message(message: discord.Message):
return return
elif config_get('och-anyone-enable', message.guild.id) and ( elif config_get('och-anyone-enable', message.guild.id) and (
match := OCH_ANYONE_REGEX.search(message.content)) is not None: match := OCH_ANYONE_REGEX.search(message.content)) is not None:
t = time.time() t = time.time() - config_get('och-cooldown', message.guild.id)
if t - config_get('och-cooldown', message.guild.id) <= _get_last_och_time(message.guild): if t <= _get_last_och_time(message.guild):
await message.channel.send('429: Too many requests') await message.channel.send('429: Too many requests - Wait ' + str(t) + ' more seconds!')
return return
_set_last_och_time(message.guild) _set_last_och_time(message.guild)

View File

@@ -1,6 +1,6 @@
import json import json
import os import os
from typing import Optional from typing import Optional, Any
CONFIG = 'data/config.json' CONFIG = 'data/config.json'
config: dict = { config: dict = {
@@ -60,13 +60,15 @@ def config_save():
json.dump(config, config_file) 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: if guild is None:
return config[key] return config[key]
guild = _get_guild_config(guild) guild = _get_guild_config(guild)
if key in guild: if key in guild:
return guild[key] return guild[key]
if key in config:
return config[key] return config[key]
return None
def config_set(key: str, value, guild: Optional[int] = None) -> str: def config_set(key: str, value, guild: Optional[int] = None) -> str: