Skip to content

Commit 6052537

Browse files
committed
Merge branch 'master' into v2.x
2 parents e69b7d4 + d8bcbfa commit 6052537

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2403
-1021
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ body:
6464
attributes:
6565
label: Checklist
6666
description: >
67-
Let's make sure you've properly done due dilligence when reporting this issue!
67+
Let's make sure you've properly done due diligence when reporting this issue!
6868
options:
6969
- label: I have searched the open issues for duplicates.
7070
required: true

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@ build/
3030
test.py
3131
build/
3232
node_modules/*
33-
test.py

README.rst

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
Pycord
22
======
33

4-
.. image:: https://img.shields.io/discord/881207955029110855?color=blue&label=discord
4+
.. image:: https://img.shields.io/discord/881207955029110855?label=discord&style=for-the-badge&logo=discord&color=5865F2&logoColor=white
55
:target: https://pycord.dev/discord
66
:alt: Discord server invite
7-
.. image:: https://img.shields.io/pypi/v/py-cord.svg
7+
.. image:: https://img.shields.io/pypi/v/py-cord.svg?style=for-the-badge&logo=pypi&color=yellowgreen&logoColor=white
88
:target: https://pypi.python.org/pypi/py-cord
99
:alt: PyPI version info
10-
.. image:: https://img.shields.io/pypi/pyversions/py-cord.svg
10+
.. image:: https://img.shields.io/pypi/pyversions/py-cord.svg?style=for-the-badge&logo=python&logoColor=white
1111
:target: https://pypi.python.org/pypi/py-cord
1212
:alt: PyPI supported Python versions
13-
.. image:: https://img.shields.io/pypi/dm/py-cord?color=blue
13+
.. image:: https://img.shields.io/pypi/dm/py-cord?color=blueviolet&logo=pypi&logoColor=white&style=for-the-badge
1414
:target: https://pypi.python.org/pypi/py-cord
1515
:alt: PyPI downloads
1616

1717
A fork of discord.py. Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python.
1818

19-
What Happened to Discord.py?
20-
----------------------------
21-
Rapptz, also known as Danny, the maintainer and core developer of discord.py will no longer be updating it. Here's his `Full explanation <https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1>`__ and an `FAQ <https://gist.github.com/Rapptz/4a2f62751b9600a31a0d3c78100287f1#FAQ>`__.
22-
23-
24-
Pycord v1.7.3 is the same as discord.py v1.7.3, however, Pycord v2.0 will support newer features of the API such as slash commands, context menus, scheduled events, timeouts, and others.
25-
2619
Key Features
2720
------------
2821

@@ -115,7 +108,9 @@ Traditional Commands Example
115108
import discord
116109
from discord.ext import commands
117110
118-
bot = commands.Bot(command_prefix=">")
111+
intents = discord.Intents.default()
112+
intents.message_content = True
113+
bot = commands.Bot(command_prefix=">", intents=intents)
119114
120115
@bot.command()
121116
async def ping(ctx):
@@ -127,10 +122,11 @@ You can find more examples in the examples directory.
127122

128123
Note: Make sure you do not reveal your bot token to anyone, it can grant access to your bot.
129124

130-
Links
131-
-----
125+
Useful Links
126+
------------
132127

133128
- `Documentation <https://docs.pycord.dev/en/master/index.html>`_
129+
- `Learn how to create Discord bots with Pycord <https://guide.pycord.dev>`_
134130
- `Our Official Discord Server <https://pycord.dev/discord>`_
135131
- `Official Discord Developers Server <https://discord.gg/discord-developers>`_
136132
- `Unofficial Discord API Server <https://discord.gg/discord-api>`_

discord/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
__author__ = "Pycord Development"
1414
__license__ = "MIT"
1515
__copyright__ = "Copyright 2015-2021 Rapptz & Copyright 2021-present Pycord Development"
16-
__version__ = "2.0.0b5"
16+
__version__ = "2.0.0b6"
1717

1818
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1919

@@ -28,9 +28,9 @@
2828
from .bot import *
2929
from .channel import *
3030
from .client import *
31-
from .cog import Cog
31+
from .cog import *
3232
from .colour import *
33-
from .commands.__init__ import *
33+
from .commands import *
3434
from .components import *
3535
from .embeds import *
3636
from .emoji import *
@@ -75,6 +75,6 @@ class VersionInfo(NamedTuple):
7575
serial: int
7676

7777

78-
version_info: VersionInfo = VersionInfo(major=2, minor=0, micro=0, releaselevel="beta", serial=5)
78+
version_info: VersionInfo = VersionInfo(major=2, minor=0, micro=0, releaselevel="beta", serial=6)
7979

8080
logging.getLogger(__name__).addHandler(logging.NullHandler())

discord/abc.py

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import asyncio
2929
import copy
30+
import time
3031
from typing import (
3132
TYPE_CHECKING,
3233
Any,
@@ -41,6 +42,7 @@
4142
Union,
4243
overload,
4344
runtime_checkable,
45+
Iterable,
4446
)
4547

4648
from . import utils
@@ -79,6 +81,7 @@
7981
GroupChannel,
8082
PartialMessageable,
8183
TextChannel,
84+
VoiceChannel,
8285
)
8386
from .client import Client
8487
from .embeds import Embed
@@ -95,13 +98,82 @@
9598
from .ui.view import View
9699
from .user import ClientUser
97100

98-
PartialMessageableChannel = Union[TextChannel, Thread, DMChannel, PartialMessageable]
101+
PartialMessageableChannel = Union[TextChannel, VoiceChannel, Thread, DMChannel, PartialMessageable]
99102
MessageableChannel = Union[PartialMessageableChannel, GroupChannel]
100103
SnowflakeTime = Union["Snowflake", datetime]
101104

102105
MISSING = utils.MISSING
103106

104107

108+
async def _single_delete_strategy(messages: Iterable[Message], *, reason: Optional[str] = None):
109+
for m in messages:
110+
await m.delete(reason=reason)
111+
112+
113+
async def _purge_messages_helper(
114+
channel: Union[TextChannel, Thread, VoiceChannel],
115+
*,
116+
limit: Optional[int] = 100,
117+
check: Callable[[Message], bool] = MISSING,
118+
before: Optional[SnowflakeTime] = None,
119+
after: Optional[SnowflakeTime] = None,
120+
around: Optional[SnowflakeTime] = None,
121+
oldest_first: Optional[bool] = False,
122+
bulk: bool = True,
123+
reason: Optional[str] = None,
124+
) -> List[Message]:
125+
if check is MISSING:
126+
check = lambda m: True
127+
128+
iterator = channel.history(
129+
limit=limit,
130+
before=before,
131+
after=after,
132+
oldest_first=oldest_first,
133+
around=around,
134+
)
135+
ret: List[Message] = []
136+
count = 0
137+
138+
minimum_time = int((time.time() - 14 * 24 * 60 * 60) * 1000.0 - 1420070400000) << 22
139+
strategy = channel.delete_messages if bulk else _single_delete_strategy
140+
141+
async for message in iterator:
142+
if count == 100:
143+
to_delete = ret[-100:]
144+
await strategy(to_delete, reason=reason)
145+
count = 0
146+
await asyncio.sleep(1)
147+
148+
if not check(message):
149+
continue
150+
151+
if message.id < minimum_time:
152+
# older than 14 days old
153+
if count == 1:
154+
await ret[-1].delete(reason=reason)
155+
elif count >= 2:
156+
to_delete = ret[-count:]
157+
await strategy(to_delete, reason=reason)
158+
159+
count = 0
160+
strategy = _single_delete_strategy
161+
162+
count += 1
163+
ret.append(message)
164+
165+
# Some messages remaining to poll
166+
if count >= 2:
167+
# more than 2 messages -> bulk delete
168+
to_delete = ret[-count:]
169+
await strategy(to_delete, reason=reason)
170+
elif count == 1:
171+
# delete a single message
172+
await ret[-1].delete(reason=reason)
173+
174+
return ret
175+
176+
105177
class _Undefined:
106178
def __repr__(self) -> str:
107179
return "see-below"
@@ -1362,11 +1434,11 @@ async def send(
13621434

13631435
if allowed_mentions is None:
13641436
allowed_mentions = state.allowed_mentions and state.allowed_mentions.to_dict()
1365-
13661437
elif state.allowed_mentions is not None:
13671438
allowed_mentions = state.allowed_mentions.merge(allowed_mentions).to_dict()
13681439
else:
13691440
allowed_mentions = allowed_mentions.to_dict()
1441+
13701442
if mention_author is not None:
13711443
allowed_mentions = allowed_mentions or AllowedMentions().to_dict()
13721444
allowed_mentions["replied_user"] = bool(mention_author)

0 commit comments

Comments
 (0)