Skip to content

feat: add start_time(s) for AutoShardedClient #1482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions interactions/client/auto_shard_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import time
from datetime import datetime
from collections import defaultdict
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -68,6 +69,16 @@ def latencies(self) -> dict[int, float]:
"""
return {state.shard_id: state.latency for state in self._connection_states}

@property
def start_time(self) -> datetime:
"""The start time of the first shard of the bot."""
return next((state.start_time for state in self._connection_states), MISSING) # type: ignore

@property
def start_times(self) -> dict[int, datetime]:
"""The start times of all shards of the bot, keyed by each shard ID."""
return {state.shard_id: state.start_time for state in self._connection_states} # type: ignore

async def stop(self) -> None:
"""Shutdown the bot."""
self.logger.debug("Stopping the bot.")
Expand Down