mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-20 02:26:32 +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")
|
@commands.slash_command(name="block")
|
||||||
@owner_or_admin()
|
@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."""
|
"""Blocks a user from using the bot."""
|
||||||
await ctx.defer()
|
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:
|
try:
|
||||||
hour, minute = map(int, until.split(":"))
|
hour, minute = map(int, until.split(":"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return await ctx.respond("\N{cross mark} Invalid time format. Use HH:MM.")
|
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.
|
# 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)
|
entry = await get_or_none(JimmyBans, user_id=user.id)
|
||||||
|
|
Loading…
Reference in a new issue