diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-01-20 18:10:47 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 18:10:47 +1100 |
commit | 084dc0be08555891cad4c2bb984822a62ec5ec9f (patch) | |
tree | ed2ca0fafefa2224ae32761f955f63935422a97d /src/gateway/events | |
parent | fix: route file regex (#956) (diff) | |
download | server-084dc0be08555891cad4c2bb984822a62ec5ec9f.tar.xz |
Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
Diffstat (limited to 'src/gateway/events')
-rw-r--r-- | src/gateway/events/Close.ts | 2 | ||||
-rw-r--r-- | src/gateway/events/Connection.ts | 7 | ||||
-rw-r--r-- | src/gateway/events/Message.ts | 15 |
3 files changed, 14 insertions, 10 deletions
diff --git a/src/gateway/events/Close.ts b/src/gateway/events/Close.ts index 6b069d0b..296ab5ee 100644 --- a/src/gateway/events/Close.ts +++ b/src/gateway/events/Close.ts @@ -26,7 +26,7 @@ import { User, } from "@fosscord/util"; -export async function Close(this: WebSocket, code: number, reason: string) { +export async function Close(this: WebSocket, code: number, reason: Buffer) { console.log("[WebSocket] closed", code, reason.toString()); if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout); if (this.readyTimeout) clearTimeout(this.readyTimeout); diff --git a/src/gateway/events/Connection.ts b/src/gateway/events/Connection.ts index 85ffb1ed..82081266 100644 --- a/src/gateway/events/Connection.ts +++ b/src/gateway/events/Connection.ts @@ -16,6 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/* eslint-disable @typescript-eslint/ban-ts-comment */ import WS from "ws"; import { genSessionId, WebSocket } from "@fosscord/gateway"; import { Send } from "../util/Send"; @@ -27,10 +28,12 @@ import { Message } from "./Message"; import { Deflate, Inflate } from "fast-zlib"; import { URL } from "url"; import { Config } from "@fosscord/util"; -var erlpack: any; +let erlpack: unknown; try { erlpack = require("@yukikaze-bot/erlpack"); -} catch (error) {} +} catch (error) { + /* empty */ +} // TODO: check rate limit // TODO: specify rate limit in config diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts index 57899a23..b949f273 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts @@ -27,14 +27,16 @@ import path from "path"; import fs from "fs/promises"; const bigIntJson = BigIntJson({ storeAsString: true }); -var erlpack: any; +let erlpack: { unpack: (buffer: Buffer) => Payload }; try { erlpack = require("@yukikaze-bot/erlpack"); -} catch (error) {} +} catch (error) { + /* empty */ +} export async function Message(this: WebSocket, buffer: WS.Data) { // TODO: compression - var data: Payload; + let data: Payload; if ( (buffer instanceof Buffer && buffer[0] === 123) || // ASCII 123 = `{`. Bad check for JSON @@ -44,9 +46,9 @@ export async function Message(this: WebSocket, buffer: WS.Data) { } else if (this.encoding === "json" && buffer instanceof Buffer) { if (this.inflate) { try { - buffer = this.inflate.process(buffer) as any; + buffer = this.inflate.process(buffer); } catch { - buffer = buffer.toString() as any; + buffer = buffer.toString(); } } data = bigIntJson.parse(buffer as string); @@ -78,7 +80,6 @@ export async function Message(this: WebSocket, buffer: WS.Data) { check.call(this, PayloadSchema, data); - // @ts-ignore const OPCodeHandler = OPCodeHandlers[data.op]; if (!OPCodeHandler) { console.error("[Gateway] Unkown opcode " + data.op); @@ -100,7 +101,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) { : undefined; try { - var ret = await OPCodeHandler.call(this, data); + const ret = await OPCodeHandler.call(this, data); Sentry.withScope((scope) => { scope.setSpan(transaction); scope.setUser({ id: this.user_id }); |