Skip to content

Commit

Permalink
Add Discord webhook message throttling to prevent excessive requests
Browse files Browse the repository at this point in the history
  • Loading branch information
raimannma committed Jan 14, 2025
1 parent 1e63936 commit c117a50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions deadlock_data_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@

STEAM_ID_64_IDENT = 76561197960265728

last_discord_msg_timestamp: None | datetime = None


def send_webhook_message(message: str):
global last_discord_msg_timestamp
if not CONFIG.discord_webhook_url:
LOGGER.warning("No Discord webhook URL provided")
return
if last_discord_msg_timestamp and (datetime.now() - last_discord_msg_timestamp).seconds < 5:
LOGGER.warning("Throttling Discord webhook messages")
return
webhook = DiscordWebhook(url=CONFIG.discord_webhook_url, content=message)
LOGGER.info(f"Sending webhook message: {message}")
webhook.execute()
last_discord_msg_timestamp = datetime.now()


def is_valid_uuid(value: str | None) -> bool:
Expand Down
24 changes: 12 additions & 12 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c117a50

Please sign in to comment.