updated stuff
This commit is contained in:
parent
4277f65051
commit
5133a58d6d
@ -84,6 +84,8 @@ __all__ = (
|
|||||||
"escape_mentions",
|
"escape_mentions",
|
||||||
"as_chunks",
|
"as_chunks",
|
||||||
"format_dt",
|
"format_dt",
|
||||||
|
"generate_snowflake",
|
||||||
|
"quick_snowflake"
|
||||||
)
|
)
|
||||||
|
|
||||||
DISCORD_EPOCH = 1420070400000
|
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]:
|
def actual_decorator(func: Callable[P, T]) -> Callable[P, T]:
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def decorated(*args: P.args, **kwargs: P.kwargs) -> T:
|
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:
|
if instead:
|
||||||
fmt = "{0.__name__} is deprecated, use {1} instead."
|
fmt = "{0.__name__} is deprecated, use {1} instead."
|
||||||
else:
|
else:
|
||||||
fmt = "{0.__name__} is deprecated."
|
fmt = "{0.__name__} is deprecated."
|
||||||
|
|
||||||
warnings.warn(fmt.format(func, instead), stacklevel=3, category=DeprecationWarning)
|
warnings.warn(fmt.format(func, instead),
|
||||||
warnings.simplefilter("default", DeprecationWarning) # reset filter
|
stacklevel=3, category=DeprecationWarning)
|
||||||
|
warnings.simplefilter(
|
||||||
|
"default", DeprecationWarning) # reset filter
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
return decorated
|
return decorated
|
||||||
@ -309,7 +314,8 @@ def oauth_url(
|
|||||||
if redirect_uri is not MISSING:
|
if redirect_uri is not MISSING:
|
||||||
from urllib.parse import urlencode
|
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:
|
if disable_guild_select:
|
||||||
url += "&disable_guild_select=true"
|
url += "&disable_guild_select=true"
|
||||||
return url
|
return url
|
||||||
@ -440,7 +446,8 @@ def get(iterable: Iterable[T], **attrs: Any) -> Optional[T]:
|
|||||||
return elem
|
return elem
|
||||||
return None
|
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:
|
for elem in iterable:
|
||||||
if _all(pred(elem) == value for pred, value in converted):
|
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:
|
if use_clock or not reset_after:
|
||||||
utc = datetime.timezone.utc
|
utc = datetime.timezone.utc
|
||||||
now = datetime.datetime.now(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()
|
return (reset - now).total_seconds()
|
||||||
else:
|
else:
|
||||||
return float(reset_after)
|
return float(reset_after)
|
||||||
@ -611,7 +619,8 @@ class SnowflakeList(array.array):
|
|||||||
...
|
...
|
||||||
|
|
||||||
def __new__(cls, data: Iterable[int], *, is_sorted: bool = False):
|
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:
|
def add(self, element: int) -> None:
|
||||||
i = bisect_left(self, element)
|
i = bisect_left(self, element)
|
||||||
@ -694,7 +703,8 @@ def resolve_template(code: Union[Template, str]) -> str:
|
|||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
_MARKDOWN_ESCAPE_SUBREGEX = "|".join(r"\{0}(?=([\s\S]*((?<!\{0})\{0})))".format(c) for c in ("*", "`", "_", "~", "|"))
|
_MARKDOWN_ESCAPE_SUBREGEX = "|".join(
|
||||||
|
r"\{0}(?=([\s\S]*((?<!\{0})\{0})))".format(c) for c in ("*", "`", "_", "~", "|"))
|
||||||
|
|
||||||
_MARKDOWN_ESCAPE_COMMON = r"^>(?:>>)?\s|\[.+\]\(.+\)"
|
_MARKDOWN_ESCAPE_COMMON = r"^>(?:>>)?\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):
|
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:
|
if evaluated_args == args:
|
||||||
return tp
|
return tp
|
||||||
@ -1020,3 +1031,22 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None)
|
|||||||
if style is None:
|
if style is None:
|
||||||
return f"<t:{int(dt.timestamp())}>"
|
return f"<t:{int(dt.timestamp())}>"
|
||||||
return f"<t:{int(dt.timestamp())}:{style}>"
|
return f"<t:{int(dt.timestamp())}:{style}>"
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user