cleaned up code
This commit is contained in:
parent
31688c2dba
commit
657990fd15
1 changed files with 12 additions and 5 deletions
17
index.js
17
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue