Small changes
This commit is contained in:
@@ -49,6 +49,7 @@ class PlayerLink(commands.Cog):
|
||||
def check(message: discord.Message):
|
||||
return message.channel.id == channelid and message.author.id == authorid
|
||||
|
||||
# creates the embed for the link message
|
||||
def create_embed(discord_author, minecraftname, timer, error=None, success=False):
|
||||
embed = discord.Embed(title="WorldCraft Linker")
|
||||
embed.add_field(name="How to:", value= "A code has been sent to your minecraft chat in the WorldCraft server.\nSend the code in this channel.")
|
||||
@@ -58,7 +59,7 @@ class PlayerLink(commands.Cog):
|
||||
if isinstance(error, WrongCodeError):
|
||||
embed.add_field(name="Error", value=f"The code is wrong!", inline=False)
|
||||
embed.colour = discord.Colour.red()
|
||||
elif (timer.minutes == 0 and timer.seconds == 0 and timer.ended):
|
||||
elif (timer.ended):
|
||||
embed.add_field(name="Timer", value=f"The code is expired!", inline=False)
|
||||
embed.colour = discord.Colour.red()
|
||||
elif (success == True):
|
||||
@@ -73,6 +74,8 @@ class PlayerLink(commands.Cog):
|
||||
while (not timer.ended):
|
||||
await asyncio.sleep(1)
|
||||
timer.update()
|
||||
# maybe create a task from this because this takes some time -> timer not accurate
|
||||
# asyncio.create_task(message........)
|
||||
await message.edit(embed=create_embed(ctx.author, arg, timer))
|
||||
|
||||
try:
|
||||
@@ -83,6 +86,7 @@ class PlayerLink(commands.Cog):
|
||||
# Start timer in background
|
||||
task = asyncio.create_task(update_timer(timer, message))
|
||||
|
||||
# Wait for the code response
|
||||
msg = await self.client.wait_for('message', check=check)
|
||||
|
||||
if msg.content == code:
|
||||
@@ -90,7 +94,7 @@ class PlayerLink(commands.Cog):
|
||||
timer.ended = True
|
||||
await message.edit(embed=create_embed(ctx.author, arg, timer, success=True))
|
||||
else:
|
||||
# this stops the timer loop
|
||||
# this stops the timer task
|
||||
task.cancel()
|
||||
timer.ended = True
|
||||
await message.edit(embed=create_embed(ctx.author, arg, timer, WrongCodeError()))
|
||||
|
||||
Reference in New Issue
Block a user