This commit is contained in:
Pascal Engélibert 2022-01-21 16:02:39 +01:00
parent 5857912e6a
commit 7cb6ac4cbd
Signed by: tuxmain
GPG Key ID: 3504BC6D362F7DCA
4 changed files with 37 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.lua

View File

@ -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).

8
config.template.lua Normal file
View File

@ -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"

View File

@ -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)