Compare commits

..

No commits in common. "6fb0a6f726ce0ae8eb659f26bf630ee8091ea4ae" and "6679cbffe279d61aa39a82a18f3fd724121b9fa7" have entirely different histories.

11 changed files with 26 additions and 109 deletions

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[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,22 +1,10 @@
This is a fork of [diggers-mt/matrix_chat](https://github.com/diggers-mt/matrix_chat).
# Matrix mod for Minetest
This mod creates a bridge between a [Matrix](https://matrix.org) channel and the in-game chat.
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
@ -32,8 +20,6 @@ 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
```
@ -44,17 +30,15 @@ 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 add `matrix_chat` to `secure.trusted_mods` for lua-matrix to work. This will hopefully change.
For the moment you need to disabled mod security for lua-matrix to work. This will hopefully change.
```
secure.trusted_mods = matrix_chat
secure.enable_security = false
```
[wiki]: https://wiki.minetest.net/Installing_mods
@ -66,13 +50,12 @@ secure.trusted_mods = matrix_chat
* `matrix.password`: Password for Matrix user
* `matrix.server`: Server to connect to, include http(s) and port, `https://matrix.org`
* `matrix.server`: Server to connect to, include http(s), `https://matrix.org`
* `matrix.port`: Server port, default `8448`
* `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,5 +28,6 @@ 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

View File

@ -1,41 +0,0 @@
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

1
description.txt Normal file
View File

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

View File

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

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

View File

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

1
neturl

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

View File

@ -7,6 +7,10 @@ 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

View File

@ -1,21 +0,0 @@
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