Browse Source

Rebase to latest upstream

pull/10109/head
dolfies 3 years ago
parent
commit
50ff16ede6
  1. 2
      discord/__main__.py
  2. 3
      discord/abc.py
  3. 36
      discord/channel.py
  4. 2
      discord/ext/commands/bot.py
  5. 8
      discord/file.py
  6. 10
      discord/message.py
  7. 2
      discord/state.py
  8. 5
      examples/basic_voice.py
  9. 1
      examples/custom_context.py
  10. 1
      examples/deleted.py
  11. 1
      examples/edits.py
  12. 1
      examples/guessing_game.py
  13. 1
      examples/reaction_roles.py
  14. 1
      examples/reply.py

2
discord/__main__.py

@ -56,6 +56,8 @@ def show_version() -> None:
def core(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None:
if args.version:
show_version()
else:
parser.print_help()
_bot_template = """#!/usr/bin/env python3

3
discord/abc.py

@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
import copy
import time
import asyncio
from datetime import datetime
from typing import (
@ -32,6 +33,7 @@ from typing import (
AsyncIterator,
Callable,
Dict,
Iterable,
List,
Optional,
TYPE_CHECKING,
@ -1225,6 +1227,7 @@ class Messageable:
The following implement this ABC:
- :class:`~discord.TextChannel`
- :class:`~discord.VoiceChannel`
- :class:`~discord.DMChannel`
- :class:`~discord.GroupChannel`
- :class:`~discord.User`

36
discord/channel.py

@ -85,6 +85,7 @@ if TYPE_CHECKING:
CategoryChannel as CategoryChannelPayload,
GroupDMChannel as GroupChannelPayload,
)
from .types.snowflake import SnowflakeList
class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
@ -132,11 +133,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
Bots and users with :attr:`~Permissions.manage_channels` or
:attr:`~Permissions.manage_messages` bypass slowmode.
nsfw: :class:`bool`
If the channel is marked as "not safe for work".
.. note::
To check if the channel or the guild of that channel are marked as NSFW, consider :meth:`is_nsfw` instead.
If the channel is marked as "not safe for work" or "age restricted".
default_auto_archive_duration: :class:`int`
The default auto archive duration in minutes for threads created in this channel.
@ -358,7 +355,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
{'topic': self.topic, 'nsfw': self.nsfw, 'rate_limit_per_user': self.slowmode_delay}, name=name, reason=reason
)
async def delete_messages(self, messages: Iterable[Snowflake], *, reason: Optional[str] = None) -> None:
async def delete_messages(self, messages: Iterable[Snowflake], /, *, reason: Optional[str] = None) -> None:
"""|coro|
Deletes a list of messages. This is similar to :meth:`Message.delete`
@ -822,6 +819,7 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
'name',
'id',
'guild',
'nsfw',
'bitrate',
'user_limit',
'_state',
@ -847,6 +845,7 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
def _update(self, guild: Guild, data: Union[VoiceChannelPayload, StageChannelPayload]) -> None:
self.guild: Guild = guild
self.name: str = data['name']
self.nsfw: bool = data.get('nsfw', False)
self.rtc_region: Optional[str] = data.get('rtc_region')
self.video_quality_mode: VideoQualityMode = try_enum(VideoQualityMode, data.get('video_quality_mode', 1))
self.category_id: Optional[int] = utils._get_as_snowflake(data, 'parent_id')
@ -860,6 +859,13 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
def _sorting_bucket(self) -> int:
return ChannelType.voice.value
def is_nsfw(self) -> bool:
""":class:`bool`: Checks if the channel is NSFW.
.. versionadded:: 2.0
"""
return self.nsfw
@property
def members(self) -> List[Member]:
"""List[:class:`Member`]: Returns all members that are currently inside this voice channel."""
@ -945,6 +951,10 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
The guild the channel belongs to.
id: :class:`int`
The channel ID.
nsfw: :class:`bool`
If the channel is marked as "not safe for work" or "age restricted".
.. versionadded:: 2.0
category_id: Optional[:class:`int`]
The category channel ID this channel belongs to, if applicable.
position: :class:`int`
@ -1057,6 +1067,8 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
Since messages are just iterated over and deleted one-by-one,
it's easy to get ratelimited using this method.
.. versionadded:: 2.0
Parameters
-----------
messages: Iterable[:class:`abc.Snowflake`]
@ -1099,6 +1111,8 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
The :attr:`~Permissions.read_message_history` permission is needed to
retrieve message history.
.. versionadded:: 2.0
Examples
---------
@ -1226,6 +1240,7 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
self,
*,
name: str = ...,
nsfw: bool = ...,
bitrate: int = ...,
user_limit: int = ...,
position: int = ...,
@ -1269,6 +1284,8 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
The new channel's name.
bitrate: :class:`int`
The new channel's bitrate.
nsfw: :class:`bool`
To mark the channel as NSFW or not.
user_limit: :class:`int`
The new channel's user limit.
position: :class:`int`
@ -1347,6 +1364,10 @@ class StageChannel(VocalGuildChannel):
The guild the channel belongs to.
id: :class:`int`
The channel ID.
nsfw: :class:`bool`
If the channel is marked as "not safe for work" or "age restricted".
.. versionadded:: 2.0
topic: Optional[:class:`str`]
The channel's topic. ``None`` if it isn't set.
category_id: Optional[:class:`int`]
@ -1513,6 +1534,7 @@ class StageChannel(VocalGuildChannel):
self,
*,
name: str = ...,
nsfw: bool = ...,
position: int = ...,
sync_permissions: int = ...,
category: Optional[CategoryChannel] = ...,
@ -1554,6 +1576,8 @@ class StageChannel(VocalGuildChannel):
The new channel's name.
position: :class:`int`
The new channel's position.
nsfw: :class:`bool`
To mark the channel as NSFW or not.
sync_permissions: :class:`bool`
Whether to sync permissions with the channel's new or pre-existing
category. Defaults to ``False``.

2
discord/ext/commands/bot.py

@ -1279,5 +1279,3 @@ class Bot(BotBase, discord.Client):
.. versionadded:: 1.7
"""
pass

8
discord/file.py

@ -68,14 +68,6 @@ class File:
To pass binary data, consider usage of ``io.BytesIO``.
filename: Optional[:class:`str`]
The filename to display when uploading to Discord.
If this is not given then it defaults to ``fp.name`` or if ``fp`` is
a string then the ``filename`` will default to the string given.
description: Optional[:class:`str`]
The description (alt text) for the file.
.. versionadded:: 2.0
spoiler: :class:`bool`
Whether the attachment is a spoiler. If left unspecified, the :attr:`~File.filename` is used
to determine if the file is a spoiler.

10
discord/message.py

@ -1321,7 +1321,6 @@ class Message(PartialMessage, Hashable):
self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])]
self.components: List[Component] = [_component_factory(d, self) for d in data.get('components', [])]
self.call: Optional[CallMessage] = None
self.interaction: Optional[Interaction] = None
try:
# If the channel doesn't have a guild attribute, we handle that
@ -1329,6 +1328,15 @@ class Message(PartialMessage, Hashable):
except AttributeError:
self.guild = state._get_guild(utils._get_as_snowflake(data, 'guild_id'))
self.interaction: Optional[Interaction] = None
try:
interaction = data['interaction']
except KeyError:
pass
else:
self.interaction = Interaction._from_message(self, **interaction)
try:
ref = data['message_reference']
except KeyError:

2
discord/state.py

@ -439,7 +439,7 @@ class ConnectionState:
self._status: Optional[str] = status
if cache_flags._empty:
self.store_user = self.create_user # type: ignore # Purposeful reassignment
self.store_user = self.create_user # type: ignore # This reassignment is on purpose
self.parsers: Dict[str, Callable[[Any], None]]
self.parsers = parsers = {}

5
examples/basic_voice.py

@ -123,8 +123,9 @@ class Music(commands.Cog):
elif ctx.voice_client.is_playing():
ctx.voice_client.stop()
bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"),
description='Relatively simple music bot example')
bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"), description='Relatively simple music bot example')
@bot.event
async def on_ready():

1
examples/custom_context.py

@ -28,6 +28,7 @@ class MyBot(commands.Bot):
# use the new MyContext class
return await super().get_context(message, cls=cls)
bot = MyBot(command_prefix='!', self_bot=True)

1
examples/deleted.py

@ -18,5 +18,6 @@ class MyClient(discord.Client):
msg = f'{message.author} has deleted the message: {message.content}'
await message.channel.send(msg)
client = MyClient()
client.run('token')

1
examples/edits.py

@ -17,5 +17,6 @@ class MyClient(discord.Client):
msg = f'**{before.author}** edited their message:\n{before.content} -> {after.content}'
await before.channel.send(msg)
client = MyClient()
client.run('token')

1
examples/guessing_game.py

@ -31,5 +31,6 @@ class MyClient(discord.Client):
else:
await message.channel.send(f'Oops. It is actually {answer}.')
client = MyClient()
client.run('token')

1
examples/reaction_roles.py

@ -77,5 +77,6 @@ class MyClient(discord.Client):
# If we want to do something in case of errors we'd do it here.
pass
client = MyClient()
client.run('token')

1
examples/reply.py

@ -14,5 +14,6 @@ class MyClient(discord.Client):
if message.content.startswith('!hello'):
await message.reply('Hello!', mention_author=True)
client = MyClient()
client.run('token')

Loading…
Cancel
Save