From faa0d08df2b233e41a255c28a24f1331aed360b6 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Tue, 8 Dec 2020 11:51:19 +0100 Subject: [PATCH] =?UTF-8?q?Add=20cooldown=20for=20L=C3=B6h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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):