Skip to content

Commit

Permalink
Upgrade dependencies, Migrate to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanC committed Feb 11, 2024
1 parent 5bc5f7b commit e7fa829
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 453 deletions.
4 changes: 1 addition & 3 deletions loguru_discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
https://github.com/EthanC/Loguru-Discord
"""

from typing import List

from .sink import DiscordSink

__all__: List[str] = ["DiscordSink"]
__all__: list[str] = ["DiscordSink"]
21 changes: 12 additions & 9 deletions loguru_discord/sink.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from logging import Handler, LogRecord
from typing import List, Optional, Self, Any
from typing import Any, Self

from discord_webhook import DiscordEmbed, DiscordWebhook

Expand All @@ -12,10 +12,10 @@ def __init__(
self: Self,
webhookUrl: str,
*,
username: Optional[str] = None,
avatarUrl: Optional[str] = None,
username: str | None = None,
avatarUrl: str | None = None,
embed: bool = False,
suppress: List[Any] = [],
suppress: list[Any] = [],
) -> None:
"""
Initialize a DiscordSink instance.
Expand All @@ -36,10 +36,10 @@ def __init__(
super().__init__()

self.webhookUrl: str = webhookUrl
self.username: Optional[str] = username
self.avatarUrl: Optional[str] = avatarUrl
self.username: str | None = username
self.avatarUrl: str | None = avatarUrl
self.embed: bool = embed
self.suppress: List[Any] = suppress
self.suppress: list[Any] = suppress

self.webhook: DiscordWebhook = DiscordWebhook(
self.webhookUrl,
Expand Down Expand Up @@ -72,6 +72,7 @@ def emit(self: Self, record: LogRecord) -> None:
message: str = record.getMessage()

if not self.embed:
# Content value is restricted to defined character limit.
self.webhook.set_content(f"```py\n{message[:1990]}\n```")
else:
embed: DiscordEmbed = DiscordEmbed()
Expand All @@ -92,10 +93,12 @@ def emit(self: Self, record: LogRecord) -> None:
case _:
pass

embed.set_title(record.levelname)
# Field values are restricted to defined character limits.
# https://discord.com/developers/docs/resources/channel#embed-object-embed-limits
embed.set_title(record.levelname[:256])
embed.set_description(f"```py\n{message[:4086]}\n```")
embed.set_footer(
text=f"{record.filename}:{record.lineno}",
text=f"{record.filename[:2040]}:{record.lineno:,}",
icon_url="https://i.imgur.com/7xeGMSf.png",
)
embed.set_timestamp(record.created)
Expand Down
Loading

0 comments on commit e7fa829

Please sign in to comment.