Compare commits
10 Commits
6679cbffe2
...
6fb0a6f726
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fb0a6f726 | |||
|
|
17c1ae786d | ||
|
|
cd2c6c949c | ||
|
|
0b0535dff5 | ||
|
|
e93f6b436a | ||
|
|
d316776ed0 | ||
|
|
c3c6731d8b | ||
|
|
b601d5cc64 | ||
|
|
b54f0df57b | ||
|
|
fab8a5a729 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
||||
29
README.md
29
README.md
@ -1,10 +1,22 @@
|
||||
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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
41
debug.lua
Normal 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
|
||||
@ -1 +0,0 @@
|
||||
This mod creates a bridge between a Matrix channel and the in-game chat!
|
||||
29
init.lua
29
init.lua
@ -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
|
||||
3
mod.conf
3
mod.conf
@ -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
1
neturl
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit e69ad0d005d7d70ff445d823ff69f1b41b6157ea
|
||||
@ -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
21
validate_server.lua
Normal 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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user