Make last och time guild specific

This commit is contained in:
2021-01-19 11:34:46 +01:00
parent 55e258513b
commit 94597b45ad
2 changed files with 23 additions and 8 deletions

23
bot.py
View File

@@ -10,7 +10,8 @@ import gtts
from discord.ext import commands
from dotenv import load_dotenv
from lib.config import config, config_meta, config_load, config_save, config_get, config_set, config_get_descriptions
from lib.config import config, config_meta, config_load, config_save, config_get, config_set, config_get_descriptions, \
config_set_raw
from lib.utils import async_filter
load_dotenv()
@@ -44,8 +45,6 @@ OWNER_ID = 327126546970312739
OCH_LOEH_SOUND = "assets/och_loeh.mp3"
last_och = 0
config_load()
bot = commands.Bot(command_prefix=config.get('prefix'))
@@ -60,6 +59,14 @@ async def _get_loeh(guild: discord.Guild) -> Optional[discord.Member]:
return None
def _get_last_och_time(guild: discord.Guild) -> int:
return config_get('last-och-time', guild.id)
def _set_last_och_time(guild: discord.Guild):
config_set_raw('last-och-time', time.time(), guild.id)
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@@ -67,17 +74,17 @@ async def on_ready():
@bot.event
async def on_message(message: discord.Message):
global last_och
if message.guild is not None and not message.author.bot:
if config_get('loeh-enable', message.guild.id) and 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_get('och-cooldown', message.guild.id) <= last_och:
if t - config_get('och-cooldown', message.guild.id) <= _get_last_och_time(message.guild):
await message.channel.send('429: Too many requests')
return
last_och = t
_set_last_och_time(message.guild)
loeh = await _get_loeh(message.guild)
if loeh is None:
await message.channel.send('404: Löh not found!')
@@ -107,10 +114,10 @@ async def on_message(message: discord.Message):
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) <= last_och:
if t - config_get('och-cooldown', message.guild.id) <= _get_last_och_time():
await message.channel.send('429: Too many requests')
return
last_och = t
_set_last_och_time()
guild: discord.Guild = message.guild
bot_member: discord.Member = guild.get_member(bot.user.id)