1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-11-23 22:22:34 +02:00
Files
ComfyFactorio/utils/discord_handler.lua

72 lines
2.0 KiB
Lua
Raw Normal View History

2023-09-17 16:27:58 +02:00
local Discord = require 'utils.discord'
local Server = require 'utils.server'
local Public = {}
local notification = Discord.channel_names.scenario_notifications
2025-09-16 23:13:48 +02:00
--- Send a parsed message to the named discord channel.
2023-09-17 16:27:58 +02:00
--- Requires at least a title and a description
2025-09-08 23:39:31 +02:00
---@param data table
function Public.send_notification(data)
if not data or not data.title or not data.description then
return error("Title and description is required.", 2)
2023-09-17 16:27:58 +02:00
end
2025-09-08 23:39:31 +02:00
if game.tick < 10 then return end
2023-09-17 16:27:58 +02:00
2025-09-08 23:39:31 +02:00
data.tick = game.tick
2024-01-09 21:57:10 +01:00
Server.to_discord_named_parsed_embed(notification, data)
end
2025-09-16 23:13:48 +02:00
--- Send a parsed message to the connected channel.
--- Requires at least a title and a description
---@param data table
function Public.send_notification_connected_channel(data)
if not data or not data.title or not data.description then
return error("Title and description is required.", 2)
end
if game.tick < 10 then return end
data.tick = game.tick
Server.to_discord_embed_parsed(data)
end
2023-09-17 16:27:58 +02:00
--- Send a message to the connected channel.
--- Requires a title and a description
2024-05-27 20:30:03 +02:00
---@param scenario_name string|nil
2023-09-17 16:27:58 +02:00
---@param message string
function Public.send_notification_raw(scenario_name, message)
if not scenario_name then
2024-03-28 23:37:14 +01:00
scenario_name = Server.get_server_name() or 'CommandHandler'
2023-09-17 16:27:58 +02:00
end
if not message then
return error('A message is required.', 2)
end
2025-09-08 23:39:31 +02:00
local data = table.concat({ '**[', scenario_name, ']**', ' - ', message })
2023-09-17 16:27:58 +02:00
Server.to_discord_named_embed(notification, data)
end
2023-12-03 00:21:37 +01:00
function Public.send_notification_debug(player, source_debug, debug_data)
local name = player and player.valid and player.name or 'script'
2025-09-08 23:39:31 +02:00
local data =
{
2023-12-03 00:21:37 +01:00
title = Server.get_server_name(),
description = source_debug,
2025-09-08 23:39:31 +02:00
fields =
{
{
title = 'Debug data for: ' .. name,
description = debug_data
}
2023-12-03 00:21:37 +01:00
}
}
Public.send_notification(data)
end
2023-09-17 16:27:58 +02:00
return Public