updated rulefiltering, added selfmonitor (C4ll)
This commit is contained in:
13
index.js
13
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,7 +46,9 @@ mqttClient.on('message', async (topic, payload) => {
|
||||
const data = JSON.parse(payload.toString());
|
||||
// console.log(`MQTT message on ${topic}: ${data?.msg}`);
|
||||
|
||||
rules.forEach((r) => {
|
||||
rules
|
||||
.filter(({ name }) => enabledRules.includes(name))
|
||||
.forEach((r) => {
|
||||
if (r.rule(data)) {
|
||||
console.log(`${topic} aplying ${r.name}`);
|
||||
postMessage(r.msg(data));
|
||||
|
16
rules.js
16
rules.js
@@ -1,3 +1,5 @@
|
||||
const config = require('./config.json');
|
||||
|
||||
// Helper: SNR (dB) to emoji "bar chart"
|
||||
function snrToBars(db) {
|
||||
const snr = Math.max(Math.min(db, 0), -30); // clamp -30 to 0
|
||||
@@ -72,7 +74,14 @@ function formatMessageWX(data) {
|
||||
const dirEmoji = getWindDirectionEmoji(wind_dir_deg);
|
||||
const readableTime = new Date(timestamp).toLocaleString();
|
||||
// Acurite-986 is giving celsius under _F
|
||||
const temperature = temperature_C || temperature_F;
|
||||
let temperature;
|
||||
if (temperature_C != null) {
|
||||
temperature = temperature_C;
|
||||
} else if (temperature_F != null) {
|
||||
temperature = (temperature_F - 32) * 5 / 9;
|
||||
} else {
|
||||
temperature = null; // or handle the missing value case as needed
|
||||
}
|
||||
|
||||
const response =
|
||||
`${emoji.mic} reporting ${model}\n` +
|
||||
@@ -131,6 +140,11 @@ module.exports = [
|
||||
rule: (data) => data?.msg?.includes('CQ'),
|
||||
msg: formatMessageCQ,
|
||||
},
|
||||
{
|
||||
name: "C4LL",
|
||||
rule: (data) => data?.msg?.includes(config.callsign),
|
||||
msg: formatMessageCQ,
|
||||
},
|
||||
{
|
||||
name: "WX",
|
||||
// Not to miss the zero degree
|
||||
|
Reference in New Issue
Block a user