From 36234091fcecdda318ca15ad43c19fe63b5bf847 Mon Sep 17 00:00:00 2001 From: Dooley_labs Date: Thu, 12 Dec 2024 20:50:38 -0500 Subject: [PATCH] 2024.12.12 - disco.gateway.client: optional `isal` import speed/resource optimization; - disco.voice.client: log voice state changes and negotiated encryption mode on `info` channel instead of `debug`; - disco.state: Optimize state listeners, add `message_create` config toggle for state listeners; --- disco/gateway/client.py | 6 +++++- disco/state.py | 47 +++++++++++++++++++++++++++++++---------- disco/voice/client.py | 4 ++-- requirements.txt | 2 +- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/disco/gateway/client.py b/disco/gateway/client.py index e0e08d2..eb18911 100644 --- a/disco/gateway/client.py +++ b/disco/gateway/client.py @@ -3,7 +3,11 @@ from platform import system as platform_system from time import time, perf_counter_ns as time_perf_counter_ns from websocket import ABNF, WebSocketConnectionClosedException, WebSocketTimeoutException -from zlib import decompress as zlib_decompress, decompressobj as zlib_decompressobj + +try: + from isal.isal_zlib import decompress as zlib_decompress, decompressobj as zlib_decompressobj +except ImportError: + from zlib import decompress as zlib_decompress, decompressobj as zlib_decompressobj from disco.gateway.packets import OPCode, RECV, SEND from disco.gateway.events import GatewayEvent diff --git a/disco/state.py b/disco/state.py index c6e9047..97a9cea 100644 --- a/disco/state.py +++ b/disco/state.py @@ -53,6 +53,7 @@ class StateConfig(Config): to batch requests using the underlying `GatewayClient.request_guild_members` interface. """ + message_create = True track_messages = False track_messages_size = 100 @@ -101,16 +102,7 @@ class State: messages : Optional[dict(snowflake, deque)] Mapping of channel ids to dequeue containing `StackMessage` objects. """ - EVENTS = [ - 'Ready', 'UserUpdate', 'MessageCreate', 'ChannelCreate', 'ChannelDelete', 'ChannelTopicUpdate', 'ChannelUpdate', - 'GuildCreate', 'GuildDelete', 'GuildUpdate', 'GuildEmojisUpdate', 'GuildMemberAdd', 'GuildMemberRemove', - 'GuildMembersChunk', 'GuildMemberUpdate', 'GuildRoleCreate', 'GuildRoleDelete', 'GuildRoleUpdate', - 'GuildScheduledEventCreate', 'GuildScheduledEventDelete', 'GuildScheduledEventUpdate', - 'GuildSoundboardSoundCreate', 'GuildSoundboardSoundDelete', 'GuildSoundboardSoundUpdate', 'GuildStickersUpdate', - 'PresenceUpdate', 'StageInstanceCreate', 'StageInstanceDelete', 'StageInstanceUpdate', 'ThreadCreate', - 'ThreadDelete', 'ThreadListSync', 'ThreadUpdate', 'VoiceChannelStatusUpdate', 'VoiceServerUpdate', - 'VoiceStateUpdate', - ] + EVENTS = ['Ready', 'UserUpdate', 'GuildCreate', 'GuildDelete', 'GuildUpdate', 'VoiceServerUpdate'] def __init__(self, client, config): self.client = client @@ -134,7 +126,40 @@ def __init__(self, client, config): # If message tracking is enabled, listen to those events if self.config.track_messages: self.messages = DefaultHashMap(lambda: deque(maxlen=self.config.track_messages_size)) - self.EVENTS += ['MessageDelete', 'MessageDeleteBulk'] + self.EVENTS += ['MessageDelete', 'MessageDeleteBulk',] + + if self.config.message_create: + self.EVENTS += ['MessageCreate',] + + if self.config.sync_guild_members: + self.EVENTS += ['GuildMemberAdd', 'GuildMemberRemove', 'GuildMembersChunk', 'GuildMemberUpdate', 'PresenceUpdate',] + + if self.config.cache_channels or self.config.cache_dm_channels: + self.EVENTS += ['ChannelCreate', 'ChannelDelete', 'ChannelTopicUpdate', 'ChannelUpdate', 'VoiceChannelStatusUpdate',] + + if self.config.cache_threads: + self.EVENTS += ['ThreadCreate', 'ThreadDelete', 'ThreadListSync', 'ThreadUpdate',] + + if self.config.cache_roles: + self.EVENTS += ['GuildRoleCreate', 'GuildRoleDelete', 'GuildRoleUpdate',] + + if self.config.cache_voice_states: + self.EVENTS += ['VoiceStateUpdate',] + + if self.config.cache_emojis: + self.EVENTS += ['GuildEmojisUpdate',] + + if self.config.cache_stickers: + self.EVENTS += ['GuildStickersUpdate',] + + if self.config.cache_soundboard: + self.EVENTS += ['GuildSoundboardSoundCreate', 'GuildSoundboardSoundDelete', 'GuildSoundboardSoundUpdate',] + + if self.config.cache_scheduled_events: + self.EVENTS += ['GuildScheduledEventCreate', 'GuildScheduledEventDelete', 'GuildScheduledEventUpdate',] + + if self.config.cache_stage_instances: + self.EVENTS += ['StageInstanceCreate', 'StageInstanceDelete', 'StageInstanceUpdate',] # The bound listener objects self.listeners = [] diff --git a/disco/voice/client.py b/disco/voice/client.py index 84a7cc5..3f994d2 100644 --- a/disco/voice/client.py +++ b/disco/voice/client.py @@ -185,7 +185,7 @@ def ssrc_rtcp(self): return self.ssrc + 3 def set_state(self, state): - self.log.debug('[{}] state {} -> {}'.format(self.channel_id or '-', self.state, state)) + self.log.info('[{}] state {} -> {}'.format(self.channel_id or '-', self.state, state)) prev_state = self.state self.state = state self.state_emitter.emit(state, prev_state) @@ -333,7 +333,7 @@ def on_voice_ready(self, data): for mode in self.enc_modes: if mode in self.SUPPORTED_MODES: self.mode = mode - self.log.debug('[{}] Selected mode {}'.format(self.channel_id, mode)) + self.log.info('[{}] Selected mode {}'.format(self.channel_id, mode)) break else: raise Exception('Failed to find a supported voice mode') diff --git a/requirements.txt b/requirements.txt index 2d135a9..bff382b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -gevent==24.10.2 +gevent==24.11.1 requests==2.32.3 websocket-client==1.8.0 \ No newline at end of file