🚧 WIP member list + voice

This commit is contained in:
Flam3rboy
2021-05-18 22:04:29 +02:00
parent e83b7cab75
commit da08497a19
7 changed files with 94 additions and 12 deletions
+44 -3
View File
@@ -1,10 +1,51 @@
import { CLOSECODES, OPCODES, Payload } from "../util/Constants";
// @ts-nocheck WIP
import { db, getPermission, MemberModel, MongooseCache, PublicUserProjection, RoleModel } from "@fosscord/server-util";
import { LazyRequest } from "../schema/LazyRequest";
import { OPCODES, Payload } from "../util/Constants";
import { Send } from "../util/Send";
import WebSocket from "../util/WebSocket";
import { check } from "./instanceOf";
export function onLazyRequest(this: WebSocket, { d }: Payload) {
// TODO: config: if want to list all members (even those who are offline) sorted by role, or just those who are online
export async function onLazyRequest(this: WebSocket, { d }: Payload) {
return; // WIP
// TODO: check data
const { guild_id, typing, channels, activities } = d;
check.call(this, LazyRequest, d);
const { guild_id, typing, channels, activities } = d as LazyRequest;
const permissions = await getPermission(this.user_id, guild_id);
// MongoDB query to retrieve all hoisted roles and join them with the members and users collection
const roles = await db
.collection("roles")
.aggregate([
{ $match: { guild_id, hoist: true } },
{ $sort: { position: 1 } },
{
$lookup: {
from: "members",
let: { id: "$id" },
pipeline: [
{ $match: { $expr: { $in: ["$$id", "$roles"] } } },
{ $limit: 1 },
{
$lookup: {
from: "users",
let: { user_id: "$id" },
pipeline: [
{ $match: { $expr: { $eq: ["$id", "$$user_id"] } } },
{ $project: PublicUserProjection },
],
as: "user",
},
},
],
as: "members",
},
},
])
.toArray();
Send(this, {
op: OPCODES.Dispatch,
+9 -1
View File
@@ -1,5 +1,13 @@
import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdate.ts";
import { CLOSECODES, Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { check } from "./instanceOf";
// TODO: implementation
// TODO: check if a voice server is setup
// TODO: save voice servers in database and retrieve them
// Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not.
export function onVoiceStateUpdate(this: WebSocket, data: Payload) {}
export function onVoiceStateUpdate(this: WebSocket, data: Payload) {
check.call(this, VoiceStateUpdateSchema, data.d);
}