send message every Nth message
This commit is contained in:
parent
abb29fd42a
commit
885bba8f9b
1 changed files with 17 additions and 3 deletions
20
index.js
20
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
|
||||
};
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue