feat: cache voice channel info from gateway - #3210
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3210/head:pr-3210
git checkout pr-3210This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3210/head |
…o feat/channel-status-gateway # Conflicts: # discord/channel.py
|
Test code I've been using: import asyncio
import discord
import logging
logging.basicConfig(level=logging.DEBUG)
client = discord.Client(cache_channel_info=True, intents=discord.Intents.all(), chunk_guilds_at_startup=False)
@client.event
async def on_ready():
while True:
for channel in client.get_all_channels():
if hasattr(channel, "voice_start_time") and channel.voice_start_time:
print("rec", getattr(channel, "status", ...), channel.voice_start_time)
@client.event
async def on_voice_channel_status_update(channel, old, new):
print("status", channel.status, channel.voice_start_time, old, new)
@client.event
async def on_voice_channel_start_time_update(channel, old, new):
print("start", channel.status, channel.voice_start_time, old, new)
client.run("token") |
…o feat/channel-status-gateway
|
Needs input: API for |
…o feat/channel-status-gateway
Co-authored-by: Paillat <jeremiecotti@ik.me> Signed-off-by: plun1331 <plun1331@gmail.com>
Co-authored-by: plun1331 <plun1331@gmail.com> Signed-off-by: plun1331 <plun1331@gmail.com>
Co-authored-by: Michael <vmphasee@gmail.com> Signed-off-by: plun1331 <plun1331@gmail.com>
Signed-off-by: plun1331 <plun1331@gmail.com>
| """ | ||
| if self._voice_start_time is None: | ||
| return None | ||
| return datetime.datetime.fromtimestamp(self._voice_start_time, tz=datetime.UTC) |
There was a problem hiding this comment.
datetime.UTC was added in Python 3.11 as an alias for datetime.timezone.utc.
Workflow tests don't catch this critical issue because property access is lazy.
| return datetime.datetime.fromtimestamp(self._voice_start_time, tz=datetime.UTC) | |
| return datetime.datetime.fromtimestamp( | |
| self._voice_start_time, | |
| tz=datetime.timezone.utc, | |
| ) |
| self.id: int = int(data["id"]) | ||
| self.guild_id: int = int(data["guild_id"]) | ||
| self.voice_start_time: datetime.datetime | None = ( | ||
| datetime.datetime.fromtimestamp(data["voice_start_time"], tz=datetime.UTC) |
There was a problem hiding this comment.
datetime.UTC was added in Python 3.11 as an alias for datetime.timezone.utc.
Workflow tests don't catch this critical issue because attribute access is lazy.
| datetime.datetime.fromtimestamp(data["voice_start_time"], tz=datetime.UTC) | |
| datetime.datetime.fromtimestamp( | |
| data["voice_start_time"], | |
| tz=datetime.timezone.utc, | |
| ) |
| if not e.resume: | ||
| # Since we aren't resuming, channel info can fall out of date | ||
| # So we re-request it | ||
| self._connection._request_channel_info = True |
There was a problem hiding this comment.
I don't see the _connection._request_channel_info flag being reset to False anywhere.
| import aiohttp | ||
|
|
||
| from . import utils | ||
| from .abc import Snowflake |
There was a problem hiding this comment.
Unused import.
| from .abc import Snowflake |
Summary
https://docs.discord.com/developers/change-log#voice-channel-status-and-start-time-documentation
cache_channel_info, defaultFalse)voice_channel_start_time_updateeventvoice_start_timeto voice channels.statusis stored on voice channels.Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.