forked from AliasAlreadyTaken/yl_matterbridge
settingtypes and api disable register_on_chat_message
This commit is contained in:
parent
dda80031da
commit
adff5e2f7c
49
init.lua
49
init.lua
@ -1,9 +1,12 @@
|
||||
-- Version 0.0.1
|
||||
-- Version 0.0.2
|
||||
-- Author AliasAlreadyTaken
|
||||
-- License MIT
|
||||
|
||||
-- Changelog
|
||||
|
||||
-- 0.0.1 First puny attempts
|
||||
-- 0.0.2 feature complete including settings
|
||||
|
||||
local mod_start_time = core.get_us_time()
|
||||
core.log("action", "[MOD] yl_matterbridge loading")
|
||||
|
||||
@ -14,18 +17,18 @@ yl_matterbridge.modpath = core.get_modpath("yl_matterbridge") .. DIR_DELIM
|
||||
yl_matterbridge.worldpath = core.get_worldpath() .. DIR_DELIM
|
||||
|
||||
yl_matterbridge.information = {}
|
||||
yl_matterbridge.information.version = "0.0.1"
|
||||
yl_matterbridge.information.version = "0.0.2"
|
||||
yl_matterbridge.information.author = "AliasAlreadyTaken"
|
||||
yl_matterbridge.information.license = "MIT"
|
||||
yl_matterbridge.information.name = "yl_matterbridge"
|
||||
yl_matterbridge.information.additional = "Additional information"
|
||||
yl_matterbridge.information.additional = "Sends and receives ingame chat to and from matterbridge https://github.com/42wim/matterbridge"
|
||||
|
||||
local address = minetest.settings:get("yl_matterbridge.address") or false
|
||||
local port = minetest.settings:get("yl_matterbridge.port") or false
|
||||
local gateway = minetest.settings:get("yl_matterbridge.gateway") or false
|
||||
local token = minetest.settings:get("yl_matterbridge.token") or ""
|
||||
local address = core.settings:get("yl_matterbridge.address") or "127.0.0.1"
|
||||
local port = core.settings:get("yl_matterbridge.port") or "4242"
|
||||
local gateway = core.settings:get("yl_matterbridge.gateway") or "default"
|
||||
local token = core.settings:get("yl_matterbridge.token") or ""
|
||||
|
||||
local http = minetest.request_http_api()
|
||||
local http = core.request_http_api()
|
||||
|
||||
function send(user_name, message_text)
|
||||
local url = "http://" .. address .. ":" .. port .. "/api/message"
|
||||
@ -42,14 +45,14 @@ function send(user_name, message_text)
|
||||
url = url,
|
||||
extra_headers = post_headers,
|
||||
timeout = timeout,
|
||||
post_data = minetest.write_json(data)
|
||||
post_data = core.write_json(data)
|
||||
},
|
||||
function(result)
|
||||
if result.succeeded then
|
||||
local data = minetest.parse_json(result.data)
|
||||
local data = core.parse_json(result.data)
|
||||
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
|
||||
else
|
||||
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
||||
core.log("error", "[yl_matterbridge] " .. dump(result))
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -68,14 +71,14 @@ local function receive()
|
||||
},
|
||||
function(result)
|
||||
if result.succeeded then
|
||||
local data = minetest.parse_json(result.data)
|
||||
for _,v in ipairs(data) do
|
||||
local data = core.parse_json(result.data)
|
||||
for _, v in ipairs(data) do
|
||||
if v.username and v.text then
|
||||
yl_matterbridge.publish_to_chat(v.username, v.text)
|
||||
end
|
||||
end
|
||||
else
|
||||
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
||||
core.log("error", "[yl_matterbridge] " .. dump(result))
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -86,21 +89,25 @@ end
|
||||
-- Overwrite these function in your chat mod, if you want to govern sending and receveiving yourself
|
||||
-- Don't forget to add an optional dependency to yl_matterbridge
|
||||
|
||||
function yl_matterbridge.publish_to_chat(user_name,message_text)
|
||||
core.chat_send_all("<"..user_name.."@irc> "..message_text)
|
||||
function yl_matterbridge.publish_to_chat(user_name, message_text)
|
||||
core.chat_send_all("<" .. user_name .. "@irc> " .. message_text)
|
||||
end
|
||||
|
||||
function yl_matterbridge.send_to_bridge(user_name,message_text)
|
||||
function yl_matterbridge.send_to_bridge(user_name, message_text)
|
||||
send(user_name, message_text)
|
||||
end
|
||||
|
||||
-- Set this function to yl_matterbridge.chat_message = function() end if you call yl_matterbridge.send_to_bridge yourself
|
||||
|
||||
function yl_matterbridge.chat_message(user_name, message_text)
|
||||
send_to_bridge(user_name, message_text)
|
||||
end
|
||||
|
||||
-- connect to Minetest
|
||||
|
||||
minetest.register_on_chat_message(
|
||||
yl_matterbridge.send_to_bridge
|
||||
)
|
||||
core.register_on_chat_message(yl_matterbridge.chat_message)
|
||||
|
||||
minetest.register_globalstep(receive)
|
||||
core.register_globalstep(receive)
|
||||
|
||||
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
|
||||
core.log("action", "[MOD] yl_matterbridge loaded in [" .. mod_end_time .. "s]")
|
||||
|
24
settingtypes.txt
Normal file
24
settingtypes.txt
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
### This file allows you to configure your yl_matterbridge connection
|
||||
|
||||
[yl_matterbridge]
|
||||
|
||||
# The address or IP to the matterbridge server
|
||||
# If you run the bridge on the same machine where you run your MT, you can use the default
|
||||
# Defaults to 127.0.0.1
|
||||
yl_matterbridge.address (Bridge IP address or URL) string "127.0.0.1"
|
||||
|
||||
# The port the matterbridge server listens to
|
||||
# You need to set this to the port of the API connection, which you configured in the toml
|
||||
# Defaults to 4242
|
||||
yl_matterbridge.port (Bridge port) string "4242"
|
||||
|
||||
# The name of the gateway of the matterbridge server
|
||||
# You need to set this to the gatewayname, which you configured in the toml
|
||||
# Defaults to "default"
|
||||
yl_matterbridge.gateway (Bridge gateway) string "default"
|
||||
|
||||
# The token the matterbridge server
|
||||
# If you don't configure this, every wellformed message to the right port will be relayed
|
||||
# Optional
|
||||
yl_matterbridge.token (Bridge token) string ""
|
Loading…
Reference in New Issue
Block a user