Compare commits
3 Commits
b1037a815a
...
a08e5db048
Author | SHA1 | Date |
---|---|---|
Bram van den Heuvel | a08e5db048 | |
Bram van den Heuvel | c7d116e116 | |
Bram van den Heuvel | 2a5563cd8b |
|
@ -1,3 +1,3 @@
|
|||
[submodule "lua-json"]
|
||||
path = lua-json
|
||||
url = https://git.noordstar.me/Dependencies/lua-json.git
|
||||
url = https://git.noordstar.me/Bram/lua-json.git
|
||||
|
|
45
README.md
45
README.md
|
@ -1,3 +1,46 @@
|
|||
# mt-matrix
|
||||
|
||||
Matrix-Minetest bridge
|
||||
This repository serves as a bridge between Matrix and Minetest servers.
|
||||
|
||||
## Setup
|
||||
|
||||
1. Clone this repository into your Minetest mods folder:
|
||||
|
||||
```sh
|
||||
git clone --recursive https://git.noordstar.me/Bram/mt-matrix.git
|
||||
```
|
||||
|
||||
2. To access the Matrix homeserver, this mod needs access to HTTP calls. Add this mod to your `minetest.conf` settings at the field `secure.http_mods`:
|
||||
|
||||
```
|
||||
# Comma-separated list of mods that are allowed to access HTTP APIs, which
|
||||
# allow them to upload and download data to/from the internet.
|
||||
# type: string
|
||||
secure.http_mods=mt_matrix
|
||||
```
|
||||
|
||||
3. Fill in the values in `config.lua`:
|
||||
|
||||
```lua
|
||||
config = {
|
||||
|
||||
-- The user one expects to log in as
|
||||
user = "@minetest:matrix.directory",
|
||||
|
||||
-- The URL where the user communicates with the Matrix homeserver
|
||||
url = "https://synapse.matrix.directory",
|
||||
|
||||
-- Room ID that the Minetest server bridges to
|
||||
room_id = "!fePhSRwZXgzmREGqFV:matrix.directory",
|
||||
|
||||
-- Access token to access the Matrix homeserver
|
||||
access_token = "syt_bWluZXRlc3Q_TafRsEjsCwVaCxFYCIkT_2iChoq",
|
||||
|
||||
-- Average timeout duration
|
||||
sync_timeout = 30
|
||||
}
|
||||
```
|
||||
|
||||
4. Add the mod to your world configuration.
|
||||
|
||||
Now you're good to go! Feel free to create issues or send me a message.
|
|
@ -0,0 +1,78 @@
|
|||
-- Create code to load modules
|
||||
modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
local function load(name)
|
||||
dofile(modpath.."/"..name..".lua")
|
||||
end
|
||||
|
||||
-- Load HTTP privileges
|
||||
local http_api = minetest.request_http_api and minetest.request_http_api()
|
||||
if http_api == nil then
|
||||
error(
|
||||
"This mod has no access to HTTP requests - which is crucial for it "..
|
||||
"to relay messages to Matrix. Please enable it at the "..
|
||||
"`secure.http_mods` or the `secure.trusted_mods` settings!"
|
||||
)
|
||||
end
|
||||
|
||||
-- Load standard configuration
|
||||
load("config")
|
||||
|
||||
-- Load JSON module
|
||||
json = nil
|
||||
load("lua-json/json")
|
||||
if json == nil then
|
||||
error("Failed to load JSON module")
|
||||
end
|
||||
|
||||
-- Load Matrix modules
|
||||
matrix = {}
|
||||
load("lua/send")
|
||||
load("lua/sync")
|
||||
|
||||
-- Mod Minetest server
|
||||
minetest.register_on_chat_message(matrix.say(http_api))
|
||||
minetest.register_on_joinplayer(function(ObjectRef, last_login)
|
||||
local name = ObjectRef:get_player_name()
|
||||
matrix.send(http_api, name .. " has joined the Minetest server")
|
||||
end)
|
||||
minetest.register_on_leaveplayer(function(ObjectRef, timed_out)
|
||||
local name = ObjectRef:get_player_name()
|
||||
matrix.send(http_api, name .. " has left the Minetest server")
|
||||
end)
|
||||
minetest.register_on_dieplayer(function(ObjectRef, reason)
|
||||
local name = ObjectRef:get_player_name()
|
||||
matrix.send(http_api, name .. " has died! Reason:", reason)
|
||||
end)
|
||||
|
||||
-- Start Matrix sync
|
||||
local names = {}
|
||||
|
||||
matrix.sync_forever(http_api, function(event)
|
||||
local name = names[event.sender] or event.sender
|
||||
|
||||
if event.type == nil then
|
||||
elseif event.content == nil then
|
||||
elseif event.sender == config.user then
|
||||
elseif event.type == "m.room.message" then
|
||||
local msgtype = event.content.msgtype
|
||||
|
||||
if msgtype == nil then
|
||||
elseif msgtype == "m.text" then
|
||||
if event.content.body ~= nil then
|
||||
minetest.chat_send_all(name .. ": " .. event.content.body)
|
||||
end
|
||||
elseif msgtype == "m.audio" then
|
||||
minetest.chat_send_all(name .. " sent an audio message")
|
||||
elseif msgtype == "m.video" then
|
||||
minetest.chat_send_all(name .. " sent a video")
|
||||
elseif msgtype == "m.image" then
|
||||
minetest.chat_send_all(name .. " sent an image")
|
||||
end
|
||||
elseif event.type == "m.room.member" then
|
||||
if event.content.displayname ~= nil and event.state_key ~= nil then
|
||||
names[event.state_key] = event.content.displayname
|
||||
|
||||
minetest.chat_send_all("Adding Matrix user \"" .. names[event.state_key] .. "\" (" .. event.state_key .. ")")
|
||||
end
|
||||
end
|
||||
end)
|
Loading…
Reference in New Issue