mirror of https://gitlab.com/litecord/litecord.git
user_storage: add UserStorage.get_user_guilds
So that we're consistent.
- gateway.websocket, presence: change to UserStorage for
get_user_guilds
This commit is contained in:
parent
9547b5e536
commit
0aa679677f
|
|
@ -329,7 +329,7 @@ class GatewayWebsocket:
|
||||||
raise InvalidShard('Shard count > Total shards')
|
raise InvalidShard('Shard count > Total shards')
|
||||||
|
|
||||||
async def _guild_ids(self):
|
async def _guild_ids(self):
|
||||||
guild_ids = await self.storage.get_user_guilds(
|
guild_ids = await self.user_storage.get_user_guilds(
|
||||||
self.state.user_id
|
self.state.user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -667,7 +667,8 @@ class GatewayWebsocket:
|
||||||
"""Handle OP 12 Guild Sync."""
|
"""Handle OP 12 Guild Sync."""
|
||||||
data = payload['d']
|
data = payload['d']
|
||||||
|
|
||||||
gids = await self.storage.get_user_guilds(self.state.user_id)
|
gids = await self.user_storage.get_user_guilds(
|
||||||
|
self.state.user_id)
|
||||||
|
|
||||||
for guild_id in data:
|
for guild_id in data:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,9 @@ async def _pres(storage, user_id: int, status_obj: dict) -> dict:
|
||||||
|
|
||||||
class PresenceManager:
|
class PresenceManager:
|
||||||
"""Presence related functions."""
|
"""Presence related functions."""
|
||||||
def __init__(self, storage, state_manager, dispatcher):
|
def __init__(self, storage, user_storage, state_manager, dispatcher):
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
|
self.user_storage = user_storage
|
||||||
self.state_manager = state_manager
|
self.state_manager = state_manager
|
||||||
self.dispatcher = dispatcher
|
self.dispatcher = dispatcher
|
||||||
|
|
||||||
|
|
@ -171,7 +172,7 @@ class PresenceManager:
|
||||||
state['status'] = 'offline'
|
state['status'] = 'offline'
|
||||||
|
|
||||||
# TODO: shard-aware
|
# TODO: shard-aware
|
||||||
guild_ids = await self.storage.get_user_guilds(user_id)
|
guild_ids = await self.user_storage.get_user_guilds(user_id)
|
||||||
|
|
||||||
for guild_id in guild_ids:
|
for guild_id in guild_ids:
|
||||||
await self.dispatch_guild_pres(
|
await self.dispatch_guild_pres(
|
||||||
|
|
|
||||||
|
|
@ -147,16 +147,6 @@ class Storage:
|
||||||
|
|
||||||
return drow
|
return drow
|
||||||
|
|
||||||
async def get_user_guilds(self, user_id: int) -> List[int]:
|
|
||||||
"""Get all guild IDs a user is on."""
|
|
||||||
guild_ids = await self.db.fetch("""
|
|
||||||
SELECT guild_id
|
|
||||||
FROM members
|
|
||||||
WHERE user_id = $1
|
|
||||||
""", user_id)
|
|
||||||
|
|
||||||
return [row['guild_id'] for row in guild_ids]
|
|
||||||
|
|
||||||
async def _member_basic(self, guild_id: int, member_id: int):
|
async def _member_basic(self, guild_id: int, member_id: int):
|
||||||
return await self.db.fetchrow("""
|
return await self.db.fetchrow("""
|
||||||
SELECT user_id, nickname, joined_at, deafened, muted
|
SELECT user_id, nickname, joined_at, deafened, muted
|
||||||
|
|
|
||||||
|
|
@ -278,3 +278,13 @@ class UserStorage:
|
||||||
}})
|
}})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
async def get_user_guilds(self, user_id: int) -> List[int]:
|
||||||
|
"""Get all guild IDs a user is on."""
|
||||||
|
guild_ids = await self.db.fetch("""
|
||||||
|
SELECT guild_id
|
||||||
|
FROM members
|
||||||
|
WHERE user_id = $1
|
||||||
|
""", user_id)
|
||||||
|
|
||||||
|
return [row['guild_id'] for row in guild_ids]
|
||||||
|
|
|
||||||
8
run.py
8
run.py
|
|
@ -194,8 +194,12 @@ def init_app_managers(app):
|
||||||
app.icons = IconManager(app)
|
app.icons = IconManager(app)
|
||||||
|
|
||||||
app.dispatcher = EventDispatcher(app)
|
app.dispatcher = EventDispatcher(app)
|
||||||
app.presence = PresenceManager(app.storage,
|
|
||||||
app.state_manager, app.dispatcher)
|
# TODO: only pass app
|
||||||
|
app.presence = PresenceManager(
|
||||||
|
app.storage, app.user_storage,
|
||||||
|
app.state_manager, app.dispatcher
|
||||||
|
)
|
||||||
|
|
||||||
app.storage.presence = app.presence
|
app.storage.presence = app.presence
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue