Skip to content

Commit

Permalink
Merge branch 'master' into features/voice-receive
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Jan 10, 2022
2 parents 740c41e + e58dd4d commit 88b5943
Show file tree
Hide file tree
Showing 62 changed files with 3,471 additions and 1,443 deletions.
18 changes: 10 additions & 8 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Generally speaking questions are better suited in our resources below.
- The official support server: https://discord.gg/UCXwPR7Pew
- The Discord API server under #python_discord-py: https://discord.gg/discord-api
- [The FAQ in the documentation](https://docs.pycord.dev/en/master/faq.html)
- [StackOverflow's `discord.py` tag](https://stackoverflow.com/questions/tagged/discord.py)
- [StackOverflow's `pycord` tag](https://stackoverflow.com/questions/tagged/pycord)

Please try your best not to ask questions in our issue tracker. Most of them don't belong there unless they provide value to a larger audience.

Expand Down Expand Up @@ -43,12 +43,14 @@ deciding to ignore type checking warnings.

By submitting a pull request, you agree that; 1) You hold the copyright on all submitted code inside said pull request; 2) You agree to transfer all rights to the owner of this repository, and; 3) If you are found to be in fault with any of the above, we shall not be held responsible in any way after the pull request has been merged.

### Git Commit Guidelines
## Git Commit Styling

- Use present tense (e.g. "Add feature" not "Added feature")
- Limit all lines to 72 characters or less.
- Reference issues or pull requests outside of the first line.
- Please use the shorthand `#123` and not the full URL.
- Commits regarding the commands extension must be prefixed with `[commands]`
Not following this guideline could lead to your pull being squashed for a cleaner commit history

If you do not meet any of these guidelines, don't fret. Chances are they will be fixed upon rebasing but please do try to meet them to remove some of the workload.
Some style guides we would recommed using in your pulls:

The [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) style is a very widely used style and a good style to start with.

The [gitmoji](https://gitmoji.dev) style guide would make your pull look more lively and different to others.

We don't limit nor deny your pulls when you're using another style although, please make sure it is appropriate and makes sense in this library.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ body:
- The core library
- discord.ext.commands
- discord.ext.tasks
- discord.ext.pages
- The documentation
validations:
required: true
Expand Down
1 change: 1 addition & 0 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from .commands import *
from .cog import Cog
from .welcome_screen import *
from .scheduled_events import ScheduledEvent, ScheduledEventLocation


class VersionInfo(NamedTuple):
Expand Down
22 changes: 18 additions & 4 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
runtime_checkable,
)

from .scheduled_events import ScheduledEvent
from .iterators import HistoryIterator
from .context_managers import Typing
from .enums import ChannelType
Expand Down Expand Up @@ -211,10 +212,10 @@ def _asdict(self) -> PermissionOverwritePayload:
}

def is_role(self) -> bool:
return self.type == 0
return self.type == self.ROLE

def is_member(self) -> bool:
return self.type == 1
return self.type == self.MEMBER


GCH = TypeVar('GCH', bound='GuildChannel')
Expand Down Expand Up @@ -1035,6 +1036,7 @@ async def create_invite(
max_uses: int = 0,
temporary: bool = False,
unique: bool = True,
target_event: Optional[ScheduledEvent] = None,
target_type: Optional[InviteTarget] = None,
target_user: Optional[User] = None,
target_application_id: Optional[int] = None,
Expand Down Expand Up @@ -1073,11 +1075,20 @@ async def create_invite(
.. versionadded:: 2.0
target_application_id:: Optional[:class:`int`]
target_application_id: Optional[:class:`int`]
The id of the embedded application for the invite, required if `target_type` is `TargetType.embedded_application`.
.. versionadded:: 2.0
target_event: Optional[:class:`ScheduledEvent`]
The scheduled event object to link to the event.
Shortcut to :meth:`Invite.set_scheduled_event`
See :meth:`Invite.set_scheduled_event` for more
info on event invite linking.
.. versionadded:: 2.0
Raises
-------
~discord.HTTPException
Expand All @@ -1103,7 +1114,10 @@ async def create_invite(
target_user_id=target_user.id if target_user else None,
target_application_id=target_application_id,
)
return Invite.from_incomplete(data=data, state=self._state)
invite = Invite.from_incomplete(data=data, state=self._state)
if target_event:
invite.set_scheduled_event(target_event)
return invite

async def invites(self) -> List[Invite]:
"""|coro|
Expand Down
10 changes: 8 additions & 2 deletions discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,17 @@ def _from_cover_image(cls, state, object_id: int, cover_image_hash: str) -> Asse

@classmethod
def _from_guild_image(cls, state, guild_id: int, image: str, path: str) -> Asset:
animated = False
format = "png"
if path == "banners":
animated = image.startswith("a_")
format = "gif" if animated else "png"

return cls(
state,
url=f'{cls.BASE}/{path}/{guild_id}/{image}.png?size=1024',
url=f"{cls.BASE}/{path}/{guild_id}/{image}.{format}?size=1024",
key=image,
animated=False,
animated=animated,
)

@classmethod
Expand Down
31 changes: 27 additions & 4 deletions discord/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
from .stage_instance import StageInstance
from .sticker import GuildSticker
from .threads import Thread
from .scheduled_events import ScheduledEvent
from .state import ConnectionState


def _transform_permissions(entry: AuditLogEntry, data: str) -> Permissions:
Expand Down Expand Up @@ -147,7 +149,7 @@ def _transform(entry: AuditLogEntry, data: int) -> T:

return _transform

def _transform_type(entry: AuditLogEntry, data: Union[int]) -> Union[enums.ChannelType, enums.StickerType]:
def _transform_type(entry: AuditLogEntry, data: int) -> Union[enums.ChannelType, enums.StickerType]:
if entry.action.name.startswith('sticker_'):
return enums.try_enum(enums.StickerType, data)
else:
Expand Down Expand Up @@ -210,14 +212,16 @@ class AuditLogChanges:
'privacy_level': (None, _enum_transformer(enums.StagePrivacyLevel)),
'format_type': (None, _enum_transformer(enums.StickerFormatType)),
'type': (None, _transform_type),
'status': (None, _enum_transformer(enums.ScheduledEventStatus)),
'entity_type': ('location_type', _enum_transformer(enums.ScheduledEventLocationType)),
}
# fmt: on

def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]):
def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload], *, state: ConnectionState):
self.before = AuditLogDiff()
self.after = AuditLogDiff()

for elem in data:
for elem in sorted(data, key=lambda i: i['key']):
attr = elem['key']

# special cases for role add/remove
Expand Down Expand Up @@ -246,6 +250,14 @@ def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]):
if transformer:
before = transformer(entry, before)

if attr == 'location':
if hasattr(self.before, 'location_type'):
from .scheduled_events import ScheduledEventLocation
if self.before.location_type is enums.ScheduledEventLocationType.external:
before = ScheduledEventLocation(state=state, value=before)
elif hasattr(self.before, 'channel'):
before = ScheduledEventLocation(state=state, value=self.before.channel)

setattr(self.before, attr, before)

try:
Expand All @@ -256,6 +268,14 @@ def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]):
if transformer:
after = transformer(entry, after)

if attr == 'location':
if hasattr(self.after, 'location_type'):
from .scheduled_events import ScheduledEventLocation
if self.after.location_type is enums.ScheduledEventLocationType.external:
after = ScheduledEventLocation(state=state, value=after)
elif hasattr(self.after, 'channel'):
after = ScheduledEventLocation(state=state, value=self.after.channel)

setattr(self.after, attr, after)

# add an alias
Expand Down Expand Up @@ -463,7 +483,7 @@ def category(self) -> enums.AuditLogActionCategory:
@utils.cached_property
def changes(self) -> AuditLogChanges:
""":class:`AuditLogChanges`: The list of changes this entry has."""
obj = AuditLogChanges(self, self._changes)
obj = AuditLogChanges(self, self._changes, state=self._state)
del self._changes
return obj

Expand Down Expand Up @@ -523,3 +543,6 @@ def _convert_target_sticker(self, target_id: int) -> Union[GuildSticker, Object]

def _convert_target_thread(self, target_id: int) -> Union[Thread, Object]:
return self.guild.get_thread(target_id) or Object(id=target_id)

def _convert_target_scheduled_event(self, target_id: int) -> Union[ScheduledEvent, None]:
return self.guild.get_scheduled_event(target_id) or Object(id=target_id)
Loading

0 comments on commit 88b5943

Please sign in to comment.