From 5c38999afac9ead4c5d1b90518098be726d1bdf2 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 17 Oct 2021 22:28:15 +0200 Subject: :bug: also receive events for newly added members/relationships --- gateway/src/listener/listener.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'gateway/src') diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts index 79659a1f..032b2375 100644 --- a/gateway/src/listener/listener.ts +++ b/gateway/src/listener/listener.ts @@ -117,7 +117,7 @@ export async function setupListener(this: WebSocket) { // TODO: only subscribe for events that are in the connection intents async function consume(this: WebSocket, opts: EventOpts) { const { data, event } = opts; - const id = data.id as string; + let id = data.id as string; const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm const consumer = consume.bind(this); @@ -138,6 +138,10 @@ async function consume(this: WebSocket, opts: EventOpts) { this.listen_options ); break; + case "GUILD_MEMBER_REMOVE": + if (!this.member_events[data.user.id]) break; + this.member_events[data.user.id](); + break; case "RELATIONSHIP_REMOVE": case "CHANNEL_DELETE": case "GUILD_DELETE": @@ -151,7 +155,14 @@ async function consume(this: WebSocket, opts: EventOpts) { .has("VIEW_CHANNEL") ) return; - //No break needed here, we need to call the listenEvent function below + // No break needed here, we need to call the listenEvent function below + case "RELATIONSHIP_ADD": + this.events[data.user.id] = await listenEvent( + data.user.id, + handlePresenceUpdate.bind(this), + this.listen_options + ); + break; case "GUILD_CREATE": this.events[id] = await listenEvent(id, consumer, listenOpts); break; -- cgit 1.5.1 From 4bae3909e3827e1e476fc029254865972c20df60 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Mon, 18 Oct 2021 21:10:03 +0200 Subject: :bug: fix types + prod env --- bundle/src/Server.ts | 2 +- gateway/src/opcodes/LazyRequest.ts | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'gateway/src') diff --git a/bundle/src/Server.ts b/bundle/src/Server.ts index f29cd649..e461ec5f 100644 --- a/bundle/src/Server.ts +++ b/bundle/src/Server.ts @@ -12,7 +12,7 @@ import { Config, initDatabase } from "@fosscord/util"; const app = express(); const server = http.createServer(); const port = Number(process.env.PORT) || 3001; -const production = true; +const production = process.env.NODE_ENV == "development" ? false : true; server.on("request", app); // @ts-ignore diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts index c304dfe7..2156070f 100644 --- a/gateway/src/opcodes/LazyRequest.ts +++ b/gateway/src/opcodes/LazyRequest.ts @@ -1,11 +1,4 @@ -import { - EVENTEnum, - EventOpts, - getPermission, - listenEvent, - Member, - Role, -} from "@fosscord/util"; +import { getPermission, listenEvent, Member, Role } from "@fosscord/util"; import { LazyRequest } from "../schema/LazyRequest"; import { Send } from "../util/Send"; import { OPCODES } from "../util/Constants"; @@ -47,7 +40,7 @@ async function getMembers(guild_id: string, range: [number, number]) { const member_roles = members .map((m) => m.roles) .flat() - .unique((r) => r.id); + .unique((r: Role) => r.id); for (const role of member_roles) { // @ts-ignore -- cgit 1.5.1 From a03d470c93bc519ddf9f4f303f5a24e50ce2a78f Mon Sep 17 00:00:00 2001 From: developomp Date: Wed, 20 Oct 2021 09:15:52 +0900 Subject: prettier formatted /gateway --- gateway/.github/FUNDING.yml | 2 +- gateway/src/util/SessionUtils.ts | 4 +++- gateway/tsconfig.json | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'gateway/src') diff --git a/gateway/.github/FUNDING.yml b/gateway/.github/FUNDING.yml index f76b9015..43f3b63b 100644 --- a/gateway/.github/FUNDING.yml +++ b/gateway/.github/FUNDING.yml @@ -1 +1 @@ -open_collective: fosscord \ No newline at end of file +open_collective: fosscord diff --git a/gateway/src/util/SessionUtils.ts b/gateway/src/util/SessionUtils.ts index c66c7e76..bf854042 100644 --- a/gateway/src/util/SessionUtils.ts +++ b/gateway/src/util/SessionUtils.ts @@ -7,5 +7,7 @@ export function genVoiceToken() { } function genRanHex(size: number) { - return [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join(""); + return [...Array(size)] + .map(() => Math.floor(Math.random() * 16).toString(16)) + .join(""); } diff --git a/gateway/tsconfig.json b/gateway/tsconfig.json index b6ae9455..5ecb21e1 100644 --- a/gateway/tsconfig.json +++ b/gateway/tsconfig.json @@ -8,7 +8,11 @@ "incremental": true /* Enable incremental compilation */, "target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, - "lib": ["ES2015", "ES2020.BigInt", "DOM"] /* Specify library files to be included in the compilation. */, + "lib": [ + "ES2015", + "ES2020.BigInt", + "DOM" + ] /* Specify library files to be included in the compilation. */, "allowJs": true /* Allow javascript files to be compiled. */, "checkJs": true /* Report errors in .js files. */, // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ @@ -48,7 +52,9 @@ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ - "types": ["node"] /* Type declaration files to be included in compilation. */, + "types": [ + "node" + ] /* Type declaration files to be included in compilation. */, // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ -- cgit 1.5.1 From bff6087c8bb6a5dffcb70f6b02cb05538f885c9b Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 24 Oct 2021 12:59:43 +0200 Subject: :bug: fix event listener --- gateway/src/listener/listener.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gateway/src') diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts index 032b2375..060de65b 100644 --- a/gateway/src/listener/listener.ts +++ b/gateway/src/listener/listener.ts @@ -153,9 +153,11 @@ async function consume(this: WebSocket, opts: EventOpts) { !permission .overwriteChannel(data.permission_overwrites) .has("VIEW_CHANNEL") - ) + ) { return; - // No break needed here, we need to call the listenEvent function below + } + this.events[id] = await listenEvent(id, consumer, listenOpts); + break; case "RELATIONSHIP_ADD": this.events[data.user.id] = await listenEvent( data.user.id, -- cgit 1.5.1