diff --git a/config.lua b/config.lua index 1c248e508ddef226d0e31c0a573c5029a3224980..021a14aaf56a853c689599fe1a61a18c65bb368a 100644 --- a/config.lua +++ b/config.lua @@ -29,5 +29,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", "channel", nil, true) -- Channel to join (not needed?) +setting("string", "room_id", nil, true) -- Channel to join (not needed?) setting("string", "password", nil, true) -- Server password diff --git a/init.lua b/init.lua index 20d45726a20ea186024990b3415932b7922554c8..8a0195803aada62459c9934747342edb54d72f34 100644 --- a/init.lua +++ b/init.lua @@ -32,14 +32,14 @@ end local client = require("matrix").client("https://"..matrix.config.server..":"..matrix.config.port) -client:login_with_password(matrix.config.user, matrix.config.password, true) - -local running, start_ts = true, os.time() * 1000 +local start_ts = os.time() * 1000 client:hook("invite", function (client, room) - -- When invited to a room, join it - eprintf("Invited to room %s\n", room) - client:join_room(room) + -- When invited to a room, join it + eprintf("Invited to room %s\n", room) + if room.room_id == matrix.config.room_id then + client:join_room(room) + end end):hook("logged-in", function (client) matrix.connected = true eprintf("Logged in successfully\n") @@ -59,7 +59,7 @@ end):hook("joined", function (client, room) eprintf(" - %s\n", room) end - room:send_text("Type “!bot quit” to make the bot exit") + --room:send_text("Type “!bot quit” to make the bot exit") room:hook("message", function (room, sender, message, event) if event.origin_server_ts < start_ts then @@ -83,7 +83,7 @@ end):hook("joined", function (client, room) end client:logout() matrix.connected = false - else + elseif room.room_id == matrix.config.room_id then minetest.chat_send_all("<"..sender.."> "..message.body) end end) diff --git a/settingtypes.txt b/settingtypes.txt index 7bc98f5aa0c1a682b906a5658303a31ffcda4abb..44a87226d033c64898f9e313906db974e0cbd2ed 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -13,7 +13,7 @@ matrix.server (Matrix server) string https://matrix.org matrix.port (Server port) int 8448 # Channel the bot joins after connecting. -matrix.channel (Channel to join) string #minetest +matrix.room_id (Channel to join) string # Matrix user password. matrix.password (Server password) string