impl: deprecated regions

This commit is contained in:
Luna 2020-02-03 20:01:22 +00:00
parent 41b877fcd0
commit 20bc174ea1
4 changed files with 36 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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