spammy-matrix-bots/index.js

30 lines
1,001 B
JavaScript
Raw Permalink Normal View History

2023-11-06 13:56:32 -05:00
import config from "./config.json" assert { type: "json" };
import {
MatrixClient,
SimpleFsStorageProvider,
AutojoinRoomsMixin,
RichRepliesPreprocessor,
} from "matrix-bot-sdk";
2023-01-03 23:40:02 -05:00
const storage = new SimpleFsStorageProvider("storage.json");
const client = new MatrixClient(config.homeserver, config.token, storage);
AutojoinRoomsMixin.setupOnClient(client);
2023-11-06 13:56:32 -05:00
client.addPreprocessor(new RichRepliesPreprocessor(false));
client.start().then(() => console.log(`Client has started!`));
2023-01-03 23:40:02 -05:00
2023-11-06 13:56:32 -05:00
// ? event listener
2023-01-03 23:40:02 -05:00
client.on("room.message", (roomId, event) => {
2023-11-06 13:56:32 -05:00
// ? 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();
2023-01-27 10:19:10 -05:00
2023-11-06 22:44:37 -05:00
if (message.match(/m*.e*.o*.w/gi)) {
2023-11-06 13:56:32 -05:00
let msg = "meow";
while (Math.floor(Math.random() * 5)) {
msg = msg.concat(" meow");
}
2023-11-06 13:56:32 -05:00
client.replyNotice(roomId, event, msg);
2023-01-03 23:40:02 -05:00
}
2023-11-06 13:56:32 -05:00
});