Bot cleanup and config

Cleaning my code up and adding stuff to config
This commit is contained in:
Cadyn
2021-02-24 16:05:49 -08:00
parent 155195e892
commit 3995353b03
6 changed files with 87 additions and 21 deletions

View File

@@ -404,9 +404,9 @@ proc/TextPreview(var/string,var/len=40)
t = replacetext(t, "\[/grid\]", "</td></tr></table>") t = replacetext(t, "\[/grid\]", "</td></tr></table>")
t = replacetext(t, "\[row\]", "</td><tr>") t = replacetext(t, "\[row\]", "</td><tr>")
t = replacetext(t, "\[cell\]", "<td>") t = replacetext(t, "\[cell\]", "<td>")
t = replacetext(t, "\[logo\]", "<img src = ntlogo.png>") t = replacetext(t, "\[logo\]", "<img src = https://raw.githubusercontent.com/CHOMPStation2/CHOMPStation2/master/html/images/ntlogo.png>") //CHOMPEdit
t = replacetext(t, "\[redlogo\]", "<img src = redntlogo.png>") t = replacetext(t, "\[redlogo\]", "<img src = https://raw.githubusercontent.com/CHOMPStation2/CHOMPStation2/master/html/images/redntlogo.png>") //CHOMPEdit
t = replacetext(t, "\[sglogo\]", "<img src = sglogo.png>") t = replacetext(t, "\[sglogo\]", "<img src = https://raw.githubusercontent.com/CHOMPStation2/CHOMPStation2/master/html/images/sglogo.png>") //CHOMPEdit
t = replacetext(t, "\[editorbr\]", "") t = replacetext(t, "\[editorbr\]", "")
return t return t

View File

@@ -9,6 +9,14 @@
var/vorefootstep_volume = 75 //In future see about making a function to adjust volume serverside in config.txt, easy to do with reenable values. - Jack var/vorefootstep_volume = 75 //In future see about making a function to adjust volume serverside in config.txt, easy to do with reenable values. - Jack
var/nodebot_enabled = 0 //So, nodebot is a supplement to the TGS discord bot pretty much. For things likes faxes and the manifest it's very helpful because it's able to render html into an image and post it.
var/nodebot_location //We need to print the manifest to this location so nodebot can render it to chat. //NOTE: TO BE REPLACED BY BETTER CODE FOR FETCHING MANIFEST
var/ahelp_channel_tag //This is for tgs4 channels, if you're not running on tgs4, this won't work anyways. If it's not set, it will default to the admin channel.
var/discord_faxes_autoprint = 0 //Only turn this on if you're not using the nodebot.
var/discord_faxes_disabled = 0 //Turn this off if you don't want the TGS bot sending you messages whenever a fax is sent to central.
var/discord_ahelps_disabled = 0 //Turn this off if you don't want the TGS bot sending you messages whenever an ahelp ticket is created.
var/discord_ahelps_all = 0 //Turn this on if you want all admin-PMs to go to be sent to discord, and not only the first message of a ticket.
/hook/startup/proc/read_ch_config() /hook/startup/proc/read_ch_config()
var/list/Lines = file2list("config/config.txt") var/list/Lines = file2list("config/config.txt")
for(var/t in Lines) for(var/t in Lines)
@@ -22,11 +30,11 @@
var/pos = findtext(t, " ") var/pos = findtext(t, " ")
var/name = null var/name = null
// var/value = null //Commenting out because config doesn't contain any values at the moment. - Jonathan var/value = null
if (pos) if (pos)
name = lowertext(copytext(t, 1, pos)) name = lowertext(copytext(t, 1, pos))
// value = copytext(t, pos + 1) //Commenting out because config doesn't contain any values at the moment. - Jonathan value = copytext(t, pos + 1)
else else
name = lowertext(t) name = lowertext(t)
@@ -40,4 +48,18 @@
config.use_jobwhitelist = 1 config.use_jobwhitelist = 1
if ("disable_emojis") if ("disable_emojis")
config.emojis = 0 config.emojis = 0
if ("nodebot_enabled")
config.nodebot_enabled = 1
if ("discord_faxes_autoprint")
config.discord_faxes_autoprint = 1
if ("discord_faxes_disabled")
config.discord_faxes_disabled = 1
if ("discord_ahelps_disabled")
config.discord_ahelps_disabled = 1
if ("discord_ahelps_all")
config.discord_ahelps_all = 1
if ("nodebot_location")
config.nodebot_location = value
if ("ahelp_channel_tag")
config.ahelp_channel_tag = value
return 1 return 1

View File

@@ -1,12 +1,25 @@
/client/var/datum/admin_help/current_ticket //the current ticket the (usually) not-admin client is dealing with /client/var/datum/admin_help/current_ticket //the current ticket the (usually) not-admin client is dealing with
//CHOMPEdit Begin
/proc/get_ahelp_channel() /proc/get_ahelp_channel()
var/datum/tgs_api/v5/api = TGS_READ_GLOBAL(tgs) var/datum/tgs_api/v5/api = TGS_READ_GLOBAL(tgs)
if(istype(api)) if(istype(api) && config.ahelp_channel_tag)
for(var/datum/tgs_chat_channel/channel in api.chat_channels) for(var/datum/tgs_chat_channel/channel in api.chat_channels)
if(channel.custom_tag == "ahelps") if(channel.custom_tag == config.ahelp_channel_tag)
return list(channel) return list(channel)
// return 0
/proc/ahelp_discord_message(var/message)
if(!message)
return
if(config.discord_ahelps_disabled)
return
var/datum/tgs_chat_channel/ahelp_channel = get_ahelp_channel()
if(ahelp_channel)
world.TgsChatBroadcast(message,ahelp_channel)
else
world.TgsTargetedChatBroadcast(message,TRUE)
//CHOMPEdit End
//TICKET MANAGER //TICKET MANAGER
// //
@@ -196,9 +209,9 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
var/list/activemins = adm["present"] var/list/activemins = adm["present"]
var activeMins = activemins.len var activeMins = activemins.len
if(is_bwoink) if(is_bwoink)
world.TgsChatBroadcast("ADMINHELP: FROM: [key_name_admin(usr)] TO [initiator_ckey]/[initiator_key_name] - MSG: **[msg]** - Heard by [activeMins] NON-AFK staff members.", get_ahelp_channel()) //CHOMPEdit ahelp_discord_message("ADMINHELP: FROM: [key_name_admin(usr)] TO [initiator_ckey]/[initiator_key_name] - MSG: **[msg]** - Heard by [activeMins] NON-AFK staff members.") //CHOMPEdit
else else
world.TgsChatBroadcast("ADMINHELP: FROM: [initiator_ckey]/[initiator_key_name] - MSG: **[msg]** - Heard by [activeMins] NON-AFK staff members.", get_ahelp_channel()) //CHOMPEdit ahelp_discord_message("ADMINHELP: FROM: [initiator_ckey]/[initiator_key_name] - MSG: **[msg]** - Heard by [activeMins] NON-AFK staff members.") //CHOMPEdit
//YW EDIT END //YW EDIT END
GLOB.ahelp_tickets.active_tickets += src GLOB.ahelp_tickets.active_tickets += src
@@ -210,7 +223,8 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
/datum/admin_help/proc/AddInteraction(formatted_message) /datum/admin_help/proc/AddInteraction(formatted_message)
var/curinteraction = "[gameTimestamp()]: [formatted_message]" var/curinteraction = "[gameTimestamp()]: [formatted_message]"
world.TgsChatBroadcast("ADMINHELP: TICKETID:[id] [strip_html_properly(curinteraction)]", get_ahelp_channel()) //CHOMPEdit if(config.discord_ahelps_all) //CHOMPEdit
ahelp_discord_message("ADMINHELP: TICKETID:[id] [strip_html_properly(curinteraction)]") //CHOMPEdit
_interactions += curinteraction _interactions += curinteraction
//private //private

View File

@@ -54,6 +54,8 @@
* Call the chat webhook to transmit a notification of an admin fax to the admin chat. * Call the chat webhook to transmit a notification of an admin fax to the admin chat.
*/ */
/obj/machinery/photocopier/faxmachine/proc/message_chat_admins(var/mob/sender, var/faxname, var/obj/item/sent, var/faxid, font_colour="#006100") /obj/machinery/photocopier/faxmachine/proc/message_chat_admins(var/mob/sender, var/faxname, var/obj/item/sent, var/faxid, font_colour="#006100")
if(config.discord_faxes_disabled) //CHOMPEdit
return
if (config.chat_webhook_url) if (config.chat_webhook_url)
spawn(0) spawn(0)
var/query_string = "type=fax" var/query_string = "type=fax"
@@ -70,12 +72,26 @@
var/obj/item/weapon/paper_bundle/B = sent var/obj/item/weapon/paper_bundle/B = sent
faxid = copytext(faxid,1,idlen-2) faxid = copytext(faxid,1,idlen-2)
var/faxids = "FAXMULTIID: [faxid]_0" var/faxids = "FAXMULTIID: [faxid]_0"
var/contents = ""
if((!config.nodebot_enabled) && config.discord_faxes_autoprint)
var/faxmsg = return_file_text("[config.fax_export_dir]/fax_[faxid]_0.html")
contents += "\nFAX: ```[strip_html_properly(faxmsg)]```"
for(var/page = 1, page <= B.pages.len, page++) for(var/page = 1, page <= B.pages.len, page++)
faxids+= "|[faxid]_[page]" var/curid = "[faxid]_[page]"
world.TgsTargetedChatBroadcast("MULTIFAX: [sanitize(faxname)] / [sanitize(sent.name)] - SENT BY: [sanitize(sender.name)] - [faxids]", TRUE) faxids+= "|[curid]"
if((!config.nodebot_enabled) && config.discord_faxes_autoprint)
var/faxmsg = return_file_text("[config.fax_export_dir]/fax_[curid].html")
contents += "\nFAX PAGE [page]: ```[strip_html_properly(faxmsg)]```"
world.TgsTargetedChatBroadcast("MULTIFAX: [sanitize(faxname)] / [sanitize(sent.name)] - SENT BY: [sanitize(sender.name)] - [faxids] [contents]", TRUE)
world.TgsTargetedChatBroadcast("FAX: [sanitize(faxname)] / [sanitize(sent.name)] - SENT BY: [sanitize(sender.name)] - FAXID: **[sanitize(faxid)]**", TRUE) else
var/contents = ""
if((!config.nodebot_enabled) && config.discord_faxes_autoprint)
var/faxmsg = return_file_text("[config.fax_export_dir]/fax_[faxid].html")
contents += "\nFAX: ```[strip_html_properly(faxmsg)]```"
world.TgsTargetedChatBroadcast("FAX: [sanitize(faxname)] / [sanitize(sent.name)] - SENT BY: [sanitize(sender.name)] - FAXID: **[sanitize(faxid)]** [contents]", TRUE)
//YW EDIT END //YW EDIT END
// //

View File

@@ -368,8 +368,8 @@
t = replacetext(t, "\[/grid\]", "</td></tr></table>") t = replacetext(t, "\[/grid\]", "</td></tr></table>")
t = replacetext(t, "\[row\]", "</td><tr>") t = replacetext(t, "\[row\]", "</td><tr>")
t = replacetext(t, "\[cell\]", "<td>") t = replacetext(t, "\[cell\]", "<td>")
t = replacetext(t, "\[logo\]", "<img src = ntlogo.png>") t = replacetext(t, "\[logo\]", "<img src = https://raw.githubusercontent.com/CHOMPStation2/CHOMPStation2/master/html/images/ntlogo.png>") //CHOMPEdit
t = replacetext(t, "\[sglogo\]", "<img src = sglogo.png>") t = replacetext(t, "\[sglogo\]", "<img src = https://raw.githubusercontent.com/CHOMPStation2/CHOMPStation2/master/html/images/sglogo.png>") //CHOMPEdit
t = "<font face=\"[deffont]\" color=[P ? P.colour : "black"]>[t]</font>" t = "<font face=\"[deffont]\" color=[P ? P.colour : "black"]>[t]</font>"
else // If it is a crayon, and he still tries to use these, make them empty! else // If it is a crayon, and he still tries to use these, make them empty!

View File

@@ -34,11 +34,25 @@
html = data_core.get_manifest(FALSE,TRUE,snowflake = TRUE) html = data_core.get_manifest(FALSE,TRUE,snowflake = TRUE)
else else
html = "<b>ERROR: NO DATACORE</b>" //Could make the error more fancy later html = "<b>ERROR: NO DATACORE</b>" //Could make the error more fancy later
rustg_file_write(html,"C:\\nodebot\\html.html") rustg_file_write(html,"[config.nodebot_location]\\html.html")
/datum/tgs_chat_command/manifest/Run(datum/tgs_chat_user/sender, params) /datum/tgs_chat_command/manifest/Run(datum/tgs_chat_user/sender, params)
if(config.nodebot_enabled)
ManifestToHtml() ManifestToHtml()
return "!!ManifestCompiled" return "!!ManifestCompiled"
else
var/outp = "Crew Manifest:"
var/list/total = list()
if(data_core)
data_core.get_manifest_list()
for(var/list/item in PDA_Manifest)
outp += "\n__**[item["cat"]]:**__"
for(var/list/person in item["elems"])
total |= person
outp += "\n[person["name"]] -:- [person["rank"]]"
return "**Total crew members:** [total.len]\n" + outp
/datum/tgs_chat_command/discordping /datum/tgs_chat_command/discordping
name = "discordping" name = "discordping"