diff --git a/.gitignore b/.gitignore index 478a0d6..43fa7f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ venv/ -__pycache__/ \ No newline at end of file +__pycache__/ +run.sh \ No newline at end of file diff --git a/config.py b/config.py index e569361..225c318 100644 --- a/config.py +++ b/config.py @@ -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``` """ \ No newline at end of file diff --git a/main.py b/main.py index 9303314..04b3b9b 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/nemo.py b/nemo.py index e023e57..0793280 100644 --- a/nemo.py +++ b/nemo.py @@ -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))