1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00

New module

This commit is contained in:
Gerkiz 2023-09-17 16:27:58 +02:00
parent 084c1e754f
commit aa6da86e70

113
utils/discord_handler.lua Normal file
View File

@ -0,0 +1,113 @@
local Discord = require 'utils.discord'
local Server = require 'utils.server'
local Public = {}
local notification = Discord.channel_names.scenario_notifications
--- Send a parsed message to the connected channel.
--- Requires at least a title and a description
---@param ... table
function Public.send_notification(...)
local data = ...
if not data.title or not data.description then
return error('Title and description is required.', 2)
end
local text = {
title = data.title,
description = data.description,
color = 'success'
}
if data.field1 and data.field1.text1 and data.field1.text2 then
text.field1 = {
text1 = data.field1.text1,
text2 = data.field1.text2,
inline = 'true'
}
end
if data.field2 and data.field2.text1 and data.field2.text2 then
text.field2 = {
text1 = data.field2.text1,
text2 = data.field2.text2,
inline = 'true',
emptyField = 'true',
emptyInline = 'true'
}
end
if data.field3 and data.field3.text1 and data.field3.text2 then
text.field3 = {
text1 = data.field3.text1,
text2 = data.field3.text2,
inline = 'true'
}
end
if data.field4 and data.field4.text1 and data.field4.text2 then
text.field4 = {
text1 = data.field4.text1,
text2 = data.field4.text2,
inline = 'true',
emptyField = 'true',
emptyInline = 'true'
}
end
if data.field5 and data.field5.text1 and data.field5.text2 then
text.field5 = {
text1 = data.field5.text1,
text2 = data.field5.text2,
inline = 'true'
}
end
if data.field6 and data.field6.text1 and data.field6.text2 then
text.field6 = {
text1 = data.field6.text1,
text2 = data.field6.text2,
inline = 'true',
emptyField = 'true',
emptyInline = 'true'
}
end
if data.field7 and data.field7.text1 and data.field7.text2 then
text.field7 = {
text1 = data.field7.text1,
text2 = data.field7.text2,
inline = 'true'
}
end
if data.field8 and data.field8.text1 and data.field8.text2 then
text.field8 = {
text1 = data.field8.text1,
text2 = data.field8.text2,
inline = 'true',
emptyField = 'true',
emptyInline = 'true'
}
end
Server.to_discord_named_parsed_embed(notification, text)
end
--- Send a message to the connected channel.
--- Requires a title and a description
---@param scenario_name string
---@param message string
function Public.send_notification_raw(scenario_name, message)
if not scenario_name then
return error('A scenario name is required.', 2)
end
if not message then
return error('A message is required.', 2)
end
local data = table.concat({'**[', scenario_name, ']**', ' - ', message})
Server.to_discord_named_embed(notification, data)
end
return Public