diff --git a/index.js b/index.js index f493225..59f4675 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import config from './config.json' assert {type: "json"}; import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matrix-bot-sdk"; +import fs from "fs"; const storage = new SimpleFsStorageProvider("storage.json"); const client = new MatrixClient(config.baseUrl, config.token, storage); @@ -7,7 +8,20 @@ const client = new MatrixClient(config.baseUrl, config.token, storage); AutojoinRoomsMixin.setupOnClient(client) client.start().then(() => console.log(`Client has started!`)); +let messageCounter = 0; + +// ? event listener: logs messages sent into file client.on("room.message", (roomId, event) => { - if (! event["content"] || event["sender"] === config.userId) return; - // code here -}) + 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 + if (messageCounter % 7) { + client.sendText(roomId, "Hello, World!"); // TODO: exec py function to gen message str + }; +}); +