1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 04:32:35 +01:00

update import to fosscord-server-util

This commit is contained in:
Flam3rboy 2021-02-10 14:37:16 +01:00
parent 49b3426858
commit 38757c60e1
7 changed files with 60 additions and 50 deletions

54
package-lock.json generated
View File

@ -9,10 +9,10 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"discord-server-util": "github:discord-open-source/discord-server-util",
"erlpack": "^0.1.3",
"fosscord-server-util": "github:fosscord/fosscord-server-util",
"jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.6",
"lambert-db": "^1.1.8",
"lambert-server": "^1.1.3",
"missing-native-js-functions": "^1.2.3",
"node-fetch": "^2.6.1",
@ -362,16 +362,6 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"node_modules/discord-server-util": {
"version": "1.0.0",
"resolved": "git+ssh://git@github.com/discord-open-source/discord-server-util.git#862200a80d7db52c04abb2300cbb480e2f835dfb",
"license": "ISC",
"dependencies": {
"jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.5",
"missing-native-js-functions": "^1.2.2"
}
},
"node_modules/ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
@ -548,6 +538,16 @@
"node": ">= 0.6"
}
},
"node_modules/fosscord-server-util": {
"version": "1.0.0",
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#b2e3df59d3829d8a149b0bd0c0679ec967b76e8d",
"license": "ISC",
"dependencies": {
"jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.7",
"missing-native-js-functions": "^1.2.2"
}
},
"node_modules/fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
@ -760,9 +760,9 @@
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
},
"node_modules/lambert-db": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.6.tgz",
"integrity": "sha512-FbUNAbgPYUvfJSxLdcfIk6w8J+Z4IYZJasVURBMm4eOeLm//kgGeOi+SrJqqa5z+gaCJ65ENIVs2hd+Cj2Efbw==",
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.8.tgz",
"integrity": "sha512-EyIEYLppS54tXsxIXGuS0l/0c+tF86KvaXRR92yRcGp5CHWRxPfUqV0KX/Ft7OkqtRTK5tDuJ/Bb4kUCXh2VUg==",
"dependencies": {
"missing-native-js-functions": "^1.1.8",
"mongodb": "^3.6.2",
@ -2049,15 +2049,6 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"discord-server-util": {
"version": "git+ssh://git@github.com/discord-open-source/discord-server-util.git#862200a80d7db52c04abb2300cbb480e2f835dfb",
"from": "discord-server-util@github:discord-open-source/discord-server-util",
"requires": {
"jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.5",
"missing-native-js-functions": "^1.2.2"
}
},
"ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
@ -2209,6 +2200,15 @@
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
},
"fosscord-server-util": {
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#b2e3df59d3829d8a149b0bd0c0679ec967b76e8d",
"from": "fosscord-server-util@github:fosscord/fosscord-server-util",
"requires": {
"jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.7",
"missing-native-js-functions": "^1.2.2"
}
},
"fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
@ -2367,9 +2367,9 @@
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
},
"lambert-db": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.6.tgz",
"integrity": "sha512-FbUNAbgPYUvfJSxLdcfIk6w8J+Z4IYZJasVURBMm4eOeLm//kgGeOi+SrJqqa5z+gaCJ65ENIVs2hd+Cj2Efbw==",
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.8.tgz",
"integrity": "sha512-EyIEYLppS54tXsxIXGuS0l/0c+tF86KvaXRR92yRcGp5CHWRxPfUqV0KX/Ft7OkqtRTK5tDuJ/Bb4kUCXh2VUg==",
"requires": {
"missing-native-js-functions": "^1.1.8",
"mongodb": "^3.6.2",

View File

@ -12,10 +12,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"discord-server-util": "github:discord-open-source/discord-server-util",
"erlpack": "^0.1.3",
"fosscord-server-util": "github:fosscord/fosscord-server-util",
"jsonwebtoken": "^8.5.1",
"lambert-db": "^1.1.6",
"lambert-db": "^1.1.8",
"lambert-server": "^1.1.3",
"missing-native-js-functions": "^1.2.3",
"node-fetch": "^2.6.1",

BIN
src/.DS_Store vendored

Binary file not shown.

View File

@ -1,6 +1,7 @@
import { db } from "discord-server-util";
import { db } from "fosscord-server-util";
import { Server as WebSocketServer } from "ws";
import { Connection } from "./events/Connection";
import Config from "./util/Config";
export class Server {
public ws: WebSocketServer;
@ -9,8 +10,15 @@ export class Server {
this.ws.on("connection", Connection);
}
async setupSchema() {
// TODO: adjust expireAfterSeconds -> lower
await db.conn.db.collection("events").createIndex({ created_at: 1 }, { expireAfterSeconds: 60 });
}
async listen(): Promise<void> {
await db.init();
await this.setupSchema();
await Config.init();
console.log("listening");
}
}

View File

@ -1,24 +1,23 @@
import { db, User } from "discord-server-util";
import { ProviderCache } from "lambert-db";
import { db, User, Event } from "fosscord-server-util";
import { MongodbProviderCache } from "lambert-db/dist/Mongodb";
import WebSocket from "../util/WebSocket";
export async function setupListener(this: WebSocket) {
// TODO: shard guilds (only for bots)
// TODO: bot sharding
// TODO: close connection on Invalidated Token
const user: User = await db.data.users({ id: this.userid }).get();
// * MongoDB specific $in query to get all guilds of the user
const guildCache: MongodbProviderCache = await db.data
.guilds({ id: { $id: user.guilds } })
const eventStream: MongodbProviderCache = await db.data
.guilds({ $or: [{ guild_id: { $in: user.guilds } }, { user_id: this.userid }] })
.cache({ onlyEvents: true })
.init();
guildCache.on("change", (data) => {
console.log(data);
eventStream.on("insert", (document: Event) => {
console.log("event", document);
this.emit(document.event, document.data);
});
this.once("close", async () => {
await guildCache.destroy();
});
this.once("close", () => eventStream.destroy());
}

View File

@ -1,17 +1,20 @@
import { CLOSECODES, Payload } from "../util/Constants";
import Config from "../util/Config";
import WebSocket from "../util/WebSocket";
import { checkToken, IdentifySchema } from "discord-server-util";
import { check } from "./instanceOf";
import { checkToken, IdentifySchema } from "fosscord-server-util";
import { setupListener } from "../listener/listener";
import { instanceOf } from "lambert-server";
export async function onIdentify(this: WebSocket, data: Payload) {
try {
clearTimeout(this.readyTimeout);
if (check.call(this, IdentifySchema, data.d)) return;
instanceOf(IdentifySchema, data.d);
const identify: IdentifySchema = data.d;
try {
var { id } = await checkToken(identify.token);
var decoded = await checkToken(identify.token);
this.userid = decoded.id;
await setupListener.call(this);
} catch (error) {
return this.close(CLOSECODES.Authentication_failed);
}

View File

@ -1,4 +1,4 @@
import { Config } from "discord-server-util";
import { Config } from "fosscord-server-util";
export default {
init() {