Add cooldown for Löh
This commit is contained in:
16
bot.py
16
bot.py
@@ -3,6 +3,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
@@ -40,8 +41,10 @@ SIP_ID = 327126546970312739
|
|||||||
|
|
||||||
config: dict = {
|
config: dict = {
|
||||||
'loeh-timeout': 10,
|
'loeh-timeout': 10,
|
||||||
|
'loeh-cooldown': 20,
|
||||||
'prefix': 'och!'
|
'prefix': 'och!'
|
||||||
}
|
}
|
||||||
|
last_loeh = 0
|
||||||
|
|
||||||
|
|
||||||
def load_config() -> dict:
|
def load_config() -> dict:
|
||||||
@@ -76,11 +79,19 @@ async def on_ready():
|
|||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_message(message: discord.Message):
|
async def on_message(message: discord.Message):
|
||||||
|
global last_loeh, config
|
||||||
if not message.author.bot:
|
if not message.author.bot:
|
||||||
if LOEH_REGEX.match(message.content):
|
if 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:
|
||||||
|
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)
|
loeh = await get_loeh(message.guild)
|
||||||
if loeh is None:
|
if loeh is None:
|
||||||
await message.channel.send('404: Löh not found!')
|
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':
|
elif cmd == 'list':
|
||||||
await ctx.send('Available config options:\n'
|
await ctx.send('Available config options:\n'
|
||||||
' - `prefix`: Set the bot prefix\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':
|
elif cmd == 'get':
|
||||||
if key in config:
|
if key in config:
|
||||||
await ctx.send('`' + key + '` is set to ' + str(config.get(key)))
|
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
|
config['prefix'] = val
|
||||||
elif key == 'loeh-timeout':
|
elif key == 'loeh-timeout':
|
||||||
config['loeh-timeout'] = int(val)
|
config['loeh-timeout'] = int(val)
|
||||||
|
elif key == 'loeh-cooldown':
|
||||||
|
config['loeh-cooldown'] = int(val)
|
||||||
save_config()
|
save_config()
|
||||||
await ctx.send('Config successfully updated')
|
await ctx.send('Config successfully updated')
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
|
|||||||
Reference in New Issue
Block a user