spammy-matrix-bots/index.js
array-in-a-matrix f27c772835 fix regex
2023-11-06 22:44:37 -05:00

30 lines
1,001 B
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!`));
// ? event listener
client.on("room.message", (roomId, event) => {
// ? 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 (message.match(/m*.e*.o*.w/gi)) {
let msg = "meow";
while (Math.floor(Math.random() * 5)) {
msg = msg.concat(" meow");
}
client.replyNotice(roomId, event, msg);
}
});