update import to fosscord-server-util
This commit is contained in:
parent
49b3426858
commit
38757c60e1
54
package-lock.json
generated
54
package-lock.json
generated
@ -9,10 +9,10 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord-server-util": "github:discord-open-source/discord-server-util",
|
|
||||||
"erlpack": "^0.1.3",
|
"erlpack": "^0.1.3",
|
||||||
|
"fosscord-server-util": "github:fosscord/fosscord-server-util",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"lambert-db": "^1.1.6",
|
"lambert-db": "^1.1.8",
|
||||||
"lambert-server": "^1.1.3",
|
"lambert-server": "^1.1.3",
|
||||||
"missing-native-js-functions": "^1.2.3",
|
"missing-native-js-functions": "^1.2.3",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
@ -362,16 +362,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
"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": {
|
"node_modules/ecdsa-sig-formatter": {
|
||||||
"version": "1.0.11",
|
"version": "1.0.11",
|
||||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||||
@ -548,6 +538,16 @@
|
|||||||
"node": ">= 0.6"
|
"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": {
|
"node_modules/fresh": {
|
||||||
"version": "0.5.2",
|
"version": "0.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||||
@ -760,9 +760,9 @@
|
|||||||
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
|
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
|
||||||
},
|
},
|
||||||
"node_modules/lambert-db": {
|
"node_modules/lambert-db": {
|
||||||
"version": "1.1.6",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.8.tgz",
|
||||||
"integrity": "sha512-FbUNAbgPYUvfJSxLdcfIk6w8J+Z4IYZJasVURBMm4eOeLm//kgGeOi+SrJqqa5z+gaCJ65ENIVs2hd+Cj2Efbw==",
|
"integrity": "sha512-EyIEYLppS54tXsxIXGuS0l/0c+tF86KvaXRR92yRcGp5CHWRxPfUqV0KX/Ft7OkqtRTK5tDuJ/Bb4kUCXh2VUg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"missing-native-js-functions": "^1.1.8",
|
"missing-native-js-functions": "^1.1.8",
|
||||||
"mongodb": "^3.6.2",
|
"mongodb": "^3.6.2",
|
||||||
@ -2049,15 +2049,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
"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": {
|
"ecdsa-sig-formatter": {
|
||||||
"version": "1.0.11",
|
"version": "1.0.11",
|
||||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
|
||||||
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
"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": {
|
"fresh": {
|
||||||
"version": "0.5.2",
|
"version": "0.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||||
@ -2367,9 +2367,9 @@
|
|||||||
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
|
"integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ=="
|
||||||
},
|
},
|
||||||
"lambert-db": {
|
"lambert-db": {
|
||||||
"version": "1.1.6",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.6.tgz",
|
"resolved": "https://registry.npmjs.org/lambert-db/-/lambert-db-1.1.8.tgz",
|
||||||
"integrity": "sha512-FbUNAbgPYUvfJSxLdcfIk6w8J+Z4IYZJasVURBMm4eOeLm//kgGeOi+SrJqqa5z+gaCJ65ENIVs2hd+Cj2Efbw==",
|
"integrity": "sha512-EyIEYLppS54tXsxIXGuS0l/0c+tF86KvaXRR92yRcGp5CHWRxPfUqV0KX/Ft7OkqtRTK5tDuJ/Bb4kUCXh2VUg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"missing-native-js-functions": "^1.1.8",
|
"missing-native-js-functions": "^1.1.8",
|
||||||
"mongodb": "^3.6.2",
|
"mongodb": "^3.6.2",
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord-server-util": "github:discord-open-source/discord-server-util",
|
|
||||||
"erlpack": "^0.1.3",
|
"erlpack": "^0.1.3",
|
||||||
|
"fosscord-server-util": "github:fosscord/fosscord-server-util",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"lambert-db": "^1.1.6",
|
"lambert-db": "^1.1.8",
|
||||||
"lambert-server": "^1.1.3",
|
"lambert-server": "^1.1.3",
|
||||||
"missing-native-js-functions": "^1.2.3",
|
"missing-native-js-functions": "^1.2.3",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
@ -1,6 +1,7 @@
|
|||||||
import { db } from "discord-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";
|
||||||
|
import Config from "./util/Config";
|
||||||
|
|
||||||
export class Server {
|
export class Server {
|
||||||
public ws: WebSocketServer;
|
public ws: WebSocketServer;
|
||||||
@ -9,8 +10,15 @@ export class Server {
|
|||||||
this.ws.on("connection", Connection);
|
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> {
|
async listen(): Promise<void> {
|
||||||
await db.init();
|
await db.init();
|
||||||
|
await this.setupSchema();
|
||||||
|
await Config.init();
|
||||||
console.log("listening");
|
console.log("listening");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
import { db, User } from "discord-server-util";
|
import { db, User, Event } from "fosscord-server-util";
|
||||||
import { ProviderCache } from "lambert-db";
|
|
||||||
import { MongodbProviderCache } from "lambert-db/dist/Mongodb";
|
import { MongodbProviderCache } from "lambert-db/dist/Mongodb";
|
||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
export async function setupListener(this: 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();
|
const user: User = await db.data.users({ id: this.userid }).get();
|
||||||
|
|
||||||
// * MongoDB specific $in query to get all guilds of the user
|
// * MongoDB specific $in query to get all guilds of the user
|
||||||
const guildCache: MongodbProviderCache = await db.data
|
const eventStream: MongodbProviderCache = await db.data
|
||||||
.guilds({ id: { $id: user.guilds } })
|
.guilds({ $or: [{ guild_id: { $in: user.guilds } }, { user_id: this.userid }] })
|
||||||
.cache({ onlyEvents: true })
|
.cache({ onlyEvents: true })
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
guildCache.on("change", (data) => {
|
eventStream.on("insert", (document: Event) => {
|
||||||
console.log(data);
|
console.log("event", document);
|
||||||
|
this.emit(document.event, document.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.once("close", async () => {
|
this.once("close", () => eventStream.destroy());
|
||||||
await guildCache.destroy();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
import { CLOSECODES, Payload } from "../util/Constants";
|
import { CLOSECODES, Payload } from "../util/Constants";
|
||||||
import Config from "../util/Config";
|
|
||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
import { checkToken, IdentifySchema } from "discord-server-util";
|
import { checkToken, IdentifySchema } from "fosscord-server-util";
|
||||||
import { check } from "./instanceOf";
|
import { setupListener } from "../listener/listener";
|
||||||
|
import { instanceOf } from "lambert-server";
|
||||||
|
|
||||||
export async function onIdentify(this: WebSocket, data: Payload) {
|
export async function onIdentify(this: WebSocket, data: Payload) {
|
||||||
clearTimeout(this.readyTimeout);
|
|
||||||
if (check.call(this, IdentifySchema, data.d)) return;
|
|
||||||
|
|
||||||
const identify: IdentifySchema = data.d;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var { id } = await checkToken(identify.token);
|
clearTimeout(this.readyTimeout);
|
||||||
|
instanceOf(IdentifySchema, data.d);
|
||||||
|
|
||||||
|
const identify: IdentifySchema = data.d;
|
||||||
|
|
||||||
|
var decoded = await checkToken(identify.token);
|
||||||
|
this.userid = decoded.id;
|
||||||
|
|
||||||
|
await setupListener.call(this);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.close(CLOSECODES.Authentication_failed);
|
return this.close(CLOSECODES.Authentication_failed);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Config } from "discord-server-util";
|
import { Config } from "fosscord-server-util";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
init() {
|
init() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user