Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

Commit

Permalink
Add a 'maybe' option to indicate event attendance
Browse files Browse the repository at this point in the history
  • Loading branch information
melange396 authored and jgayfer committed May 27, 2018
1 parent 93760fe commit 2586a69
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
24 changes: 24 additions & 0 deletions cogs/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ async def list_events(self, guild):
msg = await events_channel.send(embed=event_embed)
await msg.add_reaction("\N{WHITE HEAVY CHECK MARK}")
await msg.add_reaction("\N{CROSS MARK}")
await msg.add_reaction("\N{WHITE QUESTION MARK ORNAMENT}")
else:
await events_channel.send("There are no upcoming events.")


async def on_raw_reaction_add(self, payload):
"""If a reaction represents a user RSVP, update the DB and event message"""
channel = self.bot.get_channel(payload.channel_id)

if isinstance(channel, discord.abc.PrivateChannel):
return
try:
Expand All @@ -167,6 +169,8 @@ async def on_raw_reaction_add(self, payload):
await self.set_attendance(member, guild, 1, title, message)
elif payload.emoji.name == "\N{CROSS MARK}":
await self.set_attendance(member, guild, 0, title, message)
elif payload.emoji.name == "\N{WHITE QUESTION MARK ORNAMENT}":
await self.set_attendance(member, guild, 2, title, message)
elif payload.emoji.name == "\N{SKULL}":
deleted = await self.delete_event(guild, title, member, channel)

Expand Down Expand Up @@ -233,6 +237,7 @@ def create_event_embed(self, guild, event):
creator_id = event.get('user_id')
accepted = event.get('accepted')
declined = event.get('declined')
maybe = event.get('maybe')
max_members = event.get('max_members')

embed_msg = discord.Embed(color=constants.BLUE)
Expand Down Expand Up @@ -260,6 +265,8 @@ def create_event_embed(self, guild, event):
member = guild.get_member(int(user_id))
if member:
text += "{}\n".format(member.display_name)
if not text:
text = '-'
if max_members:
embed_msg.add_field(name="Accepted ({}/{})".format(len(accepted_list), max_members), value=text)
else:
Expand All @@ -277,10 +284,25 @@ def create_event_embed(self, guild, event):
member = guild.get_member(int(user_id))
if member:
text += "{}\n".format(member.display_name)
if not text:
text = '-'
embed_msg.add_field(name="Declined", value=text)
else:
embed_msg.add_field(name="Declined", value="-")

if maybe:
maybe_list = maybe.split(',')
text = ""
for user_id in maybe_list:
member = guild.get_member(int(user_id))
if member:
text += "{}\n".format(member.display_name)
if not text:
text = '-'
embed_msg.add_field(name="Maybe", value=text)
else:
embed_msg.add_field(name="Maybe", value="-")

if accepted and max_members:
standby_list = accepted.split(',')[max_members:]
if standby_list:
Expand All @@ -289,6 +311,8 @@ def create_event_embed(self, guild, event):
member = guild.get_member(int(user_id))
if member:
text += "{}\n".format(member.display_name)
if not text:
text = '-'
embed_msg.add_field(name="Standby", value=text, inline=False)

return embed_msg
20 changes: 16 additions & 4 deletions db/dbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,19 @@ def get_event(self, guild_id, title):
WHERE user_event.guild_id = %s
AND user_event.title = %s
AND user_event.attending = 0)
AS declined,
AS declined, (
SELECT GROUP_CONCAT(DISTINCT user_id ORDER BY last_updated)
FROM user_event
WHERE user_event.guild_id = %s
AND user_event.title = %s
AND user_event.attending = 2)
AS maybe,
max_members
FROM events
WHERE guild_id = %s
AND title = %s;
"""
cursor.execute(sql, (guild_id, title, guild_id, title, guild_id, title))
cursor.execute(sql, (guild_id, title, guild_id, title, guild_id, title, guild_id, title))
result = cursor.fetchone()
return result

Expand Down Expand Up @@ -200,14 +206,20 @@ def get_events(self, guild_id):
WHERE user_event.guild_id = %s
AND user_event.title = event_title
AND user_event.attending = 0)
AS declined,
AS declined, (
SELECT GROUP_CONCAT(DISTINCT user_id ORDER BY last_updated)
FROM user_event
WHERE user_event.guild_id = %s
AND user_event.title = event_title
AND user_event.attending = 2)
AS maybe,
max_members
FROM events
WHERE events.guild_id = %s
GROUP BY title, description, start_time, timezone
ORDER BY start_time DESC;
"""
cursor.execute(sql, (guild_id, guild_id, guild_id))
cursor.execute(sql, (guild_id, guild_id, guild_id, guild_id))
result = cursor.fetchall()
return result

Expand Down
1 change: 1 addition & 0 deletions db/migrations/0001_tenative_attendance.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE user_event MODIFY attending INT NOT NULL;
2 changes: 1 addition & 1 deletion db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CREATE TABLE user_event (
user_id BIGINT NOT NULL,
guild_id BIGINT NOT NULL,
title VARCHAR(256) NOT NULL,
attending BOOLEAN NOT NULL,
attending INT NOT NULL,
last_updated DATETIME NOT NULL,
PRIMARY KEY (user_id, guild_id, title),
FOREIGN KEY (guild_id, title) REFERENCES events(guild_id, title)
Expand Down

0 comments on commit 2586a69

Please sign in to comment.