Finishing the event creation

This commit is contained in:
Anonymus Raccoon
2020-07-14 17:25:18 +02:00
parent 7b6dbbfe3c
commit 6f6e41c67f
4 changed files with 19 additions and 8 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.idea/
venv/
__pycache__/
run.sh

View File

@@ -58,5 +58,5 @@ SETUP_MSG = """**Pour finaliser la création de l'event, faite l'une des command
Ouvrir l'event a tous le monde:
```!open [message]```
Faire un event privé et inviter les personnes individuellement:
```!private```");
```!private```
"""

View File

@@ -40,12 +40,12 @@ async def help_msg(channel: discord.TextChannel):
@nemo.reaction(lambda reaction, member: reaction.message.author.bot and config.CREATE_KEY in reaction.message.content)
async def create_event(reaction: discord.Reaction, message: discord.Message, member: discord.Member, guild: discord.Guild, **_):
list_msg: discord.Message = next(x async for x in message.channel.history() if config.LIST_KEY in x.content)
list_msg: discord.Message = [x async for x in message.channel.history() if config.LIST_KEY in x.content][0]
index = get_new_event_index(list_msg)
await edit_event_status(index, config.CONFIGURING_EVENT, list_msg)
await edit_event_status(index, config.CONFIGURING_EVENT.replace("@User", f"<@{member.id}>"), list_msg)
await reaction.remove(member)
org_role = await guild.create_role(name=f"{config.ORGANIZER_PREFIX}{index}", color=discord.Color.purple)
org_role = await guild.create_role(name=f"{config.ORGANIZER_PREFIX}{index}", color=discord.Color.purple())
await member.add_roles(org_role)
user_role = await guild.create_role(name=f"{config.PARTICIPANT_PREFIX}{index}")
await member.add_roles(user_role)
@@ -54,7 +54,7 @@ async def create_event(reaction: discord.Reaction, message: discord.Message, mem
guild.me: discord.PermissionOverwrite(read_messages=True),
org_role: discord.PermissionOverwrite(read_messages=True, manage_messages=True),
user_role: discord.PermissionOverwrite(read_messages=True)
}, category=next(x.name == config.CATEGORY_NAME and x.type == discord.ChannelType.category for x in guild.channels))
}, category=message.channel.category)
await list_msg.add_reaction(number_emojis[index - 1])
await channel.send(config.SETUP_MSG)

12
nemo.py
View File

@@ -39,11 +39,21 @@ class Nemo(discord.Client):
if handler is None:
return
try:
await handler[1](reaction=reaction, member=member, message=reaction.message)
await handler[1](reaction=reaction, member=member, message=reaction.message, guild=reaction.message.guild)
except Exception:
await reaction.message.channel.send(f"Fatal error: {traceback.format_exc()}")
raise
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
if payload.event_type != "REACTION_ADD":
return
channel: discord.TextChannel = self.get_channel(payload.channel_id)
message: discord.Message = await channel.fetch_message(payload.message_id)
key = f"{payload.emoji.name}:{payload.emoji.id}" if payload.emoji.id else payload.emoji.name
reaction = discord.utils.get(message.reactions, emoji=key)
await self.on_reaction_add(reaction, payload.member)
def reaction(self, predicate: Callable[[discord.Reaction, discord.Member], bool]):
def wrapper(f):
self.reactions.append((predicate, f))