Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add can_send method to Messageable" #243

Merged
merged 1 commit into from
Oct 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,59 +1529,6 @@ async def pins(self) -> List[Message]:
state = self._state
data = await state.http.pins_from(channel.id)
return [state.create_message(channel=channel, data=m) for m in data]

def can_send(self, *objects) -> bool:
"""Returns a :class:`bool` indicating whether you have the permissions to send the object(s).

Raises
------
TypeError
An invalid type has been passed.

Returns
--------
:class:`bool`
Indicates whether you have the permissions to send the object(s).
"""
mapping = {
'Message': 'send_messages',
'Embed': 'embed_links',
'File': 'attach_files',
'Emoji': 'use_external_emojis',
'GuildSticker': 'use_external_stickers',
}
# Can't use channel = await self._get_channel() since its async
if hasattr(self, 'permissions_for'):
channel = self
elif hasattr(self, 'channel') and not type(self.channel).__name__ in ('DMChannel', 'GroupChannel')
channel = self.channel
else:
return True # Permissions don't exist for User DMs


objects = (None, ) + objects # Makes sure we check for send_messages first

for obj in objects:
try:
if obj is None:
permission = mapping['Message']
else:
permission = mapping.get(type(obj).__name__) or mapping[obj.__name__]

if type(obj).__name__ == 'Emoji':
if obj._to_partial().is_unicode_emoji or obj.guild_id == channel.guild.id:
continue
elif type(obj).__name__ == 'GuildSticker':
if obj.guild_id == channel.guild.id:
continue

except (KeyError, AttributeError):
raise TypeError(f'The object {obj} is of an invalid type.')

if not getattr(channel.permissions_for(channel.guild.me), permission):
return False

return True

def history(
self,
Expand Down