22 lines
959 B
JavaScript
22 lines
959 B
JavaScript
import config from './config.json' assert {type: "json"};
|
|
import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matrix-bot-sdk";
|
|
|
|
const storage = new SimpleFsStorageProvider("storage.json");
|
|
const client = new MatrixClient(config.homeserver, config.token, storage);
|
|
|
|
AutojoinRoomsMixin.setupOnClient(client);
|
|
client.start().then(() => console.log(`Client has entered the matrix!`));
|
|
|
|
client.on("room.message", (roomId, event) => {
|
|
if (!event["content"] || event["sender"] === config.user) return;
|
|
try {
|
|
if (event["content"]["body"].toLowerCase().includes("real")) {
|
|
client.replyText(roomId, event, "real")
|
|
// console.log("real => roomId: " + roomId + " author: " + event["sender"] + " message: " + event["content"]["body"])
|
|
console.table([roomId, event["sender"], event["content"]["body"]])
|
|
}
|
|
} catch (error) {
|
|
console.error("Ran into an error:\n" + error)
|
|
}
|
|
})
|