matrix-selfbot/index.js
array-in-a-matrix 34063052e5 comments + ;
2023-11-05 19:51:33 -05:00

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);
AutojoinRoomsMixin.setupOnClient(client);
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
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"
}
});
// ? delete command message
client.redactEvent(roomId, event["event_id"], "Reaction command.");
};
});