mirror of https://gitlab.com/litecord/litecord.git
Merge branch 'impl/deprecated-regions' into 'master'
impl: deprecated regions Closes #79 See merge request litecord/litecord!57
This commit is contained in:
commit
67a8ae4ce2
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue