mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 13:14:06 +01:00
Update listener.ts
This commit is contained in:
parent
953d7bd3d2
commit
774fcc9373
@ -36,18 +36,7 @@ export async function setupListener(this: WebSocket) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await eventStream.init();
|
await eventStream.init();
|
||||||
eventStream.on("insert", async (document) => {
|
eventStream.on("insert", dispatch.bind(this));
|
||||||
dispatch.call(this, document);
|
|
||||||
|
|
||||||
const newUser = await UserModel.findOne({ id: user.id }).lean().exec();
|
|
||||||
var newGuilds = user.guilds;
|
|
||||||
|
|
||||||
if (shard_count) {
|
|
||||||
newGuilds = user.guilds.filter((x) => (BigInt(x) >> 22n) % shard_count === shard_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
eventStream.changeStream([{ $match: { $or: [{ "fullDocument.guild_id": { $in: newGuilds } }, { "fullDocument.user_id": newUser.id }] } }]);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.once("close", () => eventStream.destroy());
|
this.once("close", () => eventStream.destroy());
|
||||||
}
|
}
|
||||||
@ -62,6 +51,17 @@ export async function dispatch(this: WebSocket, document: Event) {
|
|||||||
permission = await getPermission(this.user_id, document.guild_id, channel_id);
|
permission = await getPermission(this.user_id, document.guild_id, channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(document.event === "GUILD_CREATE") {
|
||||||
|
const newUser = await UserModel.findOne({ id: this.user_id }).lean().exec();
|
||||||
|
var newGuilds = newUser.guilds;
|
||||||
|
|
||||||
|
if (shard_count) {
|
||||||
|
newGuilds = newUser.guilds.filter((x) => (BigInt(x) >> 22n) % shard_count === shard_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
eventStream.changeStream([{ $match: { $or: [{ "fullDocument.guild_id": { $in: newGuilds } }, { "fullDocument.user_id": newUser.id }] } }]);
|
||||||
|
}
|
||||||
|
|
||||||
// check intents: https://discord.com/developers/docs/topics/gateway#gateway-intents
|
// check intents: https://discord.com/developers/docs/topics/gateway#gateway-intents
|
||||||
switch (document.event) {
|
switch (document.event) {
|
||||||
case "GUILD_CREATE":
|
case "GUILD_CREATE":
|
||||||
|
Loading…
Reference in New Issue
Block a user