From 99ee7e9400f06e8718612d8b52d15215dc620774 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 26 Sep 2022 22:29:30 +1000 Subject: Prettier --- src/gateway/opcodes/Identify.ts | 12 +++--- src/gateway/opcodes/LazyRequest.ts | 72 ++++++++++++++++++++++++--------- src/gateway/opcodes/PresenceUpdate.ts | 10 ++++- src/gateway/opcodes/VoiceStateUpdate.ts | 8 ++-- 4 files changed, 72 insertions(+), 30 deletions(-) (limited to 'src/gateway/opcodes') diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index b4b36075..c5c78f1a 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -158,11 +158,13 @@ export async function onIdentify(this: WebSocket, data: Payload) { ...x.settings, guild_id: x.guild.id, // disgusting - channel_overrides: Object.entries(x.settings.channel_overrides ?? {}).map(y => ({ + channel_overrides: Object.entries( + x.settings.channel_overrides ?? {}, + ).map((y) => ({ ...y[1], channel_id: y[0], - })) - })) as any as UserGuildSettings[]; // VERY disgusting. don't care. + })), + })) as any as UserGuildSettings[]; // VERY disgusting. don't care. const channels = recipients.map((x) => { // @ts-ignore @@ -171,7 +173,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { users = users.concat(x.channel.recipients as unknown as User[]); if (x.channel.isDm()) { x.channel.recipients = x.channel.recipients!.filter( - (x) => x.id !== this.user_id + (x) => x.id !== this.user_id, ); } return x.channel; @@ -243,7 +245,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { accent_color: user.accent_color, banner: user.banner, bio: user.bio, - premium_since: user.premium_since + premium_since: user.premium_since, }; const d: ReadyEventData = { diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts index 0f21d087..f5bbad14 100644 --- a/src/gateway/opcodes/LazyRequest.ts +++ b/src/gateway/opcodes/LazyRequest.ts @@ -1,5 +1,19 @@ -import { getDatabase, getPermission, listenEvent, Member, Role, Session, LazyRequestSchema } from "@fosscord/util"; -import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send } from "@fosscord/gateway"; +import { + getDatabase, + getPermission, + listenEvent, + Member, + Role, + Session, + LazyRequestSchema, +} from "@fosscord/util"; +import { + WebSocket, + Payload, + handlePresenceUpdate, + OPCODES, + Send, +} from "@fosscord/gateway"; import { check } from "./instanceOf"; // TODO: only show roles/members that have access to this channel @@ -14,7 +28,8 @@ async function getMembers(guild_id: string, range: [number, number]) { let members: Member[] = []; try { - members = await getDatabase()!.getRepository(Member) + members = await getDatabase()! + .getRepository(Member) .createQueryBuilder("member") .where("member.guild_id = :guild_id", { guild_id }) .leftJoinAndSelect("member.roles", "role") @@ -23,7 +38,7 @@ async function getMembers(guild_id: string, range: [number, number]) { .addSelect("user.settings") .addSelect( "CASE WHEN session.status = 'offline' THEN 0 ELSE 1 END", - "_status" + "_status", ) .orderBy("role.position", "DESC") .addOrderBy("_status", "DESC") @@ -31,8 +46,7 @@ async function getMembers(guild_id: string, range: [number, number]) { .offset(Number(range[0]) || 0) .limit(Number(range[1]) || 100) .getMany(); - } - catch (e) { + } catch (e) { console.error(`LazyRequest`, e); } @@ -51,14 +65,20 @@ async function getMembers(guild_id: string, range: [number, number]) { .map((m) => m.roles) .flat() .unique((r: Role) => r.id); - member_roles.push(member_roles.splice(member_roles.findIndex(x => x.id === x.guild_id), 1)[0]); + member_roles.push( + member_roles.splice( + member_roles.findIndex((x) => x.id === x.guild_id), + 1, + )[0], + ); const offlineItems = []; for (const role of member_roles) { // @ts-ignore - const [role_members, other_members]: Member[][] = partition(members, (m: Member) => - m.roles.find((r) => r.id === role.id) + const [role_members, other_members]: Member[][] = partition( + members, + (m: Member) => m.roles.find((r) => r.id === role.id), ); const group = { count: role_members.length, @@ -74,15 +94,19 @@ async function getMembers(guild_id: string, range: [number, number]) { .map((x: Role) => x.id); const statusMap = { - "online": 0, - "idle": 1, - "dnd": 2, - "invisible": 3, - "offline": 4, + online: 0, + idle: 1, + dnd: 2, + invisible: 3, + offline: 4, }; // sort sessions by relevance const sessions = member.user.sessions.sort((a, b) => { - return (statusMap[a.status] - statusMap[b.status]) + ((a.activities.length - b.activities.length) * 2); + return ( + statusMap[a.status] - + statusMap[b.status] + + (a.activities.length - b.activities.length) * 2 + ); }); var session: Session | undefined = sessions.first(); @@ -103,7 +127,11 @@ async function getMembers(guild_id: string, range: [number, number]) { }, }; - if (!session || session.status == "invisible" || session.status == "offline") { + if ( + !session || + session.status == "invisible" || + session.status == "offline" + ) { item.member.presence.status = "offline"; offlineItems.push(item); group.count--; @@ -130,7 +158,9 @@ async function getMembers(guild_id: string, range: [number, number]) { items, groups, range, - members: items.map((x) => 'member' in x ? x.member : undefined).filter(x => !!x), + members: items + .map((x) => ("member" in x ? x.member : undefined)) + .filter((x) => !!x), }; } @@ -161,7 +191,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) { this.member_events[member.user.id] = await listenEvent( member.user.id, handlePresenceUpdate.bind(this), - this.listen_options + this.listen_options, ); }); }); @@ -181,7 +211,9 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) { op: "SYNC", range: x.range, })), - online_count: member_count - (groups.find(x => x.id == "offline")?.count ?? 0), + online_count: + member_count - + (groups.find((x) => x.id == "offline")?.count ?? 0), member_count, id: "everyone", guild_id, @@ -199,6 +231,6 @@ function partition(array: T[], isValid: Function) { ? [[...pass, elem], fail] : [pass, [...fail, elem]]; }, - [[], []] + [[], []], ); } diff --git a/src/gateway/opcodes/PresenceUpdate.ts b/src/gateway/opcodes/PresenceUpdate.ts index d17b7dd7..37299213 100644 --- a/src/gateway/opcodes/PresenceUpdate.ts +++ b/src/gateway/opcodes/PresenceUpdate.ts @@ -1,5 +1,11 @@ import { WebSocket, Payload } from "@fosscord/gateway"; -import { emitEvent, PresenceUpdateEvent, Session, User, ActivitySchema } from "@fosscord/util"; +import { + emitEvent, + PresenceUpdateEvent, + Session, + User, + ActivitySchema, +} from "@fosscord/util"; import { check } from "./instanceOf"; export async function onPresenceUpdate(this: WebSocket, { d }: Payload) { @@ -8,7 +14,7 @@ export async function onPresenceUpdate(this: WebSocket, { d }: Payload) { await Session.update( { session_id: this.session_id }, - { status: presence.status, activities: presence.activities } + { status: presence.status, activities: presence.activities }, ); await emitEvent({ diff --git a/src/gateway/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts index 8e1585ec..17ed7e4f 100644 --- a/src/gateway/opcodes/VoiceStateUpdate.ts +++ b/src/gateway/opcodes/VoiceStateUpdate.ts @@ -87,16 +87,18 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { //If it's null it means that we are leaving the channel and this event is not needed if (voiceState.channel_id !== null) { - const guild = await Guild.findOne({ where: { id: voiceState.guild_id } }); + const guild = await Guild.findOne({ + where: { id: voiceState.guild_id }, + }); const regions = Config.get().regions; let guildRegion: Region; if (guild && guild.region) { guildRegion = regions.available.filter( - (r) => r.id === guild.region + (r) => r.id === guild.region, )[0]; } else { guildRegion = regions.available.filter( - (r) => r.id === regions.default + (r) => r.id === regions.default, )[0]; } -- cgit 1.4.1