This commit is contained in:
array-in-a-matrix 2023-10-29 16:44:04 -04:00
commit e74ec5e8f5

View file

@ -5,7 +5,7 @@ import fs from "fs";
const storage = new SimpleFsStorageProvider("storage.json");
const client = new MatrixClient(config.homeserver, config.token, storage);
let lastUpdate, timeoutExists, data;
let data;
const error1 = setTimeout(function () {
console.log("\x1b[41m", "ERROR: UNABLE TO CONNECT TO MATRIX SERVER");
@ -73,15 +73,6 @@ const addCount = async (roomId, message) => {
if (data.count[message["sender"]] > data.max.count) {
data.max.count++;
data.max.username = message["sender"];
if (lastUpdate + 5000 < Date.now()) {
lastUpdate = Date.now();
} else if (!timeoutExists) {
setTimeout(() => {
lastUpdate = Date.now();
timeoutExists = false;
}, lastUpdate + 5000 - Date.now());
timeoutExists = true;
}
}
};
@ -90,8 +81,6 @@ client.start().then(() => {
clearTimeout(error1);
// console.log(`Logged into ${client.guilds.cache.size} rooms`); // ? this is possible i think idk how tho
data = readFromCache();
lastUpdate = Date.now();
timeoutExists = false;
});
client.on("room.message", (roomId, event) => {
@ -105,6 +94,13 @@ client.on("room.message", (roomId, event) => {
}
if (event["content"]["body"].match(/l*.i.*n.*u.*x/gi)){
addCount(roomId, event);
client.sendEvent(roomId, "m.reaction" ({
"m.relates_to": {
"event_id":event["event_id"],
"key":data.count[message["sender"]],
"rel_type": "m.annotation"
}
}))
}
})