mirror of
https://github.com/zoriya/Nemo.git
synced 2026-08-16 02:44:59 +00:00
Creating the stop function
This commit is contained in:
@@ -59,4 +59,6 @@ Ouvrir l'event a tous le monde:
|
||||
```!open [message]```
|
||||
Faire un event privé et inviter les personnes individuellement:
|
||||
```!private```
|
||||
"""
|
||||
"""
|
||||
|
||||
STOP_MSG = """Pour confirmer la fermeture de l'event, cliquez sur ✅."""
|
||||
@@ -1,3 +1,7 @@
|
||||
import discord
|
||||
import config
|
||||
|
||||
|
||||
def auto_delete(f):
|
||||
async def wrapper(*args, **kwargs):
|
||||
ret = await f(*args, **kwargs)
|
||||
@@ -6,3 +10,26 @@ def auto_delete(f):
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def event_command(f):
|
||||
async def wrapper(*args, **kwargs):
|
||||
channel: discord.TextChannel = kwargs["message"].channel
|
||||
if not channel.name[:1].isdigit():
|
||||
return None
|
||||
return await f(*args, **kwargs, event=int(channel.name[:1]))
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def organizer_only(f):
|
||||
async def wrapper(*args, **kwargs):
|
||||
member: discord.Member = kwargs["member"]
|
||||
channel: discord.TextChannel = kwargs["message"].channel
|
||||
event: int = kwargs["event"]
|
||||
if "administrator" in channel.permissions_for(member):
|
||||
return await f(*args, **kwargs)
|
||||
if any(x for x in member.roles if x.name == f"{config.ORGANIZER_PREFIX}{event}"):
|
||||
return await f(*args, **kwargs)
|
||||
return None
|
||||
|
||||
return wrapper
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -20,7 +20,7 @@ class Nemo(discord.Client):
|
||||
return
|
||||
print(f"{message.author.display_name} used the command: '{cmd[0]}'")
|
||||
try:
|
||||
await f(cmd[1::], message=message, guild=message.guild)
|
||||
await f(cmd[1::], message=message, guild=message.guild, channel=message.channel)
|
||||
except Exception:
|
||||
await message.channel.send(f"Fatal error: {traceback.format_exc()}")
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user