initial commit
This commit is contained in:
commit
b0c2736f3e
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/node_modules
|
42
MatrixBaseBot.js
Normal file
42
MatrixBaseBot.js
Normal 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
1132
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user