1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-03 14:53:01 +02:00

Add named discord channels.

This commit is contained in:
James Gillham 2020-10-31 17:10:44 +00:00
parent 42f82de031
commit 0281a88350

View File

@ -13,6 +13,7 @@ local remove = table.remove
local tostring = tostring
local raw_print = Print.raw_print
local next = next
local type = type
local serialize_options = {sparse = true, compact = true}
@ -37,6 +38,11 @@ local discord_embed_tag = '[DISCORD-EMBED]'
local discord_embed_raw_tag = '[DISCORD-EMBED-RAW]'
local discord_admin_embed_tag = '[DISCORD-ADMIN-EMBED]'
local discord_admin_embed_raw_tag = '[DISCORD-ADMIN-EMBED-RAW]'
local discord_named_tag = '[DISCORD-NAMED]'
local discord_named_raw_tag = '[DISCORD-NAMED-RAW]'
local discord_named_bold_tag = '[DISCORD-NAMED-BOLD]'
local discord_named_embed_tag = '[DISCORD-NAMED-EMBED]'
local discord_named_embed_raw_tag = '[DISCORD-NAMED-EMBED-RAW]'
local start_scenario_tag = '[START-SCENARIO]'
local ping_tag = '[PING]'
local data_set_tag = '[DATA-SET]'
@ -53,6 +59,20 @@ Public.raw_print = raw_print
local data_set_handlers = {}
local function assert_non_empty_string_and_no_spaces(str, argument_name)
if type(str) ~= 'string' then
error(argument_name .. ' must be a string', 3)
end
if #str == 0 then
error(argument_name .. ' must not be an empty string', 3)
end
if str:match(' ') then
error(argument_name .. " must not contain space ' ' character.", 3)
end
end
--- The event id for the on_server_started event.
-- The event is raised whenever the server goes from the starting state to the running state.
-- It provides a good opportunity to request data from the web server.
@ -100,19 +120,19 @@ function Public.to_admin_raw(message)
raw_print(discord_admin_raw_tag .. message)
end
--- Sends a embed message to the linked discord channel. The message is sanitized of markdown server side.
--- Sends an embed message to the linked discord channel. The message is sanitized of markdown server side.
-- @param message<string> the content of the embed.
function Public.to_discord_embed(message)
raw_print(discord_embed_tag .. message)
end
--- Sends a embed message to the linked discord channel. The message is not sanitized of markdown.
--- Sends an embed message to the linked discord channel. The message is not sanitized of markdown.
-- @param message<string> the content of the embed.
function Public.to_discord_embed_raw(message)
raw_print(discord_embed_raw_tag .. message)
end
--- Sends a embed message to the linked admin discord channel. The message is sanitized of markdown server side.
--- Sends an embed message to the linked admin discord channel. The message is sanitized of markdown server side.
-- @param message<string> the content of the embed.
function Public.to_admin_embed(message)
raw_print(discord_admin_embed_tag .. message)
@ -124,6 +144,41 @@ function Public.to_admin_embed_raw(message)
raw_print(discord_admin_embed_raw_tag .. message)
end
--- Sends a message to the named discord channel. The message is sanitized of markdown server side.
-- @param message<string> message to send.
function Public.to_discord_named(channel_name, message)
assert_non_empty_string_and_no_spaces(channel_name, 'channel_name')
raw_print(concat({discord_named_tag, channel_name, ' ', message}))
end
--- Sends a message to the named discord channel. The message is not sanitized of markdown.
-- @param message<string> message to send.
function Public.to_discord_named_raw(channel_name, message)
assert_non_empty_string_and_no_spaces(channel_name, 'channel_name')
raw_print(concat({discord_named_raw_tag, channel_name, ' ', message}))
end
--- Sends a message to the named discord channel. The message is sanitized of markdown server side, then made bold.
-- @param message<string> message to send.
function Public.to_discord_named_bold(channel_name, message)
assert_non_empty_string_and_no_spaces(channel_name, 'channel_name')
raw_print(concat({discord_named_bold_tag, channel_name, ' ', message}))
end
--- Sends an embed message to the named discord channel. The message is sanitized of markdown server side.
-- @param message<string> the content of the embed.
function Public.to_discord_named_embed(channel_name, message)
assert_non_empty_string_and_no_spaces(channel_name, 'channel_name')
raw_print(concat({discord_named_embed_tag, channel_name, ' ', message}))
end
--- Sends an embed message to the named discord channel. The message is not sanitized of markdown.
-- @param message<string> the content of the embed.
function Public.to_discord_named_embed_raw(channel_name, message)
assert_non_empty_string_and_no_spaces(channel_name, 'channel_name')
raw_print(concat({discord_named_embed_raw_tag, channel_name, ' ', message}))
end
--- Stops and saves the factorio server and starts the named scenario.
-- @param scenario_name<string> The name of the scenario as appears in the scenario table on http://redmew.com/admin
-- @usage