generated from array-in-a-matrix/matrix-bot-template
cleanned up code + fixed message undefined bug
This commit is contained in:
parent
13c6b90332
commit
4a8f33528a
24
index.js
24
index.js
|
@ -37,19 +37,13 @@ const countCommand = async (roomId, message) => {
|
|||
let count = data.count[message["sender"]]
|
||||
|
||||
if(isNaN(count)){
|
||||
client.replyNotice(roomId, message, `You did not say linux.`)
|
||||
return;
|
||||
client.replyNotice(roomId, message, `You did not say linux.`);
|
||||
} else if(count === 1){
|
||||
client.replyNotice(roomId, message, `You said linux 1 time!`);
|
||||
} else {
|
||||
client.replyNotice(roomId, message, `You said linux ${count} times!`);
|
||||
};
|
||||
|
||||
//prevent undefined/NaN
|
||||
switch(count){
|
||||
case 1:
|
||||
client.replyNotice(roomId, message, `You said linux 1 time!`)
|
||||
break;
|
||||
default:
|
||||
client.replyNotice(roomId, message, `You said linux ${count} times!`)
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const addReaction = async (roomId, message) => {
|
||||
|
@ -77,6 +71,7 @@ const addCount = async (roomId, message) => {
|
|||
};
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(client);
|
||||
client.addPreprocessor(new RichRepliesPreprocessor(false));
|
||||
client.start().then(() => {
|
||||
clearTimeout(error1);
|
||||
// console.log(`Logged into ${client.guilds.cache.size} rooms`); // ? this is possible i think idk how tho
|
||||
|
@ -94,13 +89,6 @@ 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"
|
||||
}
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue