generated from array-in-a-matrix/matrix-bot-template
30 lines
1.3 KiB
JavaScript
30 lines
1.3 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);
|
|
|
|
client.addPreprocessor(new RichRepliesPreprocessor(false)); // ? remove replied message
|
|
client.start().then(() => console.log(`Client has started!`));
|
|
|
|
client.on("room.message", (roomId, event) => {
|
|
// ? ignore empty messages, message sent by other users or messages that are not replies
|
|
if (! event["content"] || event["sender"] != config.user) return;
|
|
if( !event["content"].hasOwnProperty(["m.relates_to"]) ) return;
|
|
// ? react to message
|
|
const message = event["content"]["body"].toLowerCase()
|
|
if (message.startsWith(config.prefix + "react") || message.startsWith(config.prefix + "r") ){
|
|
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"
|
|
}
|
|
});
|
|
// ? delete command message
|
|
client.redactEvent(roomId, event["event_id"], "selfbot");
|
|
};
|
|
});
|
|
|
|
|