diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..338c30b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.lua diff --git a/README.md b/README.md index 67f9e4b..9d7eb35 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,29 @@ # Minetest Matrix bridge +This is a server-side mod for Minetest, creating a bridge between a Matrix instant-messaging room and a Minetest server. + +**Early development**, do not use it in production yet. + +This mod does not use any additional lua library, only standard Minetest API. + +## Install + +The mod needs an existing account on the Matrix server, and access to the room. + +Copy the template config to `config.lua`: + +```bash +cp config.template.lua config.lua +``` + +then edit `config.lua`. + +Add `matrix_bridge` to `secure.http_mods` (e.g. in the file `/etc/minetest/minetest.conf`): + +``` +secure.http_mods = matrix_bridge +``` + ## Contributing See [Matrix API docs](https://www.matrix.org/docs/guides/client-server-api). diff --git a/config.template.lua b/config.template.lua new file mode 100644 index 0000000..449359e --- /dev/null +++ b/config.template.lua @@ -0,0 +1,8 @@ +-- Rename `config.template.lua` to `config.lua` +-- Please edit only `config.lua`. +-- `config.lua` will not be overwritten by updates. + +MATRIX_SERVER = "https://matrix.txmn.tk:8448" +MATRIX_ROOM = "!xReNhJbGJeGK4fysJU:matrix.txmn.tk" +MATRIX_USERNAME = "minebot" +MATRIX_PASSWORD = "PUT-YOUR-PASSWORD-HERE" diff --git a/init.lua b/init.lua index 1524801..23e37ce 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,6 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) +dofile(modpath.."/config.lua") dofile(modpath.."/debug.lua") local http = minetest.request_http_api() @@ -13,7 +14,7 @@ local txid = 0 function send_message(msg) txid = txid + 1 http.fetch({ - url = "https://matrix.txmn.tk:8448/_matrix/client/r0/rooms/!xReNhJbGJeGK4fysJU:matrix.txmn.tk/send/m.room.message/"..txid.."?access_token="..token, + url = MATRIX_SERVER.."/_matrix/client/r0/rooms/"..MATRIX_ROOM.."/send/m.room.message/"..txid.."?access_token="..token, method = "PUT", extra_headers = {"Content-Type: application/json"}, data = minetest.write_json({msgtype="m.text", body=msg}) @@ -22,10 +23,10 @@ function send_message(msg) end http.fetch({ - url = "https://matrix.txmn.tk:8448/_matrix/client/r0/login", + url = MATRIX_SERVER.."/_matrix/client/r0/login", method = "POST", extra_headers = {"Content-Type: application/json"}, - data = '{"type":"m.login.password","password":"PUT-PASSWORD-HERE","identifier":{"type":"m.id.user","user":"minebot"}}' + data = '{"type":"m.login.password","password":"'..MATRIX_PASSWORD..'","identifier":{"type":"m.id.user","user":"'..MATRIX_USERNAME..'"}}' }, function(res) if res.code == 200 then minetest.log("action", res.data)