initial commit

This commit is contained in:
root 2021-09-17 01:56:39 +00:00
commit b0c2736f3e
3 changed files with 1175 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

42
MatrixBaseBot.js Normal file
View File

@ -0,0 +1,42 @@
const sdk = require("matrix-bot-sdk");
const MatrixClient = sdk.MatrixClient;
const SimpleFsStorageProvider = sdk.SimpleFsStorageProvider;
const AutojoinRoomsMixin = sdk.AutojoinRoomsMixin;
const homeserverUrl = "https://matrix-linux.cloud"; // make sure to update this with your url
const accessToken = "";
const storage = new SimpleFsStorageProvider("bot.json");
const client = new MatrixClient(homeserverUrl, accessToken, storage);
AutojoinRoomsMixin.setupOnClient(client);
function sendMessage(channel, message) {
const content = {
"body": message,
"msgtype": "m.text",
};
client.sendEvent(channel, "m.room.message", content, "", (err, res) => {
console.log(err).code;
});
}
client.on("room.message", (roomId, event) => {
activeChannel = roomId
commandToRun = event.content.body.replace("^ ", "").replace("6", "")
if (!event["content"]) return;
const sender = event["sender"];
const body = event["content"]["body"];
if (event.unsigned.age > 300) return
if (commandToRun == "ping") {
sendMessage(activeChannel, "pong")
}
})
client.start().then(() => console.log("Client started!"));

1132
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff