Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import discord.abc

if TYPE_CHECKING:
# https://github.com/PyCQA/pylint/issues/3525
# pylint: disable=cyclic-import

import discord
from discord import Bot
from discord.state import ConnectionState
Expand Down
3 changes: 3 additions & 0 deletions discord/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
from typing import Dict, List, Optional, TYPE_CHECKING, Any, Tuple, Union

if TYPE_CHECKING:
# https://github.com/PyCQA/pylint/issues/3525
# pylint: disable=cyclic-import

from aiohttp import ClientResponse, ClientWebSocketResponse

try:
Expand Down
4 changes: 2 additions & 2 deletions discord/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"""

import asyncio
from collections import namedtuple, deque
import concurrent.futures
import logging
import struct
import sys
import time
import threading
import time
import traceback
import zlib
from collections import namedtuple, deque

import aiohttp

Expand Down
143 changes: 75 additions & 68 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@

import asyncio
import datetime
import re
import io
import re
from os import PathLike
from typing import Dict, TYPE_CHECKING, Union, List, Optional, Any, Callable, Tuple, ClassVar, Optional, overload, TypeVar, Type
from typing import Dict, TYPE_CHECKING, Union, List, Any, Callable, Tuple, ClassVar, Optional, overload, TypeVar, Type

from . import utils
from .reaction import Reaction
from .components import _component_factory
from .embeds import Embed
from .emoji import Emoji
from .partial_emoji import PartialEmoji
from .enums import MessageType, ChannelType, try_enum
from .errors import InvalidArgument, HTTPException
from .components import _component_factory
from .embeds import Embed
from .member import Member
from .flags import MessageFlags
from .file import File
from .utils import escape_mentions, MISSING
from .flags import MessageFlags
from .guild import Guild
from .member import Member
from .mixins import Hashable
from .partial_emoji import PartialEmoji
from .reaction import Reaction
from .sticker import StickerItem
from .threads import Thread
from .utils import escape_mentions, MISSING

if TYPE_CHECKING:
from .types.message import (
Expand Down Expand Up @@ -998,7 +998,7 @@ def is_system(self) -> bool:
)

@utils.cached_slot_property('_cs_system_content')
def system_content(self):
def system_content(self) -> str:
r""":class:`str`: A property that returns the content that is rendered
regardless of the :attr:`Message.type`.

Expand All @@ -1007,29 +1007,31 @@ def system_content(self):
returns an English message denoting the contents of the system message.
"""

return_msg = '' # So that pylint doesn't complain about this being used before it's set

if self.type is MessageType.default:
return self.content
return_msg = self.content

if self.type is MessageType.recipient_add:
if self.channel.type is ChannelType.group:
return f'{self.author.name} added {self.mentions[0].name} to the group.'
return_msg = f'{self.author.name} added {self.mentions[0].name} to the group.'
else:
return f'{self.author.name} added {self.mentions[0].name} to the thread.'
return_msg = f'{self.author.name} added {self.mentions[0].name} to the thread.'

if self.type is MessageType.recipient_remove:
if self.channel.type is ChannelType.group:
return f'{self.author.name} removed {self.mentions[0].name} from the group.'
return_msg = f'{self.author.name} removed {self.mentions[0].name} from the group.'
else:
return f'{self.author.name} removed {self.mentions[0].name} from the thread.'
return_msg = f'{self.author.name} removed {self.mentions[0].name} from the thread.'

if self.type is MessageType.channel_name_change:
return f'{self.author.name} changed the channel name: **{self.content}**'
return_msg = f'{self.author.name} changed the channel name: **{self.content}**'

if self.type is MessageType.channel_icon_change:
return f'{self.author.name} changed the channel icon.'
return_msg = f'{self.author.name} changed the channel icon.'

if self.type is MessageType.pins_add:
return f'{self.author.name} pinned a message to this channel.'
return_msg = f'{self.author.name} pinned a message to this channel.'

if self.type is MessageType.new_member:
formats = [
Expand All @@ -1049,66 +1051,71 @@ def system_content(self):
]

created_at_ms = int(self.created_at.timestamp() * 1000)
return formats[created_at_ms % len(formats)].format(self.author.name)
return_msg = formats[created_at_ms % len(formats)].format(self.author.name)

if self.type is MessageType.premium_guild_subscription:
if not self.content:
return f'{self.author.name} just boosted the server!'
return_msg = f'{self.author.name} just boosted the server!'
else:
return f'{self.author.name} just boosted the server **{self.content}** times!'
return_msg = f'{self.author.name} just boosted the server **{self.content}** times!'

if self.type is MessageType.premium_guild_tier_1:
if not self.content:
return f'{self.author.name} just boosted the server! {self.guild} has achieved **Level 1!**'
return_msg = f'{self.author.name} just boosted the server! {self.guild} has achieved **Level 1!**'
else:
return f'{self.author.name} just boosted the server **{self.content}** times! {self.guild} has achieved **Level 1!**'
return_msg = f'{self.author.name} just boosted the server **{self.content}** times! {self.guild} has achieved **Level 1!**'

if self.type is MessageType.premium_guild_tier_2:
if not self.content:
return f'{self.author.name} just boosted the server! {self.guild} has achieved **Level 2!**'
return_msg = f'{self.author.name} just boosted the server! {self.guild} has achieved **Level 2!**'
else:
return f'{self.author.name} just boosted the server **{self.content}** times! {self.guild} has achieved **Level 2!**'
return_msg = f'{self.author.name} just boosted the server **{self.content}** times! {self.guild} has achieved **Level 2!**'

if self.type is MessageType.premium_guild_tier_3:
if not self.content:
return f'{self.author.name} just boosted the server! {self.guild} has achieved **Level 3!**'
return_msg = f'{self.author.name} just boosted the server! {self.guild} has achieved **Level 3!**'
else:
return f'{self.author.name} just boosted the server **{self.content}** times! {self.guild} has achieved **Level 3!**'
return_msg = f'{self.author.name} just boosted the server **{self.content}** times! {self.guild} has achieved **Level 3!**'

if self.type is MessageType.channel_follow_add:
return f'{self.author.name} has added {self.content} to this channel'
return_msg = f'{self.author.name} has added {self.content} to this channel'

if self.type is MessageType.guild_stream:
# the author will be a Member
return f'{self.author.name} is live! Now streaming {self.author.activity.name}' # type: ignore
return_msg = f'{self.author.name} is live! Now streaming {self.author.activity.name}' # type: ignore

if self.type is MessageType.guild_discovery_disqualified:
return 'This server has been removed from Server Discovery because it no longer passes all the requirements. Check Server Settings for more details.'
return_msg = 'This server has been removed from Server Discovery because it no longer passes all the ' \
'requirements. Check Server Settings for more details.'

if self.type is MessageType.guild_discovery_requalified:
return 'This server is eligible for Server Discovery again and has been automatically relisted!'
return_msg = 'This server is eligible for Server Discovery again and has been automatically relisted!'

if self.type is MessageType.guild_discovery_grace_period_initial_warning:
return 'This server has failed Discovery activity requirements for 1 week. If this server fails for 4 weeks in a row, it will be automatically removed from Discovery.'
return_msg = 'This server has failed Discovery activity requirements for 1 week. If this server fails ' \
'for 4 weeks in a row, it will be automatically removed from Discovery.'

if self.type is MessageType.guild_discovery_grace_period_final_warning:
return 'This server has failed Discovery activity requirements for 3 weeks in a row. If this server fails for 1 more week, it will be removed from Discovery.'
return_msg = 'This server has failed Discovery activity requirements for 3 weeks in a row. If this ' \
'server fails for 1 more week, it will be removed from Discovery.'

if self.type is MessageType.thread_created:
return f'{self.author.name} started a thread: **{self.content}**. See all **threads**.'
return_msg = f'{self.author.name} started a thread: **{self.content}**. See all **threads**.'

if self.type is MessageType.reply:
return self.content
return_msg = self.content

if self.type is MessageType.thread_starter_message:
if self.reference is None or self.reference.resolved is None:
return 'Sorry, we couldn\'t load the first message in this thread'
return_msg = 'Sorry, we couldn\'t load the first message in this thread'

# the resolved message for the reference will be a Message
return self.reference.resolved.content # type: ignore
return_msg = self.reference.resolved.content # type: ignore # pylint: disable=no-member

if self.type is MessageType.guild_invite_reminder:
return 'Wondering who to invite?\nStart by inviting anyone who can help you build the server!'
return_msg = 'Wondering who to invite?\nStart by inviting anyone who can help you build the server!'

return return_msg

async def delete(self, *, delay: Optional[float] = None) -> None:
"""|coro|
Expand Down Expand Up @@ -1152,42 +1159,42 @@ async def delete(delay: float):

@overload
async def edit(
self,
*,
content: Optional[str] = ...,
embed: Optional[Embed] = ...,
attachments: List[Attachment] = ...,
suppress: bool = ...,
delete_after: Optional[float] = ...,
allowed_mentions: Optional[AllowedMentions] = ...,
view: Optional[View] = ...,
self,
*,
content: Optional[str] = ...,
embed: Optional[Embed] = ...,
attachments: List[Attachment] = ...,
suppress: bool = ...,
delete_after: Optional[float] = ...,
allowed_mentions: Optional[AllowedMentions] = ...,
view: Optional[View] = ...,
) -> Message:
...

@overload
async def edit(
self,
*,
content: Optional[str] = ...,
embeds: List[Embed] = ...,
attachments: List[Attachment] = ...,
suppress: bool = ...,
delete_after: Optional[float] = ...,
allowed_mentions: Optional[AllowedMentions] = ...,
view: Optional[View] = ...,
self,
*,
content: Optional[str] = ...,
embeds: List[Embed] = ...,
attachments: List[Attachment] = ...,
suppress: bool = ...,
delete_after: Optional[float] = ...,
allowed_mentions: Optional[AllowedMentions] = ...,
view: Optional[View] = ...,
) -> Message:
...

async def edit(
self,
content: Optional[str] = MISSING,
embed: Optional[Embed] = MISSING,
embeds: List[Embed] = MISSING,
attachments: List[Attachment] = MISSING,
suppress: bool = MISSING,
delete_after: Optional[float] = None,
allowed_mentions: Optional[AllowedMentions] = MISSING,
view: Optional[View] = MISSING,
self,
content: Optional[str] = MISSING,
embed: Optional[Embed] = MISSING,
embeds: List[Embed] = MISSING,
attachments: List[Attachment] = MISSING,
suppress: bool = MISSING,
delete_after: Optional[float] = None,
allowed_mentions: Optional[AllowedMentions] = MISSING,
view: Optional[View] = MISSING,
) -> Message:
"""|coro|

Expand Down Expand Up @@ -1266,8 +1273,8 @@ async def edit(
payload['embeds'] = [e.to_dict() for e in embeds]

if suppress is not MISSING:
flags = MessageFlags._from_value(self.flags.value)
flags.suppress_embeds = suppress
flags = MessageFlags._from_value(self.flags.value) # pylint: disable=protected-access
flags.suppress_embeds = suppress # pylint: disable=assigning-non-slot
payload['flags'] = flags.value

if allowed_mentions is MISSING:
Expand Down Expand Up @@ -1789,7 +1796,7 @@ async def edit(self, **fields: Any) -> Optional[Message]:
except KeyError:
pass
else:
flags = MessageFlags._from_value(0)
flags = MessageFlags._from_value(0) # pylint: disable=protected-access
flags.suppress_embeds = suppress
fields['flags'] = flags.value

Expand Down
10 changes: 5 additions & 5 deletions discord/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

from __future__ import annotations

from . import utils
from .mixins import Hashable

from typing import (
SupportsInt,
TYPE_CHECKING,
Union,
)

from . import utils
from .mixins import Hashable

if TYPE_CHECKING:
import datetime
SupportsIntCast = Union[SupportsInt, str, bytes, bytearray]
Expand Down Expand Up @@ -76,9 +76,9 @@ class Object(Hashable):
The ID of the object.
"""

def __init__(self, id: SupportsIntCast):
def __init__(self, id: SupportsIntCast): # pylint: disable=redefined-builtin
try:
id = int(id)
id = int(id) # pylint: disable=redefined-builtin
except ValueError:
raise TypeError(f'id parameter must be convertible to int not {id.__class__!r}') from None
else:
Expand Down
4 changes: 2 additions & 2 deletions discord/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,10 @@ def _augment_from_permissions(cls):

# god bless Python
def getter(self, x=key):
return self._values.get(x)
return self._values.get(x) # pylint: disable=protected-access

def setter(self, value, x=key):
self._set(x, value)
self._set(x, value) # pylint: disable=protected-access

prop = property(getter, setter)
setattr(cls, name, prop)
Expand Down
16 changes: 8 additions & 8 deletions discord/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ class ConnectionState:
_parsers: Dict[str, Callable[[Dict[str, Any]], None]]

def __init__(
self,
*,
dispatch: Callable,
handlers: Dict[str, Callable],
hooks: Dict[str, Callable],
http: HTTPClient,
loop: asyncio.AbstractEventLoop,
**options: Any,
self,
*,
dispatch: Callable,
handlers: Dict[str, Callable],
hooks: Dict[str, Callable],
http: HTTPClient,
loop: asyncio.AbstractEventLoop,
**options: Any
) -> None:
self.loop: asyncio.AbstractEventLoop = loop
self.http: HTTPClient = http
Expand Down
3 changes: 3 additions & 0 deletions discord/ui/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
)

if TYPE_CHECKING:
# https://github.com/PyCQA/pylint/issues/3525
# pylint: disable=cyclic-import

from .view import View
from ..types.components import SelectMenu as SelectMenuPayload
from ..types.interactions import (
Expand Down
Loading