Compare commits

...

10 Commits

Author SHA1 Message Date
6fb0a6f726 Added fork note to README 2025-11-13 17:46:25 -05:00
zeuner
17c1ae786d
Update mod name in README and init (#15)
* mod.conf calls it `matrix_chat` now

* mod.conf calls it `matrix_chat` now

Co-authored-by: Isidor Zeuner <minetest@quidecco.de>
2022-01-21 18:57:51 +00:00
Panquesito7
cd2c6c949c Update "mod.conf" to set description (#13)
* Update mod.conf

* Delete deprecated description.txt
2019-09-04 08:21:16 +02:00
texmex
0b0535dff5
Rename mod 2018-06-24 10:16:21 +02:00
joenas
e93f6b436a Thats just stupid 2017-09-12 12:44:42 +02:00
joenas
d316776ed0 Added note to readme about WIP 2017-09-12 11:31:13 +02:00
joenas
c3c6731d8b Breaking changes:
Removed port setting (fixes #9)
Throw errors when weird/faulty matrix url (work on #10)
Added neturl for url parsing
2017-09-12 11:30:03 +02:00
joenas
b601d5cc64 Updated README 2017-08-23 10:20:11 +02:00
Jon Neverland
b54f0df57b Remove need for secure.enable_security (#7)
With changes in lua-matrix mod now works with only secure.trusted_mods
2017-08-08 12:33:33 +02:00
joenas
fab8a5a729 Only send joins etc to configured room 2017-06-22 11:42:52 +02:00
11 changed files with 109 additions and 26 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "lua-matrix"]
path = lua-matrix
url = https://github.com/diggers-mt/lua-matrix
[submodule "neturl"]
path = neturl
url = https://github.com/golgote/neturl.git

View File

@ -1,3 +1,4 @@
This is a fork of [diggers-mt/matrix_chat](https://github.com/diggers-mt/matrix_chat).
# Matrix mod for Minetest
@ -5,6 +6,17 @@
This mod creates a bridge between a [Matrix](https://matrix.org) channel and the in-game chat.
The code is shamelessly based on the [irc](https://github.com/minetest-mods/irc) mod and examples from [lua-matrix](https://github.com/aperezdc/lua-matrix).
This branch (`master`) needs a Matrix user that listens for messages and sends to Minetest. Chat messages posted in-game
will be sent with the bot to the Matrix channel like so:
```
@minetestbot: <myuser> hello world
```
For a bridge where virtual users are created in Matrix, checkout the [appservice](https://github.com/diggers-mt/minetest-matrix/tree/appservice) branch!
**This is a work in progress**
Until we have a stable release, expect breaking changes and whatnot.
## Installing
@ -20,6 +32,8 @@ luarocks-5.1 install lua-cjson
brew install openssl
luarocks-5.1 install cqueues CRYPTO_DIR=/usr/local/opt/openssl/ OPENSSL_DIR=/usr/local/opt/openssl #https://github.com/wahern/cqueues/wiki/Installation-on-OSX#via-brew
luarocks-5.1 install luaossl CRYPTO_DIR=/usr/local/opt/openssl/ OPENSSL_DIR=/usr/local/opt/openssl
luarocks-5.1 install luasocket
luarocks-5.1 install luasec OPENSSL_DIR=/usr/local/opt/openssl
export MATRIX_API_HTTP_CLIENT=luasocket
```
@ -30,15 +44,17 @@ Tested on 16.04.
```bash
apt-get install lua5.1 luarocks lua-sec
luarocks install lua-cjson
luarocks install luasocket
luarocks install luasec
export MATRIX_API_HTTP_CLIENT=luasocket
```
You might need to prepend `sudo` to first and second commands.
For the moment you need to disabled mod security for lua-matrix to work. This will hopefully change.
For the moment you need to add `matrix_chat` to `secure.trusted_mods` for lua-matrix to work. This will hopefully change.
```
secure.enable_security = false
secure.trusted_mods = matrix_chat
```
[wiki]: https://wiki.minetest.net/Installing_mods
@ -50,12 +66,13 @@ secure.enable_security = false
* `matrix.password`: Password for Matrix user
* `matrix.server`: Server to connect to, include http(s), `https://matrix.org`
* `matrix.port`: Server port, default `8448`
* `matrix.server`: Server to connect to, include http(s) and port, `https://matrix.org`
* `matrix.room_id`: Room to join, `room_id` in matrix. Always starts with `!`
### Removed, don't use
* `matrix.port`: Server port, default `8448`
## License

View File

@ -28,6 +28,5 @@ end
setting("string", "user", nil, true) -- User name, fe @digbot:matrix.org
setting("string", "server", nil, true) -- Server address to connect to
setting("number", "port", 8448) -- Server port to connect to
setting("string", "room_id", nil, true) -- Channel to join (not needed?)
setting("string", "password", nil, true) -- Server password

41
debug.lua Normal file
View File

@ -0,0 +1,41 @@
function eprintf(fmt, ...)
minetest.log("info", fmt:format(...))
end
function table_print (tt, indent, done)
done = done or {}
indent = indent or 0
if type(tt) == "table" then
local sb = {}
for key, value in pairs (tt) do
table.insert(sb, string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done [value] then
done [value] = true
table.insert(sb, "{\n");
table.insert(sb, table_print (value, indent + 2, done))
table.insert(sb, string.rep (" ", indent)) -- indent it
table.insert(sb, "}\n");
elseif "number" == type(key) then
table.insert(sb, string.format("\"%s\"\n", tostring(value)))
else
table.insert(sb, string.format(
"%s = \"%s\"\n", tostring (key), tostring(value)))
end
end
return table.concat(sb)
else
return tt .. "\n"
end
end
function to_string( tbl )
if "nil" == type( tbl ) then
return tostring(nil)
elseif "table" == type( tbl ) then
return table_print(tbl)
elseif "string" == type( tbl ) then
return tbl
else
return tostring(tbl)
end
end

View File

@ -1 +0,0 @@
This mod creates a bridge between a Matrix channel and the in-game chat!

View File

@ -8,11 +8,12 @@ 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.")
"to work. Please add matrix_chat to secure.trusted_mods.")
end
ie.package.path =
modpath.."/lua-matrix/?.lua;"
..modpath.."/neturl/lib/?.lua;"
..ie.package.path
matrix = {
@ -24,12 +25,16 @@ matrix = {
}
dofile(modpath.."/config.lua")
dofile(modpath.."/debug.lua")
local function eprintf(fmt, ...)
minetest.log("info", fmt:format(...))
end
-- Temporarily set require so that LuaIRC can access it
local old_require = require
require = ie.require
local client = require("matrix").client(matrix.config.server..":"..matrix.config.port)
dofile(modpath.."/validate_server.lua")
local hs_url = validate_server(matrix.config.server)
local client = require("matrix").client(hs_url)
local start_ts = os.time() * 1000
@ -132,13 +137,13 @@ function matrix.disconnect(message)
end
end
function matrix.say(to, message)
if not message then
message = to
to = matrix.config.channel
end
to = to or matrix.config.channel
function matrix.say(message)
for room_id, room in pairs(client.rooms) do
room:send_text(message)
if room.room_id == matrix.config.room_id then
room:send_text(message)
end
end
end
-- Restore old (safe) functions
require = old_require

@ -1 +1 @@
Subproject commit 2946b558101a22dd0770a2548f938ada86475256
Subproject commit 151355a7904640b98eef6dd59e43adefc0d178ea

View File

@ -1 +1,2 @@
name = matrix
name = matrix_chat
description = This mod creates a bridge between a Matrix channel and the in-game chat.

1
neturl Submodule

@ -0,0 +1 @@
Subproject commit e69ad0d005d7d70ff445d823ff69f1b41b6157ea

View File

@ -7,10 +7,6 @@ matrix.user (Username) string
# Server to connect to, include http(s)
matrix.server (Matrix server) string https://matrix.org
# Server port.
# The standard matrix port is 8448
matrix.port (Server port) int 8448
# Channel the bot joins after connecting.
matrix.room_id (Channel to join) string

21
validate_server.lua Normal file
View File

@ -0,0 +1,21 @@
local url = require "net.url"
function validate_server(hs_url)
u = url.parse(hs_url):normalize()
if not (u.host and u.scheme) then
return error("'"..hs_url.."' doesn't look like a valid url. Please specify scheme (http/s) and hostname")
end
if u.port and u.port == 8448 and u.scheme == 'http' then
return error("Port 8448 is for https, make sure your homeserver URL is correct")
end
if u.port and u.port == 8008 and u.scheme == 'https' then
minetest.log("warn", "Port 8008 is not https, make sure your homeserver URL is correct")
end
return hs_url
end