settingtypes and api disable register_on_chat_message
parent
dda80031da
commit
adff5e2f7c
49
init.lua
49
init.lua
|
@ -1,9 +1,12 @@
|
||||||
-- Version 0.0.1
|
-- Version 0.0.2
|
||||||
-- Author AliasAlreadyTaken
|
-- Author AliasAlreadyTaken
|
||||||
-- License MIT
|
-- License MIT
|
||||||
|
|
||||||
-- Changelog
|
-- Changelog
|
||||||
|
|
||||||
|
-- 0.0.1 First puny attempts
|
||||||
|
-- 0.0.2 feature complete including settings
|
||||||
|
|
||||||
local mod_start_time = core.get_us_time()
|
local mod_start_time = core.get_us_time()
|
||||||
core.log("action", "[MOD] yl_matterbridge loading")
|
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.worldpath = core.get_worldpath() .. DIR_DELIM
|
||||||
|
|
||||||
yl_matterbridge.information = {}
|
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.author = "AliasAlreadyTaken"
|
||||||
yl_matterbridge.information.license = "MIT"
|
yl_matterbridge.information.license = "MIT"
|
||||||
yl_matterbridge.information.name = "yl_matterbridge"
|
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 address = core.settings:get("yl_matterbridge.address") or "127.0.0.1"
|
||||||
local port = minetest.settings:get("yl_matterbridge.port") or false
|
local port = core.settings:get("yl_matterbridge.port") or "4242"
|
||||||
local gateway = minetest.settings:get("yl_matterbridge.gateway") or false
|
local gateway = core.settings:get("yl_matterbridge.gateway") or "default"
|
||||||
local token = minetest.settings:get("yl_matterbridge.token") or ""
|
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)
|
function send(user_name, message_text)
|
||||||
local url = "http://" .. address .. ":" .. port .. "/api/message"
|
local url = "http://" .. address .. ":" .. port .. "/api/message"
|
||||||
|
@ -42,14 +45,14 @@ function send(user_name, message_text)
|
||||||
url = url,
|
url = url,
|
||||||
extra_headers = post_headers,
|
extra_headers = post_headers,
|
||||||
timeout = timeout,
|
timeout = timeout,
|
||||||
post_data = minetest.write_json(data)
|
post_data = core.write_json(data)
|
||||||
},
|
},
|
||||||
function(result)
|
function(result)
|
||||||
if result.succeeded then
|
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))
|
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
|
||||||
else
|
else
|
||||||
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
core.log("error", "[yl_matterbridge] " .. dump(result))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -68,14 +71,14 @@ local function receive()
|
||||||
},
|
},
|
||||||
function(result)
|
function(result)
|
||||||
if result.succeeded then
|
if result.succeeded then
|
||||||
local data = minetest.parse_json(result.data)
|
local data = core.parse_json(result.data)
|
||||||
for _,v in ipairs(data) do
|
for _, v in ipairs(data) do
|
||||||
if v.username and v.text then
|
if v.username and v.text then
|
||||||
yl_matterbridge.publish_to_chat(v.username, v.text)
|
yl_matterbridge.publish_to_chat(v.username, v.text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
core.log("error", "[yl_matterbridge] " .. dump(result))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -86,21 +89,25 @@ end
|
||||||
-- Overwrite these function in your chat mod, if you want to govern sending and receveiving yourself
|
-- 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
|
-- Don't forget to add an optional dependency to yl_matterbridge
|
||||||
|
|
||||||
function yl_matterbridge.publish_to_chat(user_name,message_text)
|
function yl_matterbridge.publish_to_chat(user_name, message_text)
|
||||||
core.chat_send_all("<"..user_name.."@irc> "..message_text)
|
core.chat_send_all("<" .. user_name .. "@irc> " .. message_text)
|
||||||
end
|
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)
|
send(user_name, message_text)
|
||||||
end
|
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
|
-- connect to Minetest
|
||||||
|
|
||||||
minetest.register_on_chat_message(
|
core.register_on_chat_message(yl_matterbridge.chat_message)
|
||||||
yl_matterbridge.send_to_bridge
|
|
||||||
)
|
|
||||||
|
|
||||||
minetest.register_globalstep(receive)
|
core.register_globalstep(receive)
|
||||||
|
|
||||||
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
|
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
|
||||||
core.log("action", "[MOD] yl_matterbridge loaded in [" .. mod_end_time .. "s]")
|
core.log("action", "[MOD] yl_matterbridge loaded in [" .. mod_end_time .. "s]")
|
||||||
|
|
|
@ -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