text-gen-bot/index.js

28 lines
1 KiB
JavaScript
Raw Normal View History

2022-08-15 17:28:08 -04:00
import config from './config.json' assert {type: "json"};
import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matrix-bot-sdk";
2022-08-15 19:48:20 -04:00
import fs from "fs";
2022-08-15 17:28:08 -04:00
const storage = new SimpleFsStorageProvider("storage.json");
const client = new MatrixClient(config.baseUrl, config.token, storage);
AutojoinRoomsMixin.setupOnClient(client)
client.start().then(() => console.log(`Client has started!`));
2022-08-15 19:48:20 -04:00
let messageCounter = 0;
// ? event listener: logs messages sent into file
2022-08-15 17:28:08 -04:00
client.on("room.message", (roomId, event) => {
2022-08-15 19:48:20 -04:00
if (!event["content"] || event["sender"] === config.userId) return;
messageCounter = messageCounter + 1;
fs.appendFile('training-matrix.txt', event["content"]["body"] + "\n", function (err) {
if (err) throw err;
console.log(messageCounter + "\t" + event["content"]["body"]);
});
// ? send message every N messages using the training data
2022-08-15 20:11:10 -04:00
if (!(messageCounter % 7)) {
2022-08-15 19:48:20 -04:00
client.sendText(roomId, "Hello, World!"); // TODO: exec py function to gen message str
};
});