Skip to content

Commit

Permalink
add presences to GUILD_MEMBERS
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanUC committed Sep 2, 2024
1 parent e461f73 commit 98a73bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion yepcord/gateway/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def __init__(self, friends_presences: list[dict], guilds_ids: list[int]):
self.guilds_ids = guilds_ids

async def json(self) -> dict:
g = [{"voice_states": [], "id": str(i), "embedded_activities": []} for i in self.guilds_ids] # TODO
# TODO
g = [{"voice_states": [], "id": str(guilds_id), "embedded_activities": []} for guilds_id in self.guilds_ids]
return {
"t": self.NAME,
"op": self.OP,
Expand Down
17 changes: 15 additions & 2 deletions yepcord/gateway/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,21 @@ async def handle_GUILD_MEMBERS(self, data: dict) -> None:
limit = data.get("limit", 100)
if limit > 100 or limit < 1:
limit = 100

members = await getCore().getGuildMembersGw(guild, query, limit, data.get("user_ids", []))
presences = [] # TODO: add presences
member_ids = [member.user.id for member in members]

presences = await Presence.filter(
user__id__in=member_ids,
status__not_in=["offline", "invisible"],
updated_at__gt=int(time() - Config.GATEWAY_KEEP_ALIVE_DELAY * 1.25)
).select_related("user")
presences = [{
"user": (await presence.user.userdata).ds_json,
"guild_id": str(guild_id),
**presence.ds_json(False),
} for presence in presences]

await self.esend(GuildMembersChunkEvent(members, presences, guild_id))


Expand Down Expand Up @@ -429,6 +442,6 @@ async def getFriendsPresences(user_id: int) -> list[dict[str, ...]]:
):
presences.append(presence.ds_json())
continue
presences.append(Presence.ds_json_offline())
presences.append(Presence.ds_json_offline(other.id))

return presences
4 changes: 2 additions & 2 deletions yepcord/yepcord/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,10 +775,10 @@ async def getRoleMemberIds(self, role: Role) -> list[int]:
return [member.user.id for member in await role.guildmembers.all().select_related("user").limit(100)]

async def getGuildMembersGw(self, guild: Guild, query: str, limit: int, user_ids: list[int]) -> list[GuildMember]:
db_query = Q(guild=guild) & (Q(nick__startswith=query) | Q(user__userdatas__username__istartswith=query))
db_query = Q(guild=guild) & ((Q(nick__not_isnull=True) & Q(nick__istartswith=query)) | Q(user__userdatas__username__istartswith=query))
if user_ids:
db_query &= Q(user__id__in=user_ids)
return await GuildMember.filter(db_query).select_related("user").limit(limit).all()
return await GuildMember.filter(db_query).select_related("user").limit(limit)

async def memberHasRole(self, member: GuildMember, role: Role) -> bool:
return await member.roles.filter(id=role.id).exists()
Expand Down

0 comments on commit 98a73bb

Please sign in to comment.