Allowing users to join events

This commit is contained in:
Anonymus Raccoon
2020-07-14 23:42:58 +02:00
parent 0a7836b75c
commit afecb0896d
3 changed files with 37 additions and 2 deletions

View File

@@ -48,6 +48,9 @@ CREATE_KEY = "Créer un event"
CONFIGURING_EVENT = "@User configure l'event."
EVENT_CONFIGURING_KEY = "configure l'event."
PRIVATE_EVENT = "L'event est privé, vous ne pouvez pas le rejoindre."
EVENT_SUFFIX = "-event"
ORGANIZER_PREFIX = "Organisateur-"
PARTICIPANT_PREFIX = "Event-"
@@ -67,3 +70,8 @@ SET_EVENT_MSG = """@User a changé la description de l'event pour "@Status"."""
NEW_EVENT = """@everyone Nouvel event (@id)"""
NEW_EVENT_KEY = """Nouvel event ("""
EVENT_JOIN = """@User vient de rejoindre l'event.
Vous pouvez le quitter en tappant !leave.
"""

29
main.py
View File

@@ -40,8 +40,35 @@ async def help_msg(channel: discord.TextChannel):
await msg.add_reaction("")
@nemo.reaction(lambda reaction, member: reaction.message.author.bot and config.LIST_KEY in reaction.message.content)
async def join_event(*,
reaction: discord.Reaction,
member: discord.Member,
guild: discord.Guild,
channel: discord.TextChannel,
**_):
event: int = number_emojis.index(reaction.emoji) + 1
role: str = discord.utils.get(guild.roles, name=f"{config.PARTICIPANT_PREFIX}{event}")
if role is None or role in member.roles:
return
list_msg: discord.Message = [x async for x in channel.history() if config.LIST_KEY in x.content][0]
try:
status = list_msg.content.split('\n')[event + 1]
except IndexError:
return
if config.EMPTY_SLOT in status or config.EVENT_CONFIGURING_KEY in status or config.PRIVATE_EVENT in status:
return
await member.add_roles(role)
event_channel: discord.TextChannel = discord.utils.get(guild.channels, name=f"{event}{config.EVENT_SUFFIX}")
await event_channel.send(config.EVENT_JOIN.replace("@User", f"<@{member.id}>"))
@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,
async def create_event(reaction: discord.Reaction,
message: discord.Message,
member: discord.Member,
guild: discord.Guild, **_):
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)

View File

@@ -41,7 +41,7 @@ class Nemo(discord.Client):
if handler is None:
return
try:
await handler[1](reaction=reaction, member=member, message=reaction.message, guild=reaction.message.guild)
await handler[1](reaction=reaction, member=member, message=reaction.message, guild=reaction.message.guild, channel=reaction.message.channel)
except Exception:
await reaction.message.channel.send(f"Fatal error: {traceback.format_exc()}")
raise