diff --git a/litecord/blueprints/guilds.py b/litecord/blueprints/guilds.py index 14a7056..1c2f2db 100644 --- a/litecord/blueprints/guilds.py +++ b/litecord/blueprints/guilds.py @@ -350,9 +350,7 @@ async def _update_guild(guild_id): ) guild = await app.storage.get_guild_full(guild_id, user_id) - await app.dispatcher.dispatch_guild(guild_id, "GUILD_UPDATE", guild) - return jsonify(guild) diff --git a/litecord/voice/lvsp_conn.py b/litecord/voice/lvsp_conn.py index d7bad73..c0c8726 100644 --- a/litecord/voice/lvsp_conn.py +++ b/litecord/voice/lvsp_conn.py @@ -52,10 +52,12 @@ class LVSPConnection: async def send(self, payload): """Send a payload down the websocket.""" msg = json.dumps(payload) + assert self.conn is not None await self.conn.send(msg) async def recv(self): """Receive a payload.""" + assert self.conn is not None msg = await self.conn.recv() msg = json.dumps(msg) return msg @@ -82,6 +84,8 @@ class LVSPConnection: # give the server 300 milliseconds to reply. await asyncio.sleep(300) + + assert self.conn is not None await self.conn.close(4000, "heartbeat timeout") except asyncio.CancelledError: pass @@ -182,7 +186,7 @@ class LVSPConnection: await self.start() try: - if not self.conn: + if self.conn is None: log.error("failed to start lvsp connection, stopping") return diff --git a/litecord/voice/lvsp_manager.py b/litecord/voice/lvsp_manager.py index e3d15c2..a75a544 100644 --- a/litecord/voice/lvsp_manager.py +++ b/litecord/voice/lvsp_manager.py @@ -169,3 +169,6 @@ class LVSPManager: def region(self, region_id: str) -> Optional[Region]: """Get a :class:`Region` instance""" return self.regions.get(region_id) + + def get_conn(self, hostname: str) -> Optional[LVSPConnection]: + return self.conns.get(hostname) diff --git a/litecord/voice/manager.py b/litecord/voice/manager.py index 1a2367a..008695a 100644 --- a/litecord/voice/manager.py +++ b/litecord/voice/manager.py @@ -60,7 +60,7 @@ class VoiceManager: ctype = ChannelType(channel["type"]) if ctype not in VOICE_CHANNELS: - return + return False states = await self.app.voice.state_count(channel_id) @@ -79,7 +79,7 @@ class VoiceManager: # - user is not manage channels # then it fails if not is_bot and not is_manager and is_full: - return + return False # all good return True @@ -161,6 +161,10 @@ class VoiceManager: return conn = self.lvsp.get_conn(hostname) + if conn is None: + log.error("not connected to server {!r}", hostname) + return + await conn.send_info(info_type, info_data) async def _create_ctx_guild(self, guild_id, channel_id): @@ -263,3 +267,25 @@ class VoiceManager: ) return list(map(dict, rows)) + + async def disable_region(self, region: str) -> None: + """Disable a region.""" + guild_ids = await self.app.db.fetch( + """ + UPDATE guilds + SET region = null + WHERE region = $1 + RETURNING guild_id + """, + region, + ) + + guild_count = len(guild_ids) + log.info("updated {} guilds. region={} to null", guild_count, region) + + # slow, but it be like that, also copied from other users... + for guild_id in guild_ids: + guild = await self.app.storage.get_guild_full(guild_id, None) + await self.app.dispatcher.dispatch_guild(guild_id, "GUILD_UPDATE", guild) + + # TODO propagate the channel deprecation to LVSP connections