2023-09-27 10:57:15 +00:00
|
|
|
local http, instance, key
|
2023-10-02 16:02:53 +00:00
|
|
|
local server_name = minetest.settings:get("server_name") or ""
|
|
|
|
local automatic_delete = minetest.settings:get_bool("fediauth.automatic_delete")
|
2023-09-27 10:57:15 +00:00
|
|
|
|
|
|
|
function fediauth.send_code(code, account_handle)
|
2023-10-02 16:02:53 +00:00
|
|
|
expires_in = nil
|
|
|
|
if automatic_delete then
|
|
|
|
expires_in = 3600
|
|
|
|
end
|
|
|
|
|
2023-09-27 10:57:15 +00:00
|
|
|
local status = {
|
|
|
|
visibility = "direct",
|
2023-10-02 16:02:53 +00:00
|
|
|
status = "This is an automated message from minetest server " .. server_name ..
|
|
|
|
" If you did not request this message please ignore or block.\n\n" .. code .. "\n\n" .. account_handle,
|
|
|
|
expires_in = expires_in
|
2023-09-27 10:57:15 +00:00
|
|
|
}
|
|
|
|
local json = minetest.write_json(status)
|
|
|
|
http.fetch({
|
|
|
|
url = "https://" .. instance .. "/api/v1/statuses",
|
|
|
|
extra_headers = { "Content-Type: application/json", "Authorization: Bearer " .. key },
|
|
|
|
timeout = 15,
|
|
|
|
post_data = json
|
|
|
|
}, function(res)
|
2023-10-02 16:02:53 +00:00
|
|
|
if res.code == 200 then
|
2023-09-27 10:57:15 +00:00
|
|
|
minetest.log("action", "[fediauth] code sent to: '" .. account_handle .. "'")
|
|
|
|
else
|
|
|
|
minetest.log("error", "[fediauth] code not sent to: '" .. account_handle .. "'")
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function mastoapi_init(h, i, k)
|
|
|
|
http = h
|
|
|
|
instance = i
|
|
|
|
key = k
|
|
|
|
end
|