From 7f8f57603a732e0dcedc0fba5069cd77385b58a2 Mon Sep 17 00:00:00 2001 From: tursom Date: Fri, 11 Oct 2024 16:53:41 +0800 Subject: [PATCH] update --- chat.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/chat.js b/chat.js index 38cf15f..66ed2d6 100644 --- a/chat.js +++ b/chat.js @@ -3,6 +3,12 @@ const axios = require('axios'); const http = require('http'); const { once } = require("node:events"); +fs.mkdir("./logs", { recursive: true }, (err) => { + if (err) { + logger.error("an error occurred while creating the logs directory: " + err); + } +}); + async function sendMsg(req, res) { let body = ''; req.on('data', chunk => { @@ -27,6 +33,19 @@ async function sendMsg(req, res) { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Success\n'); + + fs.appendFile("./logs/chat.jsonl", JSON.stringify({ + date: dateToString(response.server_timestamp), + echo: true, + id: requests.id, + name: getUserInfo(client.steamUser.steamID).player_name, + message: response.modified_message, + ordinal: response.ordinal, + }) + "\n", (e) => { + if (e) { + logger.error("an error occurred while writing chat log file: " + e); + } + }); }) } @@ -103,6 +122,15 @@ function readFileAsBuffer(filePath) { }); } +function dateToString(date) { + return dateformat(date, "yyyy-mm-dd HH:MM:ss.l"); +} + +async function getUserInfo(steamID) { + return client.getUserInfo(steamID, (ignore) => { + }); +} + server.listen(3000, '0.0.0.0', () => { console.log('Server running at http://0.0.0.0:3000/'); });