diff --git a/bot.py b/bot.py index d330651..d427de0 100644 --- a/bot.py +++ b/bot.py @@ -3,6 +3,7 @@ import json import os import random import re +import time from typing import Optional import discord @@ -40,8 +41,10 @@ SIP_ID = 327126546970312739 config: dict = { 'loeh-timeout': 10, + 'loeh-cooldown': 20, 'prefix': 'och!' } +last_loeh = 0 def load_config() -> dict: @@ -76,11 +79,19 @@ async def on_ready(): @bot.event async def on_message(message: discord.Message): + global last_loeh, config if not message.author.bot: if 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: + t = time.time() + if t - config['loeh-cooldown'] <= last_loeh: + await message.channel.send('Don\'t try this to often, **' + message.author.nick + + '**. That might backfire.') + last_loeh = t + return + last_loeh = t loeh = await get_loeh(message.guild) if loeh is None: await message.channel.send('404: Löh not found!') @@ -133,7 +144,8 @@ async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = elif cmd == 'list': await ctx.send('Available config options:\n' ' - `prefix`: Set the bot prefix\n' - ' - `loeh-timeout`: The timeout for Löh') + ' - `loeh-timeout`: The timeout for Löh in seconds' + ' - `loeh-cooldown`: Number of seconds between timeouts') elif cmd == 'get': if key in config: await ctx.send('`' + key + '` is set to ' + str(config.get(key))) @@ -145,6 +157,8 @@ async def config_prefix_command(ctx: commands.Context, cmd: str = '', key: str = config['prefix'] = val elif key == 'loeh-timeout': config['loeh-timeout'] = int(val) + elif key == 'loeh-cooldown': + config['loeh-cooldown'] = int(val) save_config() await ctx.send('Config successfully updated') except (ValueError, TypeError):