Baphomet is the dedicated bot for nulloctet matrix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

  1. let sdk = require("matrix-js-sdk");
  2. let config = require("./data/config.json");
  3. console.log("Running with config:");
  4. console.log(config);
  5. let client = sdk.createClient({
  6. baseUrl: config.baseUrl,
  7. accessToken: config.accessToken,
  8. userId: config.userId
  9. });
  10. function createBasicTextMessage(body) {
  11. return {
  12. "body": body,
  13. "msgtype": "m.text"
  14. }
  15. }
  16. function sendClientStatusUpdate() {
  17. config.statusRooms.forEach(roomId => {
  18. console.log("Notifying %s", roomId);
  19. client.sendMessage(roomId, createBasicTextMessage("Started!")).done(function() {
  20. console.log("Notified %s", roomId);
  21. })
  22. });
  23. }
  24. // Prep the bot
  25. client.on("sync", function (state, previousState, data) {
  26. switch (state) {
  27. case "PREPARED":
  28. sendClientStatusUpdate();
  29. break;
  30. }
  31. });
  32. // auto join rooms that an admin user has invited the bot to
  33. client.on("RoomMember.membership", function (event, member) {
  34. if (member.membership === "invite"
  35. && config.admin.indexOf(ember.userId) >= 0) {
  36. client.joinRoom(member.roomId).done(function () {
  37. console.log("Auto-joined %s", member.roomId);
  38. });
  39. }
  40. });
  41. client.startClient()