Creating the stop function

This commit is contained in:
Anonymus Raccoon
2020-07-14 21:09:44 +02:00
parent 6f6e41c67f
commit ce0df405c1
4 changed files with 66 additions and 2 deletions
+35
View File
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
import asyncio
import nemo
import helper
import config
@@ -77,5 +79,38 @@ async def edit_event_status(index: int, text: str, list_msg: discord.Message):
await list_msg.edit(content="\n".join(content))
@nemo.command("!close")
@nemo.command("!stop")
@helper.event_command
@helper.organizer_only
@helper.auto_delete
async def stop(*,
channel: discord.TextChannel,
member: discord.Member,
message: discord.Message,
guild: discord.Guild,
event: int,
**_):
msg = await channel.send(config.STOP_MSG.replace("@User", f"<@{member.id}>"))
await msg.add_reaction("")
try:
await nemo.wait_for("reaction_add", timeout=60, check=lambda reaction, user: user == message.author)
except asyncio.TimeoutError:
await msg.delete()
return
await discord.utils.get(guild.roles, name=f"{config.ORGANIZER_PREFIX}{event}").delete()
await discord.utils.get(guild.roles, name=f"{config.PARTICIPANT_PREFIX}{event}").delete()
await channel.delete()
org_channel: discord.TextChannel = discord.utils.get(guild.channels, name=config.ORGANIZATION_NAME)
list_msg: discord.Message = [x async for x in org_channel.history() if config.LIST_KEY in x.content][0]
if f"**{event + 1}:**" in list_msg.content:
await edit_event_status(event, config.EMPTY_SLOT, list_msg)
elif event == 1:
await list_msg.edit(content=config.EVENT_LIST)
else:
await list_msg.edit(content='\n'.join(list_msg.content.split('\n')[:-1]))
await list_msg.clear_reaction(number_emojis[event - 1])
if __name__ == "__main__":
nemo.run(config.TOKEN)