From f2c73b43ebcd3a8a5d05a1c72bbcf22aaac28749 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Fri, 20 May 2022 15:36:22 -0400 Subject: [PATCH] Bot refresh - Light cleanup of bot code, allows the bot to ping a role when rebooting (#4085) --- code/__HELPERS/chat.dm | 61 +++++++++++++++++++ code/__HELPERS/unsorted.dm | 2 +- code/controllers/configuration/entries/bot.dm | 3 + code/controllers/subsystem/ticker.dm | 6 +- config/entries/bot.txt | 11 ++++ vorestation.dme | 2 + 6 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 code/__HELPERS/chat.dm create mode 100644 code/controllers/configuration/entries/bot.dm create mode 100644 config/entries/bot.txt diff --git a/code/__HELPERS/chat.dm b/code/__HELPERS/chat.dm new file mode 100644 index 00000000000..def684c5099 --- /dev/null +++ b/code/__HELPERS/chat.dm @@ -0,0 +1,61 @@ +/* + +Here's how to use the chat system with configs + +send2adminchat is a simple function that broadcasts to admin channels + +send2chat is a bit verbose but can be very specific + +The second parameter is a string, this string should be read from a config. +What this does is dictacte which TGS4 channels can be sent to. + +For example if you have the following channels in tgs4 set up +- Channel 1, Tag: asdf +- Channel 2, Tag: bombay,asdf +- Channel 3, Tag: Hello my name is asdf +- Channel 4, No Tag +- Channel 5, Tag: butts + +and you make the call: + +send2chat("I sniff butts", CONFIG_GET(string/where_to_send_sniff_butts)) + +and the config option is set like: + +WHERE_TO_SEND_SNIFF_BUTTS asdf + +It will be sent to channels 1 and 2 + +Alternatively if you set the config option to just: + +WHERE_TO_SEND_SNIFF_BUTTS + +it will be sent to all connected chats. + +In TGS3 it will always be sent to all connected designated game chats. +*/ + +/** + * Sends a message to TGS chat channels. + * + * message - The message to send. + * channel_tag - Required. If "", the message with be sent to all connected (Game-type for TGS3) channels. Otherwise, it will be sent to TGS4 channels with that tag (Delimited by ','s). + */ +/proc/send2chat(message, channel_tag) + if(channel_tag == null || !world.TgsAvailable()) + return + + var/datum/tgs_version/version = world.TgsVersion() + if(channel_tag == "" || version.suite == 3) + world.TgsTargetedChatBroadcast(message, FALSE) + return + + var/list/channels_to_use = list() + for(var/I in world.TgsChatChannelInfo()) + var/datum/tgs_chat_channel/channel = I + var/list/applicable_tags = splittext(channel.custom_tag, ",") + if(channel_tag in applicable_tags) + channels_to_use += channel + + if(channels_to_use.len) + world.TgsChatBroadcast(message, channels_to_use) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 2269633a3ab..2ea98b83c3e 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1560,7 +1560,7 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new) //Sender is optional /proc/admin_chat_message(var/message = "Debug Message", var/color = "#FFFFFF", var/sender) if(message) //Adds TGS3 integration to those fancy verbose round event messages - world.TgsTargetedChatBroadcast(message, TRUE) + send2irc("Event", message) if (!config_legacy.chat_webhook_url || !message) return spawn(0) diff --git a/code/controllers/configuration/entries/bot.dm b/code/controllers/configuration/entries/bot.dm new file mode 100644 index 00000000000..dabdfecef25 --- /dev/null +++ b/code/controllers/configuration/entries/bot.dm @@ -0,0 +1,3 @@ +/datum/config_entry/string/chat_reboot_role + +/datum/config_entry/string/chat_roundend_notice_tag diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index 3402867febf..c482654c6ff 100644 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -462,7 +462,11 @@ SUBSYSTEM_DEF(ticker) blackbox.save_all_data_to_sql() send2irc("Server", "A round of [mode.name] just ended.") - world.TgsTargetedChatBroadcast("The round has ended.", FALSE) + if(CONFIG_GET(string/chat_roundend_notice_tag)) + var/broadcastmessage = "The round has ended." + if(CONFIG_GET(string/chat_reboot_role)) + broadcastmessage += "\n\n<@&[CONFIG_GET(string/chat_reboot_role)]>, the server will reboot shortly!" + send2chat(broadcastmessage, CONFIG_GET(string/chat_roundend_notice_tag)) SSpersistence.SavePersistence() ready_for_reboot = TRUE diff --git a/config/entries/bot.txt b/config/entries/bot.txt new file mode 100644 index 00000000000..11e3f745e80 --- /dev/null +++ b/config/entries/bot.txt @@ -0,0 +1,11 @@ +## Chat Announce Options +## Various messages to be sent to game chats +## Uncommenting these will enable them, by default they will be broadcast to Game chat channels on TGS3 or non-admin channels on TGS4 +## If using TGS4, the string option can be set as a chat channel tag to limit the message to channels of that tag type (case-sensitive) +## i.e. CHAT_ANNOUNCE_NEW_GAME chat_channel_tag + +## Announcements for when the round ends, pending server reboot. +#CHAT_ROUNDEND_NOTICE_TAG + +## Role ID that, when present, will be pinged every round end. +#CHAT_REBOOT_ROLE diff --git a/vorestation.dme b/vorestation.dme index a222a49ec5b..3ed7e834d0a 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -185,6 +185,7 @@ #include "code\__HELPERS\_logging.dm" #include "code\__HELPERS\areas.dm" #include "code\__HELPERS\atom_movables.dm" +#include "code\__HELPERS\chat.dm" #include "code\__HELPERS\events.dm" #include "code\__HELPERS\files.dm" #include "code\__HELPERS\filters.dm" @@ -314,6 +315,7 @@ #include "code\controllers\verbs.dm" #include "code\controllers\configuration\config_entry.dm" #include "code\controllers\configuration\configuration.dm" +#include "code\controllers\configuration\entries\bot.dm" #include "code\controllers\configuration\entries\comms.dm" #include "code\controllers\configuration\entries\dbconfig.dm" #include "code\controllers\configuration\entries\fail2topic.dm"