From 54bae2f98612e88344811a7bef173e87d0537169 Mon Sep 17 00:00:00 2001 From: alexbcberio Date: Thu, 6 Jan 2022 18:21:16 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Add=20tsconfig=20and=20fix=20som?= =?UTF-8?q?e=20TS=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/helpers/webServer.ts | 7 +++--- .../pubSubClient/actions/russianRoulette.ts | 23 +++++++------------ tsconfig.json | 22 ++++++++++++++++++ 3 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 tsconfig.json diff --git a/src/backend/helpers/webServer.ts b/src/backend/helpers/webServer.ts index 0b568b2..0a56176 100644 --- a/src/backend/helpers/webServer.ts +++ b/src/backend/helpers/webServer.ts @@ -1,10 +1,11 @@ +import * as WebSocket from "ws"; +import * as express from "express"; + import { AddressInfo, Socket } from "net"; import { IncomingMessage, Server } from "http"; import { save, scheduledActions } from "./miniDb"; import { Action } from "../../interfaces/actions/Action"; -import WebSocket from "ws"; -import express from "express"; import { handleClientAction } from "../chatClient"; import { isDevelopment } from "./util"; import { join } from "path"; @@ -73,7 +74,7 @@ function onListening() { } function onUpgrade(req: IncomingMessage, socket: Socket, head: Buffer) { - wsServer.handleUpgrade(req, socket, head, (socket) => { + wsServer.handleUpgrade(req, socket, head, (socket: WebSocket) => { wsServer.emit("connection", socket, req); }); } diff --git a/src/backend/pubSubClient/actions/russianRoulette.ts b/src/backend/pubSubClient/actions/russianRoulette.ts index 640efa6..7bf7348 100644 --- a/src/backend/pubSubClient/actions/russianRoulette.ts +++ b/src/backend/pubSubClient/actions/russianRoulette.ts @@ -41,24 +41,17 @@ async function russianRoulette( // eslint-disable-next-line require-atomic-updates msg.message = win ? "" : "got shot"; - const promises: Array> = []; + try { + if (!win) { + await timeout(channel, userDisplayName, timeoutSeconds, "F en la ruleta"); - if (!win) { - promises.push( - timeout(channel, userDisplayName, timeoutSeconds, "F en la ruleta") - ); - promises.push( - say( + await say( channel, `PepeHands ${userDisplayName} no ha sobrevivido para contarlo` - ) - ); - } else { - promises.push(say(channel, `rdCool Clap ${userDisplayName}`)); - } - - try { - await Promise.allSettled(promises); + ); + } else { + await say(channel, `rdCool Clap ${userDisplayName}`); + } } catch (e) { if (e instanceof Error) { console.log(`${LOG_PREFIX}${e.message}`); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c1612da --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "outDir": "dist", + "target": "ES2017", + "module": "CommonJS", + "moduleResolution": "Node", + + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "alwaysStrict": true, + "exactOptionalPropertyTypes": true, + "noFallthroughCasesInSwitch": true, + // "noImplicitAny": true, // enabled on strict mode + "noImplicitReturns": true, + // "noImplicitThis": true, // enabled on strict mode + "noUnusedLocals": true, + "noUnusedParameters": true, + "strict": true + }, + // "files": ["src/index.ts"], + "include": ["src/**/*"] +}