Skip to content

Commit 09a11a9

Browse files
committed
♻️ move snowflake_time function to public.py
1 parent 0cdcb31 commit 09a11a9

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

discord/interactions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import asyncio
2929
from typing import TYPE_CHECKING, Any, Coroutine, Union
3030

31-
from .utils.private import get_as_snowflake
31+
from .utils.private import get_as_snowflake, deprecated
3232
from . import utils
3333
from .channel import ChannelType, PartialMessageable, _threaded_channel_factory
3434
from .enums import (
@@ -292,7 +292,7 @@ def is_component(self) -> bool:
292292
return self.type == InteractionType.component
293293

294294
@utils.cached_slot_property("_cs_channel")
295-
@discord.utils.private.deprecated("Interaction.channel", "2.7", stacklevel=4)
295+
@deprecated("Interaction.channel", "2.7", stacklevel=4)
296296
def cached_channel(self) -> InteractionChannel | None:
297297
"""The cached channel from which the interaction was sent.
298298
DM channels are not resolved. These are :class:`PartialMessageable` instead.
@@ -428,7 +428,7 @@ async def original_response(self) -> InteractionMessage:
428428
self._original_response = message
429429
return message
430430

431-
@discord.utils.private.deprecated("Interaction.original_response", "2.2")
431+
@deprecated("Interaction.original_response", "2.2")
432432
async def original_message(self):
433433
"""An alias for :meth:`original_response`.
434434
@@ -555,7 +555,7 @@ async def edit_original_response(
555555

556556
return message
557557

558-
@discord.utils.private.deprecated("Interaction.edit_original_response", "2.2")
558+
@deprecated("Interaction.edit_original_response", "2.2")
559559
async def edit_original_message(self, **kwargs):
560560
"""An alias for :meth:`edit_original_response`.
561561
@@ -613,7 +613,7 @@ async def delete_original_response(self, *, delay: float | None = None) -> None:
613613
else:
614614
await func
615615

616-
@discord.utils.private.deprecated("Interaction.delete_original_response", "2.2")
616+
@deprecated("Interaction.delete_original_response", "2.2")
617617
async def delete_original_message(self, **kwargs):
618618
"""An alias for :meth:`delete_original_response`.
619619
@@ -1238,7 +1238,7 @@ async def send_modal(self, modal: Modal) -> Interaction:
12381238
self._parent._state.store_modal(modal, self._parent.user.id)
12391239
return self._parent
12401240

1241-
@discord.utils.private.deprecated("a button with type ButtonType.premium", "2.6")
1241+
@deprecated("a button with type ButtonType.premium", "2.6")
12421242
async def premium_required(self) -> Interaction:
12431243
"""|coro|
12441244

discord/utils/__init__.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
)
5959

6060
from ..errors import HTTPException
61-
from .public import basic_autocomplete, generate_snowflake, utcnow
61+
from .public import basic_autocomplete, generate_snowflake, utcnow, snowflake_time
6262

6363
try:
6464
import msgspec
@@ -288,23 +288,6 @@ def oauth_url(
288288
return url
289289

290290

291-
def snowflake_time(id: int) -> datetime.datetime:
292-
"""Converts a Discord snowflake ID to a UTC-aware datetime object.
293-
294-
Parameters
295-
----------
296-
id: :class:`int`
297-
The snowflake ID.
298-
299-
Returns
300-
-------
301-
:class:`datetime.datetime`
302-
An aware datetime in UTC representing the creation time of the snowflake.
303-
"""
304-
timestamp = ((id >> 22) + DISCORD_EPOCH) / 1000
305-
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
306-
307-
308291
def find(predicate: Callable[[T], Any], seq: Iterable[T]) -> T | None:
309292
"""A helper to return the first element found in the sequence
310293
that meets the predicate. For example: ::

discord/utils/public.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from collections.abc import Awaitable, Callable, Iterable
77
from typing import TYPE_CHECKING, Any, Literal
88

9+
from . import DISCORD_EPOCH
10+
911
if TYPE_CHECKING:
1012
from ..commands.context import AutocompleteContext
1113
from ..commands.options import OptionChoice
@@ -176,3 +178,20 @@ def generate_snowflake(
176178
return (discord_millis << 22) + (2**22 - 1 if high else 0)
177179
else:
178180
raise ValueError(f"Invalid mode '{mode}'. Must be 'realistic' or 'boundary'")
181+
182+
183+
def snowflake_time(id: int) -> datetime.datetime:
184+
"""Converts a Discord snowflake ID to a UTC-aware datetime object.
185+
186+
Parameters
187+
----------
188+
id: :class:`int`
189+
The snowflake ID.
190+
191+
Returns
192+
-------
193+
:class:`datetime.datetime`
194+
An aware datetime in UTC representing the creation time of the snowflake.
195+
"""
196+
timestamp = ((id >> 22) + DISCORD_EPOCH) / 1000
197+
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)

0 commit comments

Comments
 (0)