mirror of
				https://github.com/Rapptz/discord.py.git
				synced 2025-11-03 23:12:56 +00:00 
			
		
		
		
	message: de-duplicate reaction type conversion
Removes some duplicate code in Message.{add,remove}_reaction.
The code in question converts the emoji object from Reaction, Emoji, str, or PartialEmoji
to a string form suitable for sending over the wire.
			
			
This commit is contained in:
		@@ -675,18 +675,7 @@ class Message:
 | 
				
			|||||||
            The emoji parameter is invalid.
 | 
					            The emoji parameter is invalid.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if isinstance(emoji, Reaction):
 | 
					        emoji = self._emoji_reaction(emoji)
 | 
				
			||||||
            emoji = emoji.emoji
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if isinstance(emoji, Emoji):
 | 
					 | 
				
			||||||
            emoji = '%s:%s' % (emoji.name, emoji.id)
 | 
					 | 
				
			||||||
        elif isinstance(emoji, PartialEmoji):
 | 
					 | 
				
			||||||
            emoji = emoji._as_reaction()
 | 
					 | 
				
			||||||
        elif isinstance(emoji, str):
 | 
					 | 
				
			||||||
            pass # this is okay
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        await self._state.http.add_reaction(self.id, self.channel.id, emoji)
 | 
					        await self._state.http.add_reaction(self.id, self.channel.id, emoji)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def remove_reaction(self, emoji, member):
 | 
					    async def remove_reaction(self, emoji, member):
 | 
				
			||||||
@@ -721,23 +710,26 @@ class Message:
 | 
				
			|||||||
            The emoji parameter is invalid.
 | 
					            The emoji parameter is invalid.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if isinstance(emoji, Reaction):
 | 
					        emoji = self._emoji_reaction(emoji)
 | 
				
			||||||
            emoji = emoji.emoji
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if isinstance(emoji, Emoji):
 | 
					 | 
				
			||||||
            emoji = '%s:%s' % (emoji.name, emoji.id)
 | 
					 | 
				
			||||||
        elif isinstance(emoji, PartialEmoji):
 | 
					 | 
				
			||||||
            emoji = emoji._as_reaction()
 | 
					 | 
				
			||||||
        elif isinstance(emoji, str):
 | 
					 | 
				
			||||||
            pass # this is okay
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if member.id == self._state.self_id:
 | 
					        if member.id == self._state.self_id:
 | 
				
			||||||
            await self._state.http.remove_own_reaction(self.id, self.channel.id, emoji)
 | 
					            await self._state.http.remove_own_reaction(self.id, self.channel.id, emoji)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            await self._state.http.remove_reaction(self.id, self.channel.id, emoji, member.id)
 | 
					            await self._state.http.remove_reaction(self.id, self.channel.id, emoji, member.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @staticmethod
 | 
				
			||||||
 | 
					    def _emoji_reaction(emoji):
 | 
				
			||||||
 | 
					        if isinstance(emoji, Reaction):
 | 
				
			||||||
 | 
					            return emoji.emoji
 | 
				
			||||||
 | 
					        if isinstance(emoji, Emoji):
 | 
				
			||||||
 | 
					            return '%s:%s' % (emoji.name, emoji.id)
 | 
				
			||||||
 | 
					        if isinstance(emoji, PartialEmoji):
 | 
				
			||||||
 | 
					            return emoji._as_reaction()
 | 
				
			||||||
 | 
					        if isinstance(emoji, str):
 | 
				
			||||||
 | 
					            return emoji # this is okay
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        raise InvalidArgument('emoji argument must be str, Emoji, or Reaction not {.__class__.__name__}.'.format(emoji))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def clear_reactions(self):
 | 
					    async def clear_reactions(self):
 | 
				
			||||||
        """|coro|
 | 
					        """|coro|
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user