Skip to content

Commit 40f1bcf

Browse files
authored
Updatet main-branch(discord) to 1.7.5.1
1 parent 9f4d93c commit 40f1bcf

18 files changed

+1363
-577
lines changed

discord/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"""
1313

1414
__title__ = 'discord'
15-
__author__ = 'Rapptz'
15+
__author__ = 'Rapptz & mccoderpy'
1616
__license__ = 'MIT'
1717
__copyright__ = 'Copyright 2015-present Rapptz'
18-
__version__ = '1.7.2'
18+
__version__ = '1.7.5.1'
1919

2020
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
2121

@@ -29,6 +29,7 @@
2929
from .partial_emoji import PartialEmoji
3030
from .activity import *
3131
from .channel import *
32+
from .components import ActionRow, Button, SelectMenu, SelectOption
3233
from .guild import Guild
3334
from .flags import *
3435
from .relationship import Relationship
@@ -51,7 +52,6 @@
5152
from . import utils, opus, abc
5253
from .enums import *
5354
from .embeds import Embed
54-
from .components import Button, SelectMenu, ActionRow, ButtonColor, ButtonStyle, select_option
5555
from .mentions import AllowedMentions
5656
from .shard import AutoShardedClient, ShardInfo
5757
from .player import *

discord/__main__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import aiohttp
3434
import platform
3535

36+
3637
def show_version():
3738
entries = []
3839

@@ -49,10 +50,12 @@ def show_version():
4950
entries.append('- system info: {0.system} {0.release} {0.version}'.format(uname))
5051
print('\n'.join(entries))
5152

53+
5254
def core(parser, args):
5355
if args.version:
5456
show_version()
5557

58+
5659
bot_template = """#!/usr/bin/env python3
5760
# -*- coding: utf-8 -*-
5861
@@ -177,12 +180,13 @@ async def cog_after_invoke(self, ctx):
177180

178181
translation_table = str.maketrans(_base_table)
179182

183+
180184
def to_path(parser, name, *, replace_spaces=False):
181185
if isinstance(name, Path):
182186
return name
183187

184188
if sys.platform == 'win32':
185-
forbidden = ('CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', \
189+
forbidden = ('CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7',
186190
'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9')
187191
if len(name) <= 4 and name.upper() in forbidden:
188192
parser.error('invalid directory name given, use a different one')
@@ -192,6 +196,7 @@ def to_path(parser, name, *, replace_spaces=False):
192196
name = name.replace(' ', '-')
193197
return Path(name)
194198

199+
195200
def newbot(parser, args):
196201
new_directory = to_path(parser, args.directory) / to_path(parser, args.name)
197202

@@ -233,6 +238,7 @@ def newbot(parser, args):
233238

234239
print('successfully made bot at', new_directory)
235240

241+
236242
def newcog(parser, args):
237243
cog_dir = to_path(parser, args.directory)
238244
try:
@@ -266,6 +272,7 @@ def newcog(parser, args):
266272
else:
267273
print('successfully made cog at', directory)
268274

275+
269276
def add_newbot_args(subparser):
270277
parser = subparser.add_parser('newbot', help='creates a command bot project quickly')
271278
parser.set_defaults(func=newbot)
@@ -276,6 +283,7 @@ def add_newbot_args(subparser):
276283
parser.add_argument('--sharded', help='whether to use AutoShardedBot', action='store_true')
277284
parser.add_argument('--no-git', help='do not create a .gitignore file', action='store_true', dest='no_git')
278285

286+
279287
def add_newcog_args(subparser):
280288
parser = subparser.add_parser('newcog', help='creates a new cog template quickly')
281289
parser.set_defaults(func=newcog)
@@ -287,6 +295,7 @@ def add_newcog_args(subparser):
287295
parser.add_argument('--hide-commands', help='whether to hide all commands in the cog', action='store_true')
288296
parser.add_argument('--full', help='add all special methods as well', action='store_true')
289297

298+
290299
def parse_args():
291300
parser = argparse.ArgumentParser(prog='discord', description='Tools for helping with discord.py')
292301
parser.add_argument('-v', '--version', action='store_true', help='shows the library version')
@@ -297,9 +306,11 @@ def parse_args():
297306
add_newcog_args(subparser)
298307
return parser, parser.parse_args()
299308

309+
300310
def main():
301311
parser, args = parse_args()
302312
args.func(parser, args)
303313

314+
304315
if __name__ == '__main__':
305316
main()

discord/abc.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from .iterators import HistoryIterator
3636
from .context_managers import Typing
37-
from .enums import ChannelType
37+
from .enums import try_enum, ChannelType, PermissionType
3838
from .errors import InvalidArgument, ClientException
3939
from .mentions import AllowedMentions
4040
from .permissions import PermissionOverwrite, Permissions
@@ -175,10 +175,7 @@ def __init__(self, **kwargs):
175175
self.id = kwargs.pop('id')
176176
self.allow = int(kwargs.pop('allow_new', 0))
177177
self.deny = int(kwargs.pop('deny_new', 0))
178-
_type = kwargs.pop('type')
179-
if _type not in ('role', 'user', 'member'):
180-
_type = {0: 'role', 1: 'member'}.get(_type)
181-
self.type = sys.intern(_type)
178+
self.type = sys.intern(kwargs.pop('type'))
182179

183180
def _asdict(self):
184181
return {
@@ -331,10 +328,13 @@ def _fill_overwrites(self, data):
331328
everyone_id = self.guild.id
332329

333330
for index, overridden in enumerate(data.get('permission_overwrites', [])):
331+
overridden_type = try_enum(PermissionType, overridden.pop('type'))
332+
if not overridden_type:
333+
raise AttributeError('Type type should be 0 - member, or 1 - role not %s' % overridden_type)
334334
overridden_id = int(overridden.pop('id'))
335-
self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
335+
self._overwrites.append(_Overwrites(id=overridden_id, type=overridden_type.name, **overridden))
336336

337-
if overridden['type'] == 'member':
337+
if overridden_type.name == 'member':
338338
continue
339339

340340
if overridden_id == everyone_id:
@@ -1031,18 +1031,23 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
10311031

10321032
if embed is not None:
10331033
embed = embed.to_dict()
1034-
1034+
embed_list = []
1035+
if embed:
1036+
embed_list.append(embed)
1037+
if embeds:
1038+
embed_list.extend([e.to_dict() for e in embeds])
1039+
embeds = embed_list
1040+
if len(embeds) > 10:
1041+
raise InvalidArgument(f'The maximum number of embeds that can be send with a message is 10, got: {len(embeds)}')
10351042
if components:
10361043
_components = []
10371044
for component in ([components] if not isinstance(components, list) else components):
1038-
if isinstance(component, Button):
1039-
_components.extend(ActionRow(component).sendable())
1040-
elif isinstance(component, SelectMenu):
1041-
_components.extend(ActionRow(component).sendable())
1045+
if isinstance(component, (Button, SelectMenu)):
1046+
_components.extend(ActionRow(component).to_dict())
10421047
elif isinstance(component, ActionRow):
1043-
_components.extend(component.sendable())
1048+
_components.extend(component.to_dict())
10441049
elif isinstance(component, list):
1045-
_components.extend(ActionRow(*[obj for obj in component if any([isinstance(obj, Button), isinstance(obj, SelectMenu)])]).sendable())
1050+
_components.extend(ActionRow(*[obj for obj in component if isinstance(obj, (Button, SelectMenu))]).to_dict())
10461051
components = _components
10471052

10481053
if allowed_mentions is not None:
@@ -1066,23 +1071,17 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
10661071
if file is not None and files is not None:
10671072
raise InvalidArgument('cannot pass both file and files parameter to send()')
10681073

1069-
is_interaction_responce = kwargs.pop('__is_interaction_responce', None)
1074+
is_interaction_response = kwargs.pop('__is_interaction_response', None)
10701075
deferred = kwargs.pop('__deferred', False)
10711076
use_webhook = kwargs.pop('__use_webhook', False)
10721077
interaction_id = kwargs.pop('__interaction_id', None)
10731078
interaction_token = kwargs.pop('__interaction_token', None)
10741079
application_id = kwargs.pop('__application_id', None)
10751080
followup = kwargs.pop('followup', False)
1076-
if is_interaction_responce is False or None:
1081+
if is_interaction_response is False or None:
10771082
hidden = None
1078-
embedlist = []
1079-
if embed:
1080-
embedlist.append(embed)
1081-
if embeds:
1082-
embedlist.extend([e.to_dict() for e in embeds])
1083-
embeds = embedlist
1084-
if len(embeds) > 10:
1085-
raise InvalidArgument(f'The maximum number of embeds that can be sent with a response is 10, get: {len(embeds)}')
1083+
if hidden is True and file or files:
1084+
raise AttributeError('An ephemeral(hidden) Message could not contain file(s)')
10861085
if file is not None:
10871086
if not isinstance(file, File):
10881087
raise InvalidArgument('file parameter must be File')

discord/audit_logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _transform_overwrites(entry, data):
8282
target = Object(id=ow_id)
8383

8484
overwrites.append((target, ow))
85-
85+
print(overwrites)
8686
return overwrites
8787

8888
class AuditLogDiff:

discord/client.py

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,11 +1024,20 @@ async def on_ready():
10241024
return coro
10251025

10261026
def on_click(self, custom_id=None):
1027-
"""A decorator that registers a raw_button_click event that checks on execution if the ``custom_id's`` are the same; if so, the :func:`func` is called..
1027+
"""
1028+
A decorator that registers a raw_button_click event that checks on execution if the ``custom_id's`` are the same; if so, the :func:`func` is called..
1029+
1030+
The function this is attached to must take the same parameters as a
1031+
`raw_button_click-Event <https://discordpy-message-components.rtfd.io/en/latest/addition.html#on_raw_button_click>`_.
10281032
1029-
You can find more info about this in the `documentation <https://discordpy-message-components.readthedocs.io/en/latest/additions.html#on-click>`.
1033+
.. important::
1034+
The func must be a coroutine, if not, :exc:`TypeError` is raised.
10301035
1031-
The func must be a :ref:`coroutine <coroutine>`, if not, :exc:`TypeError` is raised.
1036+
Parameters
1037+
----------
1038+
custom_id: Optional[str]
1039+
If the :attr:`custom_id` of the :class:`discord.Button` could not use as an function name
1040+
or you want to give the function a different name then the custom_id use this one to set the custom_id.
10321041
10331042
Example
10341043
-------
@@ -1038,16 +1047,16 @@ def on_click(self, custom_id=None):
10381047
# the Button
10391048
Button(label='Hey im a cool blue Button',
10401049
custom_id='cool blue Button',
1041-
style=ButtonColor.blurple)
1050+
style=ButtonStyle.blurple)
10421051
1043-
# function thats called when the Button pressed
1052+
# function that's called when the Button pressed
10441053
@client.on_click(custom_id='cool blue Button')
1045-
async def cool_blue_button(i: discord.Interaction):
1046-
await i.respond('Hey you pressed a `cool blue Button`!', hidden=True)
1054+
async def cool_blue_button(i: discord.Interaction, button):
1055+
await i.respond(f'Hey you pressed a {button.custom_id}!', hidden=True)
10471056
10481057
Raises
10491058
------
1050-
:class:`TypeError`
1059+
TypeError
10511060
The coroutine passed is not actually a coroutine.
10521061
"""
10531062
def decorator(func):
@@ -1056,35 +1065,32 @@ def decorator(func):
10561065

10571066
_name = custom_id if custom_id is not None else func.__name__
10581067

1059-
def check(i):
1060-
return i.component.custom_id == str(_name)
1061-
10621068
try:
10631069
listeners = self._listeners['raw_button_click']
10641070
except KeyError:
10651071
listeners = []
10661072
self._listeners['raw_button_click'] = listeners
10671073

1068-
listeners.append((func, check))
1074+
listeners.append((func, lambda i, c: str(c.custom_id) == str(custom_id)))
10691075
return func
10701076

10711077
return decorator
10721078

10731079
def on_select(self, custom_id=None):
1074-
"""A decorator with which you can assign a function to a specific :class:`SelectMenu` (or its custom_id).
1080+
"""
1081+
A decorator with which you can assign a function to a specific :class:`discord.SelectMenu` (or its custom_id).
10751082
1076-
.. note::
1077-
This will always give exactly one Parameter of type `discord.Interaction <./interaction.html#discord-interaction>`_ like an `raw_selection_select-Event <#on-raw-button-click>`_.
1083+
The function this is attached to must take the same parameters as a
1084+
`raw_selection_select-Event <https://discordpy-message-components.rtfd.io/en/latest/addition.html#on_raw_selection_select>`_.
10781085
10791086
.. important::
1080-
The Function this decorator attached to must be an corountine (means an awaitable)
1087+
The func must be a coroutine, if not, :exc:`TypeError` is raised.
10811088
10821089
Parameters
1083-
----------
1084-
1085-
:attr:`custom_id`: Optional[str]
1086-
1087-
If the :attr:`custom_id` of the SelectMenu could not use as an function name or you want to give the function a diferent name then the custom_id use this one to set the custom_id.
1090+
-----------
1091+
custom_id: Optional[str]
1092+
If the :attr:`custom_id` of the :class:`discord.SelectMenu` could not use as an function name
1093+
or you want to give the function a different name then the custom_id use this one to set the custom_id.
10881094
10891095
10901096
Example
@@ -1094,16 +1100,16 @@ def on_select(self, custom_id=None):
10941100
10951101
# the SelectMenu
10961102
SelectMenu(custom_id='choose_your_gender',
1097-
options=[
1098-
select_option(label='Female', value='Female', emoji='♀️'),
1099-
select_option(label='Male', value='Male', emoji='♂️'),
1100-
select_option(label='Non Binary', value='Non Binary', emoji='⚧')
1101-
], placeholder='Choose your Gender')
1103+
options=[
1104+
SelectOption(label='Female', value='Female', emoji='♀️'),
1105+
SelectOption(label='Male', value='Male', emoji='♂️'),
1106+
SelectOption(label='Trans/Non Binary', value='Trans/Non Binary', emoji='⚧')
1107+
], placeholder='Choose your Gender')
11021108
1103-
# function thats called when the SelectMenu is used
1109+
# function that's called when the SelectMenu is used
11041110
@client.on_select()
1105-
async def choose_your_gender(i: discord.Interaction):
1106-
await i.respond(f'You selected `{i.component.values[0]}`!', hidden=True)
1111+
async def choose_your_gender(i: discord.Interaction, select_menu):
1112+
await i.respond(f'You selected `{select_menu.values[0]}`!', hidden=True)
11071113
11081114
Raises
11091115
--------
@@ -1114,18 +1120,15 @@ def decorator(func):
11141120
if not asyncio.iscoroutinefunction(func):
11151121
raise TypeError('event registered must be a coroutine function')
11161122

1117-
_name = custom_id if custom_id is not None else func.__name__
1118-
1119-
def check(i):
1120-
return i.component.custom_id == str(_name)
1123+
_custom_id = custom_id if custom_id is not None else func.__name__
11211124

11221125
try:
11231126
listeners = self._listeners['raw_selection_select']
11241127
except KeyError:
11251128
listeners = []
11261129
self._listeners['raw_selection_select'] = listeners
11271130

1128-
listeners.append((func, check))
1131+
listeners.append((func, lambda i, c: str(c.custom_id) == str(_custom_id)))
11291132
return func
11301133

11311134
return decorator

0 commit comments

Comments
 (0)