mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
🚧 WIP member list + voice
This commit is contained in:
parent
e83b7cab75
commit
da08497a19
7
package-lock.json
generated
7
package-lock.json
generated
@ -310,7 +310,6 @@
|
||||
"dependencies": {
|
||||
"anymatch": "~3.1.1",
|
||||
"braces": "~3.0.2",
|
||||
"fsevents": "~2.3.1",
|
||||
"glob-parent": "~5.1.0",
|
||||
"is-binary-path": "~2.1.0",
|
||||
"is-glob": "~4.0.1",
|
||||
@ -1147,8 +1146,7 @@
|
||||
"bson": "^1.1.4",
|
||||
"denque": "^1.4.1",
|
||||
"optional-require": "^1.0.2",
|
||||
"safe-buffer": "^5.1.2",
|
||||
"saslprep": "^1.0.0"
|
||||
"safe-buffer": "^5.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
@ -1228,8 +1226,7 @@
|
||||
"bson": "^1.1.4",
|
||||
"denque": "^1.4.1",
|
||||
"require_optional": "^1.0.1",
|
||||
"safe-buffer": "^5.1.2",
|
||||
"saslprep": "^1.0.0"
|
||||
"safe-buffer": "^5.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
|
@ -17,7 +17,7 @@ export interface DispatchOpts {
|
||||
guilds: Array<string>;
|
||||
}
|
||||
|
||||
function getPipeline(this: WebSocket, guilds: string[]) {
|
||||
function getPipeline(this: WebSocket, guilds: string[], channels: string[]) {
|
||||
if (this.shard_count) {
|
||||
guilds = guilds.filter((x) => (BigInt(x) >> 22n) % this.shard_count === this.shard_id);
|
||||
}
|
||||
@ -25,7 +25,11 @@ function getPipeline(this: WebSocket, guilds: string[]) {
|
||||
return [
|
||||
{
|
||||
$match: {
|
||||
$or: [{ "fullDocument.guild_id": { $in: guilds } }, { "fullDocument.user_id": this.user_id }],
|
||||
$or: [
|
||||
{ "fullDocument.guild_id": { $in: guilds } },
|
||||
{ "fullDocument.user_id": this.user_id },
|
||||
{ "fullDocument.channel_id": { $in: channels } },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
@ -45,6 +49,8 @@ export async function setupListener(this: WebSocket) {
|
||||
this.once("close", () => eventStream.destroy());
|
||||
}
|
||||
|
||||
// TODO: cache permission
|
||||
|
||||
export async function dispatch(this: WebSocket, document: Event, { eventStream, guilds }: DispatchOpts) {
|
||||
var permission = new Permissions("ADMINISTRATOR"); // default permission for dms
|
||||
console.log("event", document);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
15
src/schema/LazyRequest.ts
Normal file
15
src/schema/LazyRequest.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export interface LazyRequest {
|
||||
activities: boolean;
|
||||
channels: Record<string, [number, number]>;
|
||||
guild_id: string;
|
||||
threads: boolean;
|
||||
typing: true;
|
||||
}
|
||||
|
||||
export const LazyRequest = {
|
||||
activities: Boolean,
|
||||
channels: Object,
|
||||
guild_id: String,
|
||||
threads: Boolean,
|
||||
typing: Boolean,
|
||||
};
|
13
src/schema/VoiceStateUpdate.ts.ts
Normal file
13
src/schema/VoiceStateUpdate.ts.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export const VoiceStateUpdateSchema = {
|
||||
guild_id: String,
|
||||
channel_id: String,
|
||||
self_mute: Boolean,
|
||||
self_deaf: Boolean,
|
||||
};
|
||||
|
||||
export interface VoiceStateUpdateSchema {
|
||||
guild_id: string;
|
||||
channel_id: string;
|
||||
self_mute: boolean;
|
||||
self_deaf: boolean;
|
||||
}
|
@ -14,6 +14,8 @@ export default {
|
||||
setAll: Config.setAll,
|
||||
};
|
||||
|
||||
export interface DefaultOptions {}
|
||||
export interface DefaultOptions {
|
||||
endpoint?: string;
|
||||
}
|
||||
|
||||
export const DefaultOptions: DefaultOptions = {};
|
||||
|
Loading…
Reference in New Issue
Block a user