Merge branch 'impl/deprecated-regions' into 'master'

impl: deprecated regions

Closes #79

See merge request litecord/litecord!57
This commit is contained in:
Luna 2020-02-03 20:01:22 +00:00
commit 67a8ae4ce2
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) guild = await app.storage.get_guild_full(guild_id, user_id)
await app.dispatcher.dispatch_guild(guild_id, "GUILD_UPDATE", guild) await app.dispatcher.dispatch_guild(guild_id, "GUILD_UPDATE", guild)
return jsonify(guild) return jsonify(guild)

View File

@ -52,10 +52,12 @@ class LVSPConnection:
async def send(self, payload): async def send(self, payload):
"""Send a payload down the websocket.""" """Send a payload down the websocket."""
msg = json.dumps(payload) msg = json.dumps(payload)
assert self.conn is not None
await self.conn.send(msg) await self.conn.send(msg)
async def recv(self): async def recv(self):
"""Receive a payload.""" """Receive a payload."""
assert self.conn is not None
msg = await self.conn.recv() msg = await self.conn.recv()
msg = json.dumps(msg) msg = json.dumps(msg)
return msg return msg
@ -82,6 +84,8 @@ class LVSPConnection:
# give the server 300 milliseconds to reply. # give the server 300 milliseconds to reply.
await asyncio.sleep(300) await asyncio.sleep(300)
assert self.conn is not None
await self.conn.close(4000, "heartbeat timeout") await self.conn.close(4000, "heartbeat timeout")
except asyncio.CancelledError: except asyncio.CancelledError:
pass pass
@ -182,7 +186,7 @@ class LVSPConnection:
await self.start() await self.start()
try: try:
if not self.conn: if self.conn is None:
log.error("failed to start lvsp connection, stopping") log.error("failed to start lvsp connection, stopping")
return return

View File

@ -169,3 +169,6 @@ class LVSPManager:
def region(self, region_id: str) -> Optional[Region]: def region(self, region_id: str) -> Optional[Region]:
"""Get a :class:`Region` instance""" """Get a :class:`Region` instance"""
return self.regions.get(region_id) 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"]) ctype = ChannelType(channel["type"])
if ctype not in VOICE_CHANNELS: if ctype not in VOICE_CHANNELS:
return return False
states = await self.app.voice.state_count(channel_id) states = await self.app.voice.state_count(channel_id)
@ -79,7 +79,7 @@ class VoiceManager:
# - user is not manage channels # - user is not manage channels
# then it fails # then it fails
if not is_bot and not is_manager and is_full: if not is_bot and not is_manager and is_full:
return return False
# all good # all good
return True return True
@ -161,6 +161,10 @@ class VoiceManager:
return return
conn = self.lvsp.get_conn(hostname) 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) await conn.send_info(info_type, info_data)
async def _create_ctx_guild(self, guild_id, channel_id): async def _create_ctx_guild(self, guild_id, channel_id):
@ -263,3 +267,25 @@ class VoiceManager:
) )
return list(map(dict, rows)) 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