generated from array-in-a-matrix/matrix-bot-template
if commanded react to event with given message
This commit is contained in:
parent
1cc7bed429
commit
34dda8ad48
24
index.js
24
index.js
|
@ -1,23 +1,25 @@
|
|||
import config from './config.json' assert {type: "json"};
|
||||
import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matrix-bot-sdk";
|
||||
import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin, RichRepliesPreprocessor } from "matrix-bot-sdk";
|
||||
|
||||
const storage = new SimpleFsStorageProvider("storage.json");
|
||||
const client = new MatrixClient(config.homeserver, config.token, storage);
|
||||
|
||||
AutojoinRoomsMixin.setupOnClient(client);
|
||||
client.addPreprocessor(new RichRepliesPreprocessor(false));
|
||||
client.start().then(() => console.log(`Client has started!`));
|
||||
|
||||
// ? event listener
|
||||
client.on("room.message", (roomId, event) => {
|
||||
// ? check if the message's text is not empty and isn't sent by the bot itself
|
||||
if (! event["content"] || event["sender"] === config.user) return;
|
||||
// ? if message starts with the bot's <prefix + command> then execute the command
|
||||
if (event["content"]["body"].toLowerCase().startsWith(config.prefix + "COMMAND")){
|
||||
|
||||
//
|
||||
// TODO: START CODE HERE
|
||||
//
|
||||
|
||||
if (! event["content"] || event["sender"] != config.user) return;
|
||||
if( !event["content"].hasOwnProperty(["m.relates_to"]) ) return;
|
||||
if (event["content"]["body"].toLowerCase().startsWith(config.prefix + "react")){
|
||||
client.sendEvent(roomId, "m.reaction", {
|
||||
"m.relates_to": {
|
||||
"event_id": event["content"]["m.relates_to"]["m.in_reply_to"]["event_id"],
|
||||
"key": String(event["content"]["body"].split(' ').slice(1).join(' ')),
|
||||
"rel_type": "m.annotation"
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue