First attempt

This commit is contained in:
AliasAlreadyTaken 2022-02-25 03:09:00 +01:00
parent d8ee84be25
commit df3c54c21f
3 changed files with 114 additions and 0 deletions

11
config.lua Normal file
View File

@ -0,0 +1,11 @@
-- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken.
yl_matterbridge.address = minetest.settings:get("yl_matterbridge.address") or "error"
yl_matterbridge.port = minetest.settings:get("yl_matterbridge.port") or "error"
yl_matterbridge.gateway = minetest.settings:get("yl_matterbridge.gateway") or "error"
yl_matterbridge.token = minetest.settings:get("yl_matterbridge.token") or "error"
--yl_matterbridge.save_path = "yl_matterbridge" or minetest.settings:get("yl_matterbridge.save_path") or "default"
--yl_matterbridge.admin_priv = "admin_priv" or minetest.settings:get("yl_matterbridge.admin_priv") or "server"

66
init.lua Normal file
View File

@ -0,0 +1,66 @@
-- Version 0.0.1
-- Author AliasAlreadyTaken
-- License MIT
-- Changelog
local mod_start_time = core.get_us_time()
core.log("action", "[MOD] yl_matterbridge loading")
yl_matterbridge = {}
yl_matterbridge.error = {}
yl_matterbridge.modstorage = core.get_mod_storage()
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.author = "AliasAlreadyTaken"
yl_matterbridge.information.license = "MIT"
yl_matterbridge.information.name = "yl_matterbridge"
yl_matterbridge.information.additional = "Additional information"
dofile(yl_matterbridge.modpath .. "config.lua")
--dofile(yl_matterbridge.modpath .. "internal.lua")
--dofile(yl_matterbridge.modpath .. "globalsteps.lua")
local http = minetest.request_http_api()
function yl_matterbridge.send(user_name, message_text)
local url = "http://" .. yl_matterbridge.address .. ":" .. yl_matterbridge.port .. "/api/message"
local post_headers = {"Content-Type: application/json"}
local timeout = 10
local data = {
text = message_text,
username = user_name,
gateway = yl_matterbridge.gateway
}
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
http.fetch(
{
url = url,
extra_headers = post_headers,
timeout = timeout,
post_data = minetest.write_json(data)
},
function(result)
if result.succeeded then
local data = minetest.parse_json(result.data)
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
else
minetest.log("error", "[yl_matterbridge] " .. dump(result))
--minetest.chat_send_player(user_name, "We were not able to send your text.")
return false
end
end
)
return true
end
minetest.register_on_chat_message(function(user_name, message_text)
yl_matterbridge.send(user_name, message_text)
end
)
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
core.log("action", "[MOD] yl_matterbridge loaded in [" .. mod_end_time .. "s]")

37
internal.lua Normal file
View File

@ -0,0 +1,37 @@
local http = minetest.request_http_api()
function yl_matterbridge.send(user_name, message_text)
local url = "http://" .. yl_matterbridge.address .. ":" .. yl_matterbridge.port .. "/api/message"
local post_headers = {"Content-Type: application/json"}
local timeout = 10
local data = {
text = message_text,
username = user_name,
gateway = yl_matterbridge.gateway
}
http.fetch(
{
url = url,
extra_headers = post_headers,
timeout = timeout,
post_data = minetest.write_json(data)
},
function(result)
if result.succeeded then
local data = minetest.parse_json(result.data)
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
else
minetest.log("error", "[yl_matterbridge] " .. dump(result))
minetest.chat_send_player(user_name, "We were not able to send your text.")
return false
end
end
)
return true
end
minetest.register_on_chat_message(function(name, message)
yl_matterbridge.send(user_name, message_text)
end
)