Skip to content

Commit b14823f

Browse files
authored
Merge branch 'Pycord-Development:master' into master
2 parents b172c40 + bd89ae0 commit b14823f

23 files changed

+2494
-920
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ docs/crowdin.py
1414
*.jpg
1515
*.flac
1616
*.mo
17+
.idea/

discord/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
from .components import *
6161
from .threads import *
6262
from .bot import *
63-
from .app import *
63+
from .commands import *
64+
from .cog import Cog
6465
from .welcome_screen import *
6566

6667

discord/abc.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
'GuildChannel',
6464
'Messageable',
6565
'Connectable',
66+
'Mentionable'
6667
)
6768

6869
T = TypeVar('T', bound=VoiceProtocol)
@@ -1142,6 +1143,7 @@ class Messageable:
11421143
- :class:`~discord.Member`
11431144
- :class:`~discord.ext.commands.Context`
11441145
- :class:`~discord.Thread`
1146+
- :class:`~discord.ApplicationContext`
11451147
"""
11461148

11471149
__slots__ = ()
@@ -1528,6 +1530,59 @@ async def pins(self) -> List[Message]:
15281530
state = self._state
15291531
data = await state.http.pins_from(channel.id)
15301532
return [state.create_message(channel=channel, data=m) for m in data]
1533+
1534+
def can_send(self, *objects) -> bool:
1535+
"""Returns a :class:`bool` indicating whether you have the permissions to send the object(s).
1536+
1537+
Raises
1538+
------
1539+
TypeError
1540+
An invalid type has been passed.
1541+
1542+
Returns
1543+
--------
1544+
:class:`bool`
1545+
Indicates whether you have the permissions to send the object(s).
1546+
"""
1547+
mapping = {
1548+
'Message': 'send_messages',
1549+
'Embed': 'embed_links',
1550+
'File': 'attach_files',
1551+
'Emoji': 'use_external_emojis',
1552+
'GuildSticker': 'use_external_stickers',
1553+
}
1554+
# Can't use channel = await self._get_channel() since its async
1555+
if hasattr(self, 'permissions_for'):
1556+
channel = self
1557+
elif hasattr(self, 'channel') and not type(self.channel).__name__ in ('DMChannel', 'GroupChannel'):
1558+
channel = self.channel
1559+
else:
1560+
return True # Permissions don't exist for User DMs
1561+
1562+
1563+
objects = (None, ) + objects # Makes sure we check for send_messages first
1564+
1565+
for obj in objects:
1566+
try:
1567+
if obj is None:
1568+
permission = mapping['Message']
1569+
else:
1570+
permission = mapping.get(type(obj).__name__) or mapping[obj.__name__]
1571+
1572+
if type(obj).__name__ == 'Emoji':
1573+
if obj._to_partial().is_unicode_emoji or obj.guild_id == channel.guild.id:
1574+
continue
1575+
elif type(obj).__name__ == 'GuildSticker':
1576+
if obj.guild_id == channel.guild.id:
1577+
continue
1578+
1579+
except (KeyError, AttributeError):
1580+
raise TypeError(f'The object {obj} is of an invalid type.')
1581+
1582+
if not getattr(channel.permissions_for(channel.guild.me), permission):
1583+
return False
1584+
1585+
return True
15311586

15321587
def history(
15331588
self,
@@ -1691,4 +1746,4 @@ async def connect(
16911746

16921747
class Mentionable:
16931748
# TODO: documentation, methods if needed
1694-
pass
1749+
pass

0 commit comments

Comments
 (0)