Skip to content

Commit

Permalink
Merge branch 'master' into v2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
BobDotCom committed Apr 9, 2022
2 parents e69b7d4 + d8bcbfa commit 6052537
Show file tree
Hide file tree
Showing 69 changed files with 2,403 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ body:
attributes:
label: Checklist
description: >
Let's make sure you've properly done due dilligence when reporting this issue!
Let's make sure you've properly done due diligence when reporting this issue!
options:
- label: I have searched the open issues for duplicates.
required: true
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ build/
test.py
build/
node_modules/*
test.py
24 changes: 10 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
Pycord
======

.. image:: https://img.shields.io/discord/881207955029110855?color=blue&label=discord
.. image:: https://img.shields.io/discord/881207955029110855?label=discord&style=for-the-badge&logo=discord&color=5865F2&logoColor=white
:target: https://pycord.dev/discord
:alt: Discord server invite
.. image:: https://img.shields.io/pypi/v/py-cord.svg
.. image:: https://img.shields.io/pypi/v/py-cord.svg?style=for-the-badge&logo=pypi&color=yellowgreen&logoColor=white
:target: https://pypi.python.org/pypi/py-cord
:alt: PyPI version info
.. image:: https://img.shields.io/pypi/pyversions/py-cord.svg
.. image:: https://img.shields.io/pypi/pyversions/py-cord.svg?style=for-the-badge&logo=python&logoColor=white
:target: https://pypi.python.org/pypi/py-cord
:alt: PyPI supported Python versions
.. image:: https://img.shields.io/pypi/dm/py-cord?color=blue
.. image:: https://img.shields.io/pypi/dm/py-cord?color=blueviolet&logo=pypi&logoColor=white&style=for-the-badge
:target: https://pypi.python.org/pypi/py-cord
:alt: PyPI downloads

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

What Happened to Discord.py?
----------------------------
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>`__.


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.

Key Features
------------

Expand Down Expand Up @@ -115,7 +108,9 @@ Traditional Commands Example
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=">")
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix=">", intents=intents)
@bot.command()
async def ping(ctx):
Expand All @@ -127,10 +122,11 @@ You can find more examples in the examples directory.

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

Links
-----
Useful Links
------------

- `Documentation <https://docs.pycord.dev/en/master/index.html>`_
- `Learn how to create Discord bots with Pycord <https://guide.pycord.dev>`_
- `Our Official Discord Server <https://pycord.dev/discord>`_
- `Official Discord Developers Server <https://discord.gg/discord-developers>`_
- `Unofficial Discord API Server <https://discord.gg/discord-api>`_
8 changes: 4 additions & 4 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__author__ = "Pycord Development"
__license__ = "MIT"
__copyright__ = "Copyright 2015-2021 Rapptz & Copyright 2021-present Pycord Development"
__version__ = "2.0.0b5"
__version__ = "2.0.0b6"

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

Expand All @@ -28,9 +28,9 @@
from .bot import *
from .channel import *
from .client import *
from .cog import Cog
from .cog import *
from .colour import *
from .commands.__init__ import *
from .commands import *
from .components import *
from .embeds import *
from .emoji import *
Expand Down Expand Up @@ -75,6 +75,6 @@ class VersionInfo(NamedTuple):
serial: int


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

logging.getLogger(__name__).addHandler(logging.NullHandler())
76 changes: 74 additions & 2 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import asyncio
import copy
import time
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -41,6 +42,7 @@
Union,
overload,
runtime_checkable,
Iterable,
)

from . import utils
Expand Down Expand Up @@ -79,6 +81,7 @@
GroupChannel,
PartialMessageable,
TextChannel,
VoiceChannel,
)
from .client import Client
from .embeds import Embed
Expand All @@ -95,13 +98,82 @@
from .ui.view import View
from .user import ClientUser

PartialMessageableChannel = Union[TextChannel, Thread, DMChannel, PartialMessageable]
PartialMessageableChannel = Union[TextChannel, VoiceChannel, Thread, DMChannel, PartialMessageable]
MessageableChannel = Union[PartialMessageableChannel, GroupChannel]
SnowflakeTime = Union["Snowflake", datetime]

MISSING = utils.MISSING


async def _single_delete_strategy(messages: Iterable[Message], *, reason: Optional[str] = None):
for m in messages:
await m.delete(reason=reason)


async def _purge_messages_helper(
channel: Union[TextChannel, Thread, VoiceChannel],
*,
limit: Optional[int] = 100,
check: Callable[[Message], bool] = MISSING,
before: Optional[SnowflakeTime] = None,
after: Optional[SnowflakeTime] = None,
around: Optional[SnowflakeTime] = None,
oldest_first: Optional[bool] = False,
bulk: bool = True,
reason: Optional[str] = None,
) -> List[Message]:
if check is MISSING:
check = lambda m: True

iterator = channel.history(
limit=limit,
before=before,
after=after,
oldest_first=oldest_first,
around=around,
)
ret: List[Message] = []
count = 0

minimum_time = int((time.time() - 14 * 24 * 60 * 60) * 1000.0 - 1420070400000) << 22
strategy = channel.delete_messages if bulk else _single_delete_strategy

async for message in iterator:
if count == 100:
to_delete = ret[-100:]
await strategy(to_delete, reason=reason)
count = 0
await asyncio.sleep(1)

if not check(message):
continue

if message.id < minimum_time:
# older than 14 days old
if count == 1:
await ret[-1].delete(reason=reason)
elif count >= 2:
to_delete = ret[-count:]
await strategy(to_delete, reason=reason)

count = 0
strategy = _single_delete_strategy

count += 1
ret.append(message)

# Some messages remaining to poll
if count >= 2:
# more than 2 messages -> bulk delete
to_delete = ret[-count:]
await strategy(to_delete, reason=reason)
elif count == 1:
# delete a single message
await ret[-1].delete(reason=reason)

return ret


class _Undefined:
def __repr__(self) -> str:
return "see-below"
Expand Down Expand Up @@ -1362,11 +1434,11 @@ async def send(

if allowed_mentions is None:
allowed_mentions = state.allowed_mentions and state.allowed_mentions.to_dict()

elif state.allowed_mentions is not None:
allowed_mentions = state.allowed_mentions.merge(allowed_mentions).to_dict()
else:
allowed_mentions = allowed_mentions.to_dict()

if mention_author is not None:
allowed_mentions = allowed_mentions or AllowedMentions().to_dict()
allowed_mentions["replied_user"] = bool(mention_author)
Expand Down
Loading

0 comments on commit 6052537

Please sign in to comment.