mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Allow passing a datetime to /block
This commit is contained in:
parent
4e7648eef9
commit
f18a06bd5d
1 changed files with 19 additions and 2 deletions
21
cogs/mod.py
21
cogs/mod.py
|
@ -55,14 +55,31 @@ class Mod(commands.Cog):
|
|||
|
||||
@commands.slash_command(name="block")
|
||||
@owner_or_admin()
|
||||
async def block_user(self, ctx: discord.ApplicationContext, user: discord.Member, reason: str, *, until: str):
|
||||
async def block_user(
|
||||
self,
|
||||
ctx: discord.ApplicationContext,
|
||||
user: discord.Member,
|
||||
reason: str,
|
||||
until: str
|
||||
):
|
||||
"""Blocks a user from using the bot."""
|
||||
await ctx.defer()
|
||||
date = datetime.utcnow()
|
||||
_time = until
|
||||
try:
|
||||
date, _time = until.split(" ")
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
date = datetime.strptime(date, "%d/%m/%Y")
|
||||
except ValueError:
|
||||
return await ctx.respond("Invalid date format. Use `DD/MM/YYYY`.")
|
||||
try:
|
||||
hour, minute = map(int, until.split(":"))
|
||||
except ValueError:
|
||||
return await ctx.respond("\N{cross mark} Invalid time format. Use HH:MM.")
|
||||
end = datetime.utcnow().replace(hour=hour, minute=minute)
|
||||
end = date.replace(hour=hour, minute=minute)
|
||||
|
||||
# get an entry for the user's ID, and if it doesn't exist, create it. Otherwise, alert the user.
|
||||
entry = await get_or_none(JimmyBans, user_id=user.id)
|
||||
|
|
Loading…
Reference in a new issue