generated from array-in-a-matrix/matrix-bot-template
every 10th message send reaction
This commit is contained in:
parent
c15c5b365c
commit
790c490ca8
22
index.js
22
index.js
|
@ -52,11 +52,22 @@ const countCommand = async (roomId, message) => {
|
|||
}
|
||||
};
|
||||
|
||||
const addReaction = async (roomId, message) => {
|
||||
client.sendEvent(roomId, "m.reaction", {
|
||||
"m.relates_to": {
|
||||
"event_id":message["event_id"],
|
||||
"key":String(data.count[message["sender"]]),
|
||||
"rel_type": "m.annotation"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const addCount = async (roomId, message) => {
|
||||
if (!(message["sender"] in data.count)) {
|
||||
data.count[message["sender"]] = 0;
|
||||
}
|
||||
if (++data.count[message["sender"]] % 10 === 0) {
|
||||
addReaction(roomId, message);
|
||||
client.sendNotice(roomId, `${message["sender"]} said linux ${data.count[message["sender"]]} times!`);
|
||||
}
|
||||
if (data.count[message["sender"]] > data.max.count) {
|
||||
|
@ -74,16 +85,6 @@ const addCount = async (roomId, message) => {
|
|||
}
|
||||
};
|
||||
|
||||
const addReaction = async (roomId, message) => {
|
||||
client.sendEvent(roomId, "m.reaction", {
|
||||
"m.relates_to": {
|
||||
"event_id":message["event_id"],
|
||||
"key":String(data.count[message["sender"]]),
|
||||
"rel_type": "m.annotation"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(client);
|
||||
client.start().then(() => {
|
||||
clearTimeout(error1);
|
||||
|
@ -104,7 +105,6 @@ client.on("room.message", (roomId, event) => {
|
|||
}
|
||||
if (event["content"]["body"].match(/l*.i.*n.*u.*x/gi)){
|
||||
addCount(roomId, event);
|
||||
addReaction(roomId, event);
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue