mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-30 23:17:53 +02:00
added ping role support
allows a given role to be pinged by the webpanel
This commit is contained in:
parent
959018aca2
commit
5cddfdbc59
@ -4,6 +4,7 @@ local Functions = require 'maps.mountain_fortress_v3.functions'
|
||||
local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies'
|
||||
|
||||
local HS = require 'maps.mountain_fortress_v3.highscore'
|
||||
local Discord = require 'utils.discord'
|
||||
local IC = require 'maps.mountain_fortress_v3.ic.table'
|
||||
local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap'
|
||||
local Autostash = require 'modules.autostash'
|
||||
@ -52,6 +53,16 @@ require 'modules.spawners_contain_biters'
|
||||
require 'modules.wave_defense.main'
|
||||
require 'modules.charging_station'
|
||||
|
||||
-- Use these settings for live
|
||||
-- local send_ping_to_channel = Discord.channel_names.announcements
|
||||
-- local role_to_mention = Discord.role_mentions.mtn_fortress
|
||||
-- Use these settings for testing
|
||||
-- bot-lounge
|
||||
-- local send_ping_to_channel = Discord.channel_names.bot_quarters
|
||||
-- dev
|
||||
local send_ping_to_channel = Discord.channel_names.dev
|
||||
local role_to_mention = Discord.role_mentions.test_role
|
||||
|
||||
local Public = {}
|
||||
local raise_event = script.raise_event
|
||||
local floor = math.floor
|
||||
@ -254,6 +265,8 @@ function Public.reset_map()
|
||||
this.force_chunk = true
|
||||
this.market_announce = game.tick + 1200
|
||||
this.game_lost = false
|
||||
|
||||
Server.to_discord_named_raw(send_ping_to_channel, role_to_mention .. ' ** Mtn Fortress was just reset! **')
|
||||
end
|
||||
|
||||
local is_locomotive_valid = function()
|
||||
|
24
utils/discord.lua
Normal file
24
utils/discord.lua
Normal file
@ -0,0 +1,24 @@
|
||||
--- Resources for use in interacting with discord.
|
||||
return {
|
||||
--- The names of the discord channels that can be referenced by name.
|
||||
-- See features.server.to_discord_named
|
||||
channel_names = {
|
||||
bot_quarters = 'bot-quarters',
|
||||
announcements = 'announcements',
|
||||
mod_lounge = 'mods-lounge',
|
||||
dev = 'dev',
|
||||
helpdesk = 'helpdesk'
|
||||
},
|
||||
--- The strings that mention the discord role.
|
||||
-- Has to be used with features.server.to_discord_raw variants else the mention is sanitized server side.
|
||||
role_mentions = {
|
||||
test_role = '<@&821767672642797649>',
|
||||
mtn_fortress = '<@&821485320133410846>',
|
||||
fish_defender = '<@&821485656576360538>',
|
||||
biter_battles = '<@&821486037401600000>',
|
||||
chronosphere = '<@&821485811430064179>',
|
||||
modded = '<@&520169053055221770>',
|
||||
map_updates = '<@&821509848746295336>',
|
||||
mods = '<@&497677008705290251>'
|
||||
}
|
||||
}
|
@ -50,6 +50,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 stop_scenario_tag = '[STOP-SCENARIO]'
|
||||
local ping_tag = '[PING]'
|
||||
@ -67,6 +72,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.
|
||||
@ -117,6 +136,41 @@ function Public.to_discord_bold(message, locale)
|
||||
end
|
||||
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
|
||||
|
||||
--- Sends a message to the linked admin discord channel. The message is sanitized of markdown server side.
|
||||
-- @param message<string> message to send.
|
||||
-- @param locale<boolean> if the message should be handled as localized.
|
||||
|
Loading…
Reference in New Issue
Block a user