This commit is contained in:
tursom 2024-10-11 16:53:41 +08:00
parent 5965c6f092
commit 7f8f57603a

28
chat.js
View File

@ -3,6 +3,12 @@ const axios = require('axios');
const http = require('http'); const http = require('http');
const { once } = require("node:events"); 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) { async function sendMsg(req, res) {
let body = ''; let body = '';
req.on('data', chunk => { req.on('data', chunk => {
@ -27,6 +33,19 @@ async function sendMsg(req, res) {
res.statusCode = 200; res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain'); res.setHeader('Content-Type', 'text/plain');
res.end('Success\n'); 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', () => { server.listen(3000, '0.0.0.0', () => {
console.log('Server running at http://0.0.0.0:3000/'); console.log('Server running at http://0.0.0.0:3000/');
}); });