Skip to content
Snippets Groups Projects
Select Git revision
7 results Searching

webpack.config.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    init.lua 3.81 KiB
    -- This file is licensed under the terms of the BSD 2-clause license.
    -- See LICENSE.txt for details.
    
    local modpath = minetest.get_modpath(minetest.get_current_modname())
    
    -- Handle mod security if needed
    local ie, req_ie = _G, minetest.request_insecure_environment
    if req_ie then ie = req_ie() end
    if not ie then
      error("The Matrix mod requires access to insecure functions in order "..
        "to work. Please disable mod security. This will hopefully change.")
    end
    
    ie.package.path =
        modpath.."/lua-matrix/?.lua;"
        ..ie.package.path
    
    matrix = {
      version = "0.0.1",
      joined_players = {},
      connected = false,
      modpath = modpath,
      lib = lib,
    }
    
    dofile(modpath.."/config.lua")
    
    local function eprintf(fmt, ...)
      minetest.log("info", fmt:format(...))
    end
    
    local client = require("matrix").client(matrix.config.server..":"..matrix.config.port)
    
    local start_ts = os.time() * 1000
    
    client:hook("invite", function (client, room)
      -- When invited to a room, join it
      eprintf("Invited to room %s\n", room)
      if room.room_id == matrix.config.room_id then
        client:join_room(room)
      end
    end):hook("logged-in", function (client)
      matrix.connected = true
      eprintf("Logged in successfully\n")
    end):hook("logged-out", function (client)
      eprintf("Logged out... bye!\n")
      matrix.connected = false
    end):hook("left", function (client, room)
      eprintf("Left room %s, active rooms:\n", room)
      for room_id, room in pairs(client.rooms) do
        assert(room_id == room.room_id)
        eprintf("  - %s\n", room)
      end
    end):hook("joined", function (client, room)
      eprintf("Active rooms:\n")
      for room_id, room in pairs(client.rooms) do
        assert(room_id == room.room_id)
        eprintf("  - %s\n", room)
      end
    
       --room:send_text("Type “!bot quit” to make the bot exit")
    
      room:hook("message", function (room, sender, message, event)
        if event.origin_server_ts < start_ts then
          eprintf("%s: (Skipping message sent before bot startup)\n", room)
          return
        end
        if sender == room.client.user_id then
          eprintf("%s: (Skipping message sent by ourselves)\n", room)
          return