1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 05:02:37 +01:00

🎨 rename userid -> user_id

This commit is contained in:
Flam3rboy 2021-03-22 21:52:13 +01:00
parent 6030b86121
commit ccfa61ca63
7 changed files with 14 additions and 10 deletions

View File

@ -30,7 +30,8 @@ ws.on("message", (buffer) => {
send({ send({
op: 2, op: 2,
d: { d: {
token: "", token:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjgxMTY0MjkxNzQzMjA2NjA0OCIsImlhdCI6MTYxMzU4MTE1MX0.7Qj_z2lYIgJ0rc7NfGtpW5DKGqecQfv1mLpoBUQHKDc",
intents: 0n, intents: 0n,
properties: {}, properties: {},
}, },

4
package-lock.json generated
View File

@ -549,7 +549,7 @@
}, },
"node_modules/fosscord-server-util": { "node_modules/fosscord-server-util": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#2859daeba89e56683c60d99db0d6100fa4ac797d", "resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#64ab9e049ad4d3b68c0b9a9ce2e08363e77d3c84",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
@ -2216,7 +2216,7 @@
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
}, },
"fosscord-server-util": { "fosscord-server-util": {
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#2859daeba89e56683c60d99db0d6100fa4ac797d", "version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#64ab9e049ad4d3b68c0b9a9ce2e08363e77d3c84",
"from": "fosscord-server-util@github:fosscord/fosscord-server-util", "from": "fosscord-server-util@github:fosscord/fosscord-server-util",
"requires": { "requires": {
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",

View File

@ -1,3 +1,6 @@
import "missing-native-js-functions";
import dotenv from "dotenv";
dotenv.config();
import { db } from "fosscord-server-util"; import { db } from "fosscord-server-util";
import { Server as WebSocketServer } from "ws"; import { Server as WebSocketServer } from "ws";
import { Connection } from "./events/Connection"; import { Connection } from "./events/Connection";
@ -19,7 +22,8 @@ export class Server {
// @ts-ignore // @ts-ignore
await (db as Promise<Connection>); await (db as Promise<Connection>);
await this.setupSchema(); await this.setupSchema();
console.log("[DB] connected");
await Config.init(); await Config.init();
console.log("listening"); console.log("[Gateway] online");
} }
} }

View File

@ -1,6 +1,5 @@
process.on("uncaughtException", console.error); process.on("uncaughtException", console.error);
process.on("unhandledRejection", console.error); process.on("unhandledRejection", console.error);
setTimeout(() => {}, 100000000);
import { Server } from "./Server"; import { Server } from "./Server";
import { config } from "dotenv"; import { config } from "dotenv";

View File

@ -8,11 +8,11 @@ import WebSocket from "../util/WebSocket";
// ? How to resubscribe MongooseCache for new dm channel events? Maybe directly send them to the user_id regardless of the channel_id? -> max overhead of creating 10 events in database for dm user group. Or a new field in event -> recipient_ids? // ? How to resubscribe MongooseCache for new dm channel events? Maybe directly send them to the user_id regardless of the channel_id? -> max overhead of creating 10 events in database for dm user group. Or a new field in event -> recipient_ids?
export async function setupListener(this: WebSocket) { export async function setupListener(this: WebSocket) {
const user = await UserModel.findOne({ id: this.userid }).exec(); const user = await UserModel.findOne({ id: this.user_id }).exec();
const eventStream = new MongooseCache( const eventStream = new MongooseCache(
db.collection("events"), db.collection("events"),
[{ $match: { $or: [{ guild_id: { $in: user.guilds } }, { user_id: this.userid }] } }], [{ $match: { $or: [{ guild_id: { $in: user.guilds } }, { user_id: this.user_id }] } }],
{ onlyEvents: true } { onlyEvents: true }
); );
await eventStream.init(); await eventStream.init();
@ -27,7 +27,7 @@ export async function dispatch(this: WebSocket, document: Event) {
if (document.guild_id) { if (document.guild_id) {
if (!this.intents.has("GUILDS")) return; if (!this.intents.has("GUILDS")) return;
const channel_id = document.channel_id || document.data?.channel_id; const channel_id = document.channel_id || document.data?.channel_id;
permission = await getPermission(this.userid, document.guild_id, channel_id); permission = await getPermission(this.user_id, document.guild_id, channel_id);
} }
console.log("event", document); console.log("event", document);

View File

@ -14,7 +14,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
const identify: IdentifySchema = data.d; const identify: IdentifySchema = data.d;
var decoded = await checkToken(identify.token); var decoded = await checkToken(identify.token);
this.userid = decoded.id; this.user_id = decoded.id;
this.intents = new Intents(identify.intents); this.intents = new Intents(identify.intents);
await setupListener.call(this); await setupListener.call(this);

View File

@ -3,7 +3,7 @@ import WS, { Server, Data } from "ws";
interface WebSocket extends WS { interface WebSocket extends WS {
version: number; version: number;
userid: bigint; user_id: bigint;
encoding: "etf" | "json"; encoding: "etf" | "json";
compress?: "zlib-stream"; compress?: "zlib-stream";
heartbeatTimeout: NodeJS.Timeout; heartbeatTimeout: NodeJS.Timeout;