1
1
import asyncio
2
2
3
3
import nextcord
4
+ from discord import RawReactionActionEvent
4
5
5
6
from src .database import (
6
7
add_notification_for_date ,
9
10
)
10
11
from src .date_utils import add_localized_times_to_embed
11
12
12
- from .config import GENERAL_CHANNEL_ID , NOTES_LINK
13
+ from .config import (
14
+ GENERAL_CHANNEL_ID ,
15
+ MEETING_WATCHERS_ROLE_ID ,
16
+ NOTES_LINK ,
17
+ REACT_FOR_MEETINGS_NOTIFICATION_MESSAGE_ID ,
18
+ )
13
19
from .meeting import find_next_event_and_notify_core_team
14
20
15
21
@@ -19,44 +25,89 @@ def __init__(self, *args, **kwargs):
19
25
20
26
self .bg_task = self .loop .create_task (self .check_events_for_next_week ())
21
27
22
- async def on_raw_reaction_add (self , reaction ):
28
+ async def on_remove_checkmark_reaction (
29
+ self , reaction : RawReactionActionEvent
30
+ ) -> None :
31
+ message_id = reaction .message_id
23
32
24
- assert self .user
33
+ if message_id == REACT_FOR_MEETINGS_NOTIFICATION_MESSAGE_ID :
34
+ # reaction.member happens to be always `None`, so we use the
35
+ # `user_id` instead
25
36
26
- if reaction .user_id == self .user .id :
27
- return
37
+ if reaction .guild_id is None :
38
+ print ("Guild is None" )
39
+ return
40
+
41
+ guild = await self .fetch_guild (reaction .guild_id )
28
42
43
+ assert guild
44
+
45
+ member = await guild .fetch_member (reaction .user_id )
46
+
47
+ if member :
48
+ await member .remove_roles (
49
+ nextcord .Object (id = MEETING_WATCHERS_ROLE_ID ),
50
+ reason = "Opted out of meeting notifications via reaction" ,
51
+ )
52
+
53
+ async def on_add_checkmark_reaction (self , reaction : RawReactionActionEvent ) -> None :
29
54
message_id = reaction .message_id
30
- emoji = reaction .emoji
31
55
32
- if emoji .name == "✅" and (
33
- notification := get_notification_for_discord_message_id (
34
- message_id , "core_devs"
56
+ if message_id == REACT_FOR_MEETINGS_NOTIFICATION_MESSAGE_ID :
57
+ if reaction .member is None :
58
+ print ("Member is None" )
59
+ return
60
+
61
+ await reaction .member .add_roles (
62
+ nextcord .Object (id = MEETING_WATCHERS_ROLE_ID ),
63
+ reason = "Opted in for meeting notifications via reaction" ,
35
64
)
65
+
66
+ return
67
+
68
+ if meeting_notification := get_notification_for_discord_message_id (
69
+ message_id , "core_devs"
36
70
):
37
- event_date = notification .date .isoformat ()
38
- public_notification = get_notification_for_date (event_date , "public" )
71
+ event_date = meeting_notification .date .isoformat ()
39
72
40
- if public_notification :
73
+ if get_notification_for_date ( event_date , "public" ) is not None :
41
74
return
42
75
43
76
channel = client .get_channel (GENERAL_CHANNEL_ID )
44
77
45
78
assert isinstance (channel , nextcord .channel .TextChannel )
46
79
47
80
embed = nextcord .Embed (color = 5814783 )
48
- add_localized_times_to_embed (embed , notification .date )
81
+ add_localized_times_to_embed (embed , meeting_notification .date )
49
82
50
83
message = await channel .send (
51
84
"Hey @everyone 👋 the next monthly meeting will happen "
52
- f"{ notification .date .humanize ()} 📅\n "
85
+ f"{ meeting_notification .date .humanize ()} 📅\n "
53
86
f"Realtime notes will be posted here: { NOTES_LINK } .\n \n "
54
87
"Feel free to add any topics you'd like to discuss in the meeting! 🍓" ,
55
88
embed = embed ,
56
89
)
57
90
58
91
add_notification_for_date (event_date , message .id , "public" )
59
92
93
+ async def on_raw_reaction_add (self , reaction : RawReactionActionEvent ) -> None :
94
+ assert self .user
95
+
96
+ if reaction .user_id == self .user .id :
97
+ return
98
+
99
+ if reaction .emoji .name == "✅" :
100
+ await self .on_add_checkmark_reaction (reaction )
101
+
102
+ async def on_raw_reaction_remove (self , reaction : RawReactionActionEvent ) -> None :
103
+ assert self .user
104
+
105
+ if reaction .user_id == self .user .id :
106
+ return
107
+
108
+ if reaction .emoji .name == "✅" :
109
+ await self .on_remove_checkmark_reaction (reaction )
110
+
60
111
async def check_events_for_next_week (self ):
61
112
await self .wait_until_ready ()
62
113
print ("Bot is ready!" )
0 commit comments