From 22107c725be2b2aafcc353857542aec0bf287cfc Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Mon, 6 Nov 2023 13:56:32 -0500 Subject: [PATCH] overhaul --- index.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 005f869..2927946 100644 --- a/index.js +++ b/index.js @@ -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); } -}) +});