@@ -935,7 +935,7 @@ async def on_typing(self, channel, user, _):
935935 return
936936 await thread .recipient .trigger_typing ()
937937
938- async def on_raw_reaction_add (self , payload ):
938+ async def handle_reaction_events (self , payload , * , add ):
939939 user = self .get_user (payload .user_id )
940940 if user .bot :
941941 return
@@ -960,9 +960,9 @@ async def on_raw_reaction_add(self, payload):
960960 thread = await self .threads .find (recipient = user )
961961 if not thread :
962962 return
963-
964963 if (
965- message .embeds
964+ add
965+ and message .embeds
966966 and str (reaction ) == str (close_emoji )
967967 and self .config .get ("recipient_thread_close" )
968968 ):
@@ -992,8 +992,21 @@ async def on_raw_reaction_add(self, payload):
992992 logger .warning ("Failed to find linked message for reactions: %s" , e )
993993 return
994994
995- if await self .add_reaction (linked_message , reaction ):
996- await self .add_reaction (message , reaction )
995+ if add :
996+ if await self .add_reaction (linked_message , reaction ):
997+ await self .add_reaction (message , reaction )
998+ else :
999+ try :
1000+ await linked_message .remove_reaction (reaction , self .user )
1001+ await message .remove_reaction (reaction , self .user )
1002+ except (discord .HTTPException , discord .InvalidArgument ) as e :
1003+ logger .warning ("Failed to remove reaction: %s" , e )
1004+
1005+ async def on_raw_reaction_add (self , payload ):
1006+ await self .handle_reaction_events (payload , add = True )
1007+
1008+ async def on_raw_reaction_remove (self , payload ):
1009+ await self .handle_reaction_events (payload , add = False )
9971010
9981011 async def on_guild_channel_delete (self , channel ):
9991012 if channel .guild != self .modmail_guild :
0 commit comments