1
0
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:
notsapinho 2021-04-08 11:59:00 -03:00 committed by GitHub
parent 953d7bd3d2
commit 774fcc9373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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":