updated rulefiltering, added selfmonitor (C4ll)
This commit is contained in:
15
index.js
15
index.js
@@ -5,7 +5,14 @@ const rules = require('./rules.js');
|
||||
|
||||
// Matrix client
|
||||
const storage = new SimpleFsStorageProvider("matrix-storage.json");
|
||||
const matrix = new MatrixClient(config.matrix.homeserverUrl, config.matrix.accessToken, storage);
|
||||
const matrix = new MatrixClient(
|
||||
config.matrix.homeserverUrl,
|
||||
config.matrix.accessToken,
|
||||
storage);
|
||||
|
||||
const enabledRules = config.enabledRules;
|
||||
console.log(`Enabled Rules`, enabledRules.join(", "));
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(matrix);
|
||||
matrix.start().then(() => console.log("Matrix bot started"));
|
||||
|
||||
@@ -39,8 +46,10 @@ mqttClient.on('message', async (topic, payload) => {
|
||||
const data = JSON.parse(payload.toString());
|
||||
// console.log(`MQTT message on ${topic}: ${data?.msg}`);
|
||||
|
||||
rules.forEach((r) => {
|
||||
if (r.rule(data)) {
|
||||
rules
|
||||
.filter(({ name }) => enabledRules.includes(name))
|
||||
.forEach((r) => {
|
||||
if (r.rule(data)) {
|
||||
console.log(`${topic} aplying ${r.name}`);
|
||||
postMessage(r.msg(data));
|
||||
}
|
||||
|
Reference in New Issue
Block a user