From bcb37278e1ce1b5c1eef3df91c7812333262ea62 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Wed, 26 Oct 2022 12:36:07 -0400 Subject: [PATCH] created template --- example.config.json | 7 +++++++ index.js | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 example.config.json create mode 100644 index.js diff --git a/example.config.json b/example.config.json new file mode 100644 index 0000000..dc403c7 --- /dev/null +++ b/example.config.json @@ -0,0 +1,7 @@ +{ + "homeserver": "", + "token": "", + "user": "@:", + "prefix": "!", +} + diff --git a/index.js b/index.js new file mode 100644 index 0000000..9b78f5f --- /dev/null +++ b/index.js @@ -0,0 +1,23 @@ +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 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; + // ? if message starts with the bot's then execute the command + if (event["content"]["body"].toLowerCase().startsWith(config.prefix + "COMMAND")){ + + // + // TODO: START CODE HERE + // + + } +}) +