Make last och time guild specific
This commit is contained in:
23
bot.py
23
bot.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user