generated from array-in-a-matrix/matrix-bot-template
27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
import config from './config.json' assert {type: "json"};
|
|
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!`));
|
|
|
|
client.on("room.message", (roomId, event) => {
|
|
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"
|
|
}
|
|
})
|
|
client.redactEvent(roomId, event["event_id"], "Reaction command.")
|
|
}
|
|
})
|
|
|
|
|