Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils function for snowflake worker and process ids, with increment #770

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,21 @@ def created_at(self) -> datetime:
""":class:`datetime.datetime`: Returns the channel's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the channel's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the channel's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the channel's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def jump_url(self) -> str:
""":class:`str`: Returns a URL that allows the client to jump to the channel.
Expand Down
30 changes: 30 additions & 0 deletions discord/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,21 @@ def created_at(self) -> datetime:
"""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the application's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the application's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the application's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def icon(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Retrieves the application's icon asset, if any."""
Expand Down Expand Up @@ -3755,6 +3770,21 @@ def created_at(self) -> datetime:
"""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the application's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the application's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the application's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def icon(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Retrieves the application's icon asset, if any."""
Expand Down
15 changes: 15 additions & 0 deletions discord/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,21 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the entry's creation time in UTC."""
return utils.snowflake_time(self.id)

@utils.cached_property
def worker_id(self) -> int:
""":class:`int`: Returns the entry's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@utils.cached_property
def process_id(self) -> int:
""":class:`int`: Returns the entry's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@utils.cached_property
def increment(self) -> int:
""":class:`int`: Returns the entry's snowflake increment."""
return utils.snowflake_increment(self.id)

@utils.cached_property
def target(self) -> TargetType:
if self.action.target_type is None:
Expand Down
45 changes: 45 additions & 0 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3639,6 +3639,21 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the direct message channel's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the direct message channel's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the direct message channel's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the direct message channel's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def guild(self) -> Optional[Guild]:
"""Optional[:class:`Guild`]: The guild this DM channel belongs to. Always ``None``.
Expand Down Expand Up @@ -4115,6 +4130,21 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the channel's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the channel's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the channel's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the channel's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def jump_url(self) -> str:
""":class:`str`: Returns a URL that allows the client to jump to the channel.
Expand Down Expand Up @@ -4564,6 +4594,21 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the channel's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the channel's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the channel's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the channel's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def read_state(self) -> ReadState:
""":class:`ReadState`: Returns the read state for this channel.
Expand Down
15 changes: 15 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,21 @@ def created_at(self) -> datetime:
""":class:`datetime.datetime`: Returns the guild's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the guild's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the guild's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the guild's snowflake increment."""
return utils.snowflake_increment(self.id)

def get_member_named(self, name: str, /) -> Optional[Member]:
"""Returns the first member found that matches the name provided.

Expand Down
33 changes: 32 additions & 1 deletion discord/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .object import Object
from .scheduled_event import ScheduledEvent
from .stage_instance import StageInstance
from .utils import MISSING, _generate_session_id, _get_as_snowflake, parse_time, snowflake_time
from .utils import MISSING, _generate_session_id, _get_as_snowflake, parse_time, snowflake_time, snowflake_process_id, snowflake_increment, snowflake_worker_id
from .welcome_screen import WelcomeScreen

__all__ = (
Expand Down Expand Up @@ -152,6 +152,21 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the channel's creation time in UTC."""
return snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the channel's snowflake worker ID."""
return snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the channel's snowflake process ID."""
return snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the channel's snowflake increment."""
return snowflake_increment(self.id)

@property
def icon(self) -> Optional[Asset]:
"""Optional[:class:`Asset`]: Returns the channel's icon asset if available.
Expand Down Expand Up @@ -258,6 +273,22 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the guild's creation time in UTC."""
return snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the guild's snowflake worker ID."""
return snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the guild's snowflake process ID."""
return snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the guild's snowflake increment."""
return snowflake_increment(self.id)


@property
def vanity_url(self) -> Optional[str]:
"""Optional[:class:`str`]: The Discord vanity invite URL for this partial guild, if available.
Expand Down
31 changes: 31 additions & 0 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,21 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: The partial message's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the message's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the message's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the message's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def jump_url(self) -> str:
""":class:`str`: Returns a URL that allows the client to jump to this message."""
Expand Down Expand Up @@ -2408,6 +2423,22 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: The message's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the message's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the message's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the message's snowflake increment."""
return utils.snowflake_increment(self.id)


@property
def edited_at(self) -> Optional[datetime.datetime]:
"""Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the message."""
Expand Down
16 changes: 15 additions & 1 deletion discord/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from __future__ import annotations

from .mixins import Hashable
from .utils import snowflake_time, MISSING
from .utils import snowflake_time, MISSING, snowflake_worker_id, snowflake_increment, snowflake_process_id

from typing import (
SupportsInt,
Expand Down Expand Up @@ -113,5 +113,19 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the snowflake's creation time in UTC."""
return snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the object's snowflake worker ID."""
return snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the object's snowflake process ID."""
return snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the object's snowflake increment."""
return snowflake_increment(self.id)

OLDEST_OBJECT = Object(id=0)
18 changes: 18 additions & 0 deletions discord/partial_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ def created_at(self) -> Optional[datetime]:

return utils.snowflake_time(self.id)

@property
def worker_id(self) -> Optional[int]:
""":class:`int`: Returns the emoji's snowflake worker ID."""
if self.id:
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> Optional[int]:
""":class:`int`: Returns the emoji's snowflake process ID."""
if self.id:
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> Optional[int]:
""":class:`int`: Returns the emoji's snowflake increment."""
if self.id:
return utils.snowflake_increment(self.id)

@property
def url(self) -> str:
""":class:`str`: Returns the URL of the emoji, if it is custom.
Expand Down
15 changes: 15 additions & 0 deletions discord/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ def created_at(self) -> datetime:
"""
return utils.snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the application's snowflake worker ID."""
return utils.snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the application's snowflake process ID."""
return utils.snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the application's snowflake increment."""
return utils.snowflake_increment(self.id)

@property
def flags(self) -> ApplicationFlags:
""":class:`ApplicationFlags`: The flags of this application."""
Expand Down
17 changes: 16 additions & 1 deletion discord/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .flags import RoleFlags
from .mixins import Hashable
from .permissions import Permissions
from .utils import MISSING, _bytes_to_base64_data, _get_as_snowflake, snowflake_time
from .utils import MISSING, _bytes_to_base64_data, _get_as_snowflake, snowflake_time, snowflake_increment, snowflake_worker_id, snowflake_process_id

__all__ = (
'RoleTags',
Expand Down Expand Up @@ -367,6 +367,21 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the role's creation time in UTC."""
return snowflake_time(self.id)

@property
def worker_id(self) -> int:
""":class:`int`: Returns the role's snowflake worker ID."""
return snowflake_worker_id(self.id)

@property
def process_id(self) -> int:
""":class:`int`: Returns the role's snowflake process ID."""
return snowflake_process_id(self.id)

@property
def increment(self) -> int:
""":class:`int`: Returns the role's snowflake increment."""
return snowflake_increment(self.id)

@property
def mention(self) -> str:
""":class:`str`: Returns a string that allows you to mention a role."""
Expand Down
Loading