From 5133a58d6d50f6dc9b65af3040fbce7e5f44f5a9 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Sun, 3 Oct 2021 22:00:17 -0400 Subject: [PATCH 01/18] updated stuff --- discord/utils.py | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 7908b5ec..ee224987 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -84,6 +84,8 @@ __all__ = ( "escape_mentions", "as_chunks", "format_dt", + "generate_snowflake", + "quick_snowflake" ) DISCORD_EPOCH = 1420070400000 @@ -248,14 +250,17 @@ def deprecated(instead: Optional[str] = None) -> Callable[[Callable[P, T]], Call def actual_decorator(func: Callable[P, T]) -> Callable[P, T]: @functools.wraps(func) def decorated(*args: P.args, **kwargs: P.kwargs) -> T: - warnings.simplefilter("always", DeprecationWarning) # turn off filter + warnings.simplefilter( + "always", DeprecationWarning) # turn off filter if instead: fmt = "{0.__name__} is deprecated, use {1} instead." else: fmt = "{0.__name__} is deprecated." - warnings.warn(fmt.format(func, instead), stacklevel=3, category=DeprecationWarning) - warnings.simplefilter("default", DeprecationWarning) # reset filter + warnings.warn(fmt.format(func, instead), + stacklevel=3, category=DeprecationWarning) + warnings.simplefilter( + "default", DeprecationWarning) # reset filter return func(*args, **kwargs) return decorated @@ -309,7 +314,8 @@ def oauth_url( if redirect_uri is not MISSING: from urllib.parse import urlencode - url += "&response_type=code&" + urlencode({"redirect_uri": redirect_uri}) + url += "&response_type=code&" + \ + urlencode({"redirect_uri": redirect_uri}) if disable_guild_select: url += "&disable_guild_select=true" return url @@ -440,7 +446,8 @@ def get(iterable: Iterable[T], **attrs: Any) -> Optional[T]: return elem return None - converted = [(attrget(attr.replace("__", ".")), value) for attr, value in attrs.items()] + converted = [(attrget(attr.replace("__", ".")), value) + for attr, value in attrs.items()] for elem in iterable: if _all(pred(elem) == value for pred, value in converted): @@ -501,7 +508,8 @@ def _parse_ratelimit_header(request: Any, *, use_clock: bool = False) -> float: if use_clock or not reset_after: utc = datetime.timezone.utc now = datetime.datetime.now(utc) - reset = datetime.datetime.fromtimestamp(float(request.headers["X-Ratelimit-Reset"]), utc) + reset = datetime.datetime.fromtimestamp( + float(request.headers["X-Ratelimit-Reset"]), utc) return (reset - now).total_seconds() else: return float(reset_after) @@ -611,7 +619,8 @@ class SnowflakeList(array.array): ... def __new__(cls, data: Iterable[int], *, is_sorted: bool = False): - return array.array.__new__(cls, "Q", data if is_sorted else sorted(data)) # type: ignore + # type: ignore + return array.array.__new__(cls, "Q", data if is_sorted else sorted(data)) def add(self, element: int) -> None: i = bisect_left(self, element) @@ -694,7 +703,8 @@ def resolve_template(code: Union[Template, str]) -> str: return code -_MARKDOWN_ESCAPE_SUBREGEX = "|".join(r"\{0}(?=([\s\S]*((?(?:>>)?\s|\[.+\]\(.+\)" @@ -944,7 +954,8 @@ def evaluate_annotation( ) if is_literal and not all(isinstance(x, (str, int, bool, type(None))) for x in evaluated_args): - raise TypeError("Literal arguments must be of type str, int, bool, or NoneType.") + raise TypeError( + "Literal arguments must be of type str, int, bool, or NoneType.") if evaluated_args == args: return tp @@ -1020,3 +1031,22 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) if style is None: return f"" return f"" + + +def generate_snowflake(dt: datetime.datetime) -> int: + """ + ----------- + dt: :class:`datetime.datetime` + A datetime object to convert to a snowflake. + If naive, the timezone is assumed to be local time. + Returns :class:`int` as The snowflake representing the time given. + """ + + return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff + + +def quick_snowflake() -> int: + """:class:`int` Returns with The snowflake representing a snowflake from the immediate time. + """ + + return int(utcnow().timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff -- 2.47.2 From 5963ec05cad9d7ea87cfc13e9289065993245768 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Sun, 3 Oct 2021 22:45:08 -0400 Subject: [PATCH 02/18] Update utils.py --- discord/utils.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index ee224987..fe311015 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1034,19 +1034,21 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) def generate_snowflake(dt: datetime.datetime) -> int: - """ - ----------- - dt: :class:`datetime.datetime` - A datetime object to convert to a snowflake. - If naive, the timezone is assumed to be local time. - Returns :class:`int` as The snowflake representing the time given. - """ + ##""" + #----------- + #dt: :class:`datetime.datetime` + #A datetime object to convert to a snowflake. + #If naive, the timezone is assumed to be local time. + #Returns :class:`int` as The snowflake representing the time given. + #""" + + return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff def quick_snowflake() -> int: - """:class:`int` Returns with The snowflake representing a snowflake from the immediate time. - """ + #""":class:`int` Returns with The snowflake representing a snowflake from the immediate time. + #""" return int(utcnow().timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff -- 2.47.2 From dea01b189b794a914811e4f3e995ba9f0845398f Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Sun, 3 Oct 2021 22:49:08 -0400 Subject: [PATCH 03/18] test --- discord/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index fe311015..1721cde4 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1044,11 +1044,18 @@ def generate_snowflake(dt: datetime.datetime) -> int: + + return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff def quick_snowflake() -> int: - #""":class:`int` Returns with The snowflake representing a snowflake from the immediate time. - #""" + """A helper function to return a snowflake from the current UTC time. + + Returns + -------- + :class:`int` + The snowflake generated from the current time using utcnow. + """ return int(utcnow().timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff -- 2.47.2 From 675e3250e23e08797ecafe81d8a511a85c36328b Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Sun, 3 Oct 2021 22:55:43 -0400 Subject: [PATCH 04/18] hmmm --- discord/utils.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 1721cde4..14b4b59b 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1034,17 +1034,19 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) def generate_snowflake(dt: datetime.datetime) -> int: - ##""" - #----------- - #dt: :class:`datetime.datetime` - #A datetime object to convert to a snowflake. - #If naive, the timezone is assumed to be local time. - #Returns :class:`int` as The snowflake representing the time given. - #""" - - + """Returns a numeric snowflake pretending to be created at the given date but more accurate and random than snowflake_time. + Parameters + ----------- + dt: :class:`datetime.datetime` + A datetime object to convert to a snowflake. + If naive, the timezone is assumed to be local time. + Returns + -------- + :class:`int` + The snowflake representing the time given. + """ return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff -- 2.47.2 From 8bb8283ea8fdd66bd50af9b845b5bae39dbbe64a Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Sun, 3 Oct 2021 22:57:10 -0400 Subject: [PATCH 05/18] okay --- discord/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index 14b4b59b..581a8121 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1034,7 +1034,7 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) def generate_snowflake(dt: datetime.datetime) -> int: - """Returns a numeric snowflake pretending to be created at the given date but more accurate and random than snowflake_time. + """Returns a numeric snowflake pretending to be created at the given date but more accurate and random than time_snowflake. Parameters ----------- -- 2.47.2 From c360611927dc0dfa789c8f79b813ae0fb934eafa Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Mon, 4 Oct 2021 09:43:20 -0400 Subject: [PATCH 06/18] let's see if this generates. --- docs/api.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index 5fc56af1..b727b3c7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1136,6 +1136,12 @@ Utility Functions .. autofunction:: discord.utils.as_chunks +.. autofunction:: discord.utils.time_snowflake + +.. autofunction:: discord.utils.generate_snowflake + +.. autofunction:: discord.utils.quick_snowflake + .. _discord-api-enums: Enumerations -- 2.47.2 From 655692d2cc4df8d114bfc67b6e1b010b5f6053d0 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Mon, 4 Oct 2021 09:45:33 -0400 Subject: [PATCH 07/18] cool --- discord/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index 581a8121..ab852ae8 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1052,7 +1052,7 @@ def generate_snowflake(dt: datetime.datetime) -> int: def quick_snowflake() -> int: - """A helper function to return a snowflake from the current UTC time. + """A helper function to return a snowflake from the current UTC time with some randomness to make it more unique. Returns -------- -- 2.47.2 From 6a9083a504f003fdf41feadea60e6fb8b41cfa59 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Mon, 4 Oct 2021 13:53:24 -0400 Subject: [PATCH 08/18] Makes this optional I am doing this via mobile I will check on my computer later --- discord/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index ab852ae8..e8e7cd64 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1033,7 +1033,7 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) return f"" -def generate_snowflake(dt: datetime.datetime) -> int: +def generate_snowflake(dt: Optional[datetime.datetime] = None) -> int: """Returns a numeric snowflake pretending to be created at the given date but more accurate and random than time_snowflake. Parameters -- 2.47.2 From d2837a34f3fc018b8c3d0a785bdde7bfe60cab94 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Mon, 4 Oct 2021 14:04:41 -0400 Subject: [PATCH 09/18] Adds the Dt function thing Again on mobile --- discord/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index e8e7cd64..f8dc5f09 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -85,7 +85,6 @@ __all__ = ( "as_chunks", "format_dt", "generate_snowflake", - "quick_snowflake" ) DISCORD_EPOCH = 1420070400000 @@ -1047,7 +1046,7 @@ def generate_snowflake(dt: Optional[datetime.datetime] = None) -> int: :class:`int` The snowflake representing the time given. """ - + dt = dt or utcnow() return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff -- 2.47.2 From 343d533640baf2ded1b3123902bc34a2a24fe4c1 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Mon, 4 Oct 2021 22:03:55 -0400 Subject: [PATCH 10/18] removed quick_snowflake to merge it into what is wanted. --- docs/api.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index b727b3c7..7d5bb335 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1140,8 +1140,6 @@ Utility Functions .. autofunction:: discord.utils.generate_snowflake -.. autofunction:: discord.utils.quick_snowflake - .. _discord-api-enums: Enumerations -- 2.47.2 From 2bd28a799067705749d4c889ef8819f2896808e4 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Mon, 4 Oct 2021 22:07:49 -0400 Subject: [PATCH 11/18] should work with utils. --- discord/utils.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index f8dc5f09..3892de15 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1034,6 +1034,7 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) def generate_snowflake(dt: Optional[datetime.datetime] = None) -> int: """Returns a numeric snowflake pretending to be created at the given date but more accurate and random than time_snowflake. + If No dt is not passed, it makes one from the current time using utcnow. Parameters ----------- @@ -1046,17 +1047,6 @@ def generate_snowflake(dt: Optional[datetime.datetime] = None) -> int: :class:`int` The snowflake representing the time given. """ + dt = dt or utcnow() - return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff - - -def quick_snowflake() -> int: - """A helper function to return a snowflake from the current UTC time with some randomness to make it more unique. - - Returns - -------- - :class:`int` - The snowflake generated from the current time using utcnow. - """ - - return int(utcnow().timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff + return int(dt.timestamp() * 1000 - DISCORD_EPOCH) << 22 | 0x3fffff \ No newline at end of file -- 2.47.2 From e9850566e8459d0fff9b2a9b374ab4052f89db40 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Wed, 27 Oct 2021 09:10:51 -0400 Subject: [PATCH 12/18] should fix that a tiny bit. --- discord/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 3892de15..0e4ce0c6 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -953,8 +953,7 @@ def evaluate_annotation( ) if is_literal and not all(isinstance(x, (str, int, bool, type(None))) for x in evaluated_args): - raise TypeError( - "Literal arguments must be of type str, int, bool, or NoneType.") + raise TypeError("Literal arguments must be of type str, int, bool, or NoneType.") if evaluated_args == args: return tp -- 2.47.2 From 7331957ee47443fd20e8c1bfcc305142ebf8edce Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Wed, 27 Oct 2021 09:12:26 -0400 Subject: [PATCH 13/18] okay one more change --- discord/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 0e4ce0c6..5257b57d 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -702,8 +702,7 @@ def resolve_template(code: Union[Template, str]) -> str: return code -_MARKDOWN_ESCAPE_SUBREGEX = "|".join( - r"\{0}(?=([\s\S]*((?(?:>>)?\s|\[.+\]\(.+\)" -- 2.47.2 From 0e5cf0f840f91e663b0e8f9c2b00a086c54f4ccd Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Wed, 27 Oct 2021 09:13:39 -0400 Subject: [PATCH 14/18] okay --- discord/utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 5257b57d..71d1e622 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -249,17 +249,14 @@ def deprecated(instead: Optional[str] = None) -> Callable[[Callable[P, T]], Call def actual_decorator(func: Callable[P, T]) -> Callable[P, T]: @functools.wraps(func) def decorated(*args: P.args, **kwargs: P.kwargs) -> T: - warnings.simplefilter( - "always", DeprecationWarning) # turn off filter + warnings.simplefilter("always", DeprecationWarning) # turn off filter if instead: fmt = "{0.__name__} is deprecated, use {1} instead." else: fmt = "{0.__name__} is deprecated." - warnings.warn(fmt.format(func, instead), - stacklevel=3, category=DeprecationWarning) - warnings.simplefilter( - "default", DeprecationWarning) # reset filter + warnings.warn(fmt.format(func, instead), stacklevel=3, category=DeprecationWarning) + warnings.simplefilter("default", DeprecationWarning) # reset filter return func(*args, **kwargs) return decorated -- 2.47.2 From 061b2e3d90078893778e211a828becc8443e55f8 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Wed, 27 Oct 2021 09:15:04 -0400 Subject: [PATCH 15/18] ok --- discord/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 71d1e622..27f53e48 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -310,8 +310,7 @@ def oauth_url( if redirect_uri is not MISSING: from urllib.parse import urlencode - url += "&response_type=code&" + \ - urlencode({"redirect_uri": redirect_uri}) + url += "&response_type=code&" + urlencode({"redirect_uri": redirect_uri}) if disable_guild_select: url += "&disable_guild_select=true" return url -- 2.47.2 From da5ee84abe41a105cbe2037b53946cc40254092e Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Wed, 27 Oct 2021 09:15:38 -0400 Subject: [PATCH 16/18] ok --- discord/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 27f53e48..caa9b5dc 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -441,8 +441,7 @@ def get(iterable: Iterable[T], **attrs: Any) -> Optional[T]: return elem return None - converted = [(attrget(attr.replace("__", ".")), value) - for attr, value in attrs.items()] + converted = [(attrget(attr.replace("__", ".")), value) for attr, value in attrs.items()] for elem in iterable: if _all(pred(elem) == value for pred, value in converted): -- 2.47.2 From c743034e99b3d2ddc39b7430c03240d21fc152f0 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Wed, 27 Oct 2021 09:17:20 -0400 Subject: [PATCH 17/18] should fix it like gnome wants. --- discord/utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index caa9b5dc..6f8f5e36 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -502,8 +502,7 @@ def _parse_ratelimit_header(request: Any, *, use_clock: bool = False) -> float: if use_clock or not reset_after: utc = datetime.timezone.utc now = datetime.datetime.now(utc) - reset = datetime.datetime.fromtimestamp( - float(request.headers["X-Ratelimit-Reset"]), utc) + reset = datetime.datetime.fromtimestamp(float(request.headers["X-Ratelimit-Reset"]), utc) return (reset - now).total_seconds() else: return float(reset_after) @@ -613,8 +612,7 @@ class SnowflakeList(array.array): ... def __new__(cls, data: Iterable[int], *, is_sorted: bool = False): - # type: ignore - return array.array.__new__(cls, "Q", data if is_sorted else sorted(data)) + return array.array.__new__(cls, "Q", data if is_sorted else sorted(data)) # type: ignore def add(self, element: int) -> None: i = bisect_left(self, element) -- 2.47.2 From 46d621564688807d38fe66ee7c16764746804d19 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Wed, 27 Oct 2021 09:58:12 -0400 Subject: [PATCH 18/18] Update api.rst --- docs/api.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 7d5bb335..ca6c9777 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1136,8 +1136,6 @@ Utility Functions .. autofunction:: discord.utils.as_chunks -.. autofunction:: discord.utils.time_snowflake - .. autofunction:: discord.utils.generate_snowflake .. _discord-api-enums: -- 2.47.2