Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user