This commit is contained in:
array-in-a-matrix 2023-11-06 13:56:32 -05:00
parent 601ef76759
commit 22107c725b

View file

@ -1,25 +1,29 @@
import config from './config.json' assert {type: "json"};
import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matrix-bot-sdk";
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.start().then(() => console.log(`meow`));
client.addPreprocessor(new RichRepliesPreprocessor(false));
client.start().then(() => console.log(`Client has started!`));
// ? event listener
client.on("room.message", (roomId, event) => {
if (!event["content"] || event["sender"].includes("_bot:")) return;
try {
// ? 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;
const message = event["content"]["body"].toLowerCase();
if (event["content"]["body"].toLowerCase().includes("meow")) {
let msg="meow";
while(Math.floor(Math.random() * 5)){
msg = msg.concat(" meow")
}
client.replyText(roomId, event, msg)
console.table([roomId, event["sender"], event["content"]["body"]])
if (message.match(/w*.e*o*w/gi)) {
let msg = "meow";
while (Math.floor(Math.random() * 5)) {
msg = msg.concat(" meow");
}
} catch (error) {
console.error("Ran into an error:\n" + error)
client.replyNotice(roomId, event, msg);
}
})
});