From 657990fd15f34026c6d0daf520bdbbafdd2593f1 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Tue, 16 Aug 2022 00:47:38 -0400 Subject: [PATCH] cleaned up code --- index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7f3a8e5..1cd46b0 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matri import fs from "fs"; const storage = new SimpleFsStorageProvider("storage.json"); -const client = new MatrixClient(config.baseUrl, config.token, storage); +const client = new MatrixClient(config.homeserver, config.token, storage); AutojoinRoomsMixin.setupOnClient(client) client.start().then(() => console.log(`Client has started!\n`)); @@ -12,16 +12,23 @@ let messageCounter = 0; // ? event listener: logs messages sent into file client.on("room.message", (roomId, event) => { - if (!event["content"] || event["sender"] === config.userId) return; - messageCounter = messageCounter + 1; + if (!event["content"] || event["sender"] === config.user) return; + ++messageCounter; fs.appendFile('training-matrix.txt', event["content"]["body"] + "\n", function (err) { if (err) throw err; - console.log(messageCounter + "\t" + event["content"]["body"]); + // console.log(messageCounter + "\t" + event["content"]["body"]); }); + if (lineCount(config.file) < config.size) return; // ? don't start generating messages until a big enough dataset is present + + // TODO: train AI every Nth message? // ? send message every N messages using the training data - if (!(messageCounter % 7)) { + if (!(messageCounter % config.frequency)) { + console.log("Generating message..."); client.sendText(roomId, "Hello, World!"); // TODO: exec py function to gen message str }; }); +function lineCount(text) { + return fs.readFileSync(text).toString().split("\n").length - 1; +}