Skip to content

Commit

Permalink
updates and enhances chat commands
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSuckerberg committed Dec 1, 2023
1 parent d17a466 commit 88b91d1
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 40 deletions.
127 changes: 106 additions & 21 deletions code/modules/admin/chat_commands.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
break
if(!active_admins)
SSticker.Reboot("Restart requested from the discord.", "discord")
return "Rebooting..."
return new /datum/tgs_message_content("Rebooting...")
else
return "There are active admins on the server! Ask them to restart."
return new /datum/tgs_message_content("There are active admins on the server! Ask them to restart.")

/datum/tgs_chat_command/join
name = "join"
help_text = "Sends a join link."

/datum/tgs_chat_command/join/Run(datum/tgs_chat_user/sender, params)
return "<[world.internet_address]:[world.port]>"
var/datum/tgs_chat_embed/structure/embed = new()
embed.title = "Join Server"
embed.url = "byond://[world.internet_address]:[world.port]"
return new /datum/tgs_message_content()

/datum/tgs_chat_command/tgsstatus
name = "status"
Expand All @@ -32,12 +35,26 @@
/datum/tgs_chat_command/tgsstatus/Run(datum/tgs_chat_user/sender, params)
var/rtod = REALTIMEOFDAY
if(rtod - last_tgs_status < TGS_STATUS_THROTTLE)
return
return new /datum/tgs_message_content("Please wait a few seconds before using this command again.")
last_tgs_status = rtod
var/list/adm = get_admin_counts()
var/list/allmins = adm["total"]
var/status = "Admins: [allmins.len] (Active: [english_list(adm["present"])] AFK: [english_list(adm["afk"])] Stealth: [english_list(adm["stealth"])] Skipped: [english_list(adm["noflags"])]). "
status += "Players: [GLOB.clients.len] (Active: [get_active_player_count(0,1,0)]). Mode: [SSticker.mode ? SSticker.mode.name : "Not started"]."

var/datum/tgs_chat_embed/structure/embed = new()
embed.title = "Server Status"
embed.url = "byond://[world.internet_address]:[world.port]"
embed.fields += new /datum/tgs_chat_embed/field("Round", "[GLOB.round_id ? "Round #[GLOB.round_id]" : "Not started"]")
embed.fields += new /datum/tgs_chat_embed/field("Admins", "(Active: [english_list(adm["present"])] AFK: [english_list(adm["afk"])] Stealth: [english_list(adm["stealth"])] Skipped: [english_list(adm["noflags"])])")
embed.fields += new /datum/tgs_chat_embed/field("Players", "(Active: [get_active_player_count(0,1,0)])")
embed.fields += new /datum/tgs_chat_embed/field("Mode", "[SSticker.mode ? SSticker.mode.name : "Not started"]")
embed.fields += new /datum/tgs_chat_embed/field("Round Time", ROUND_TIME)
embed.fields += new /datum/tgs_chat_embed/field("Time Dilation", "[SStime_track.time_dilation_current]% ([SStime_track.time_dilation_avg]% avg)")

for(var/datum/tgs_chat_embed/field/f as anything in embed.fields)
f.is_inline = TRUE

var/datum/tgs_message_content/status = new()
status.embed = embed

return status

/datum/tgs_chat_command/tgscheck
Expand All @@ -48,10 +65,22 @@
/datum/tgs_chat_command/tgscheck/Run(datum/tgs_chat_user/sender, params)
var/rtod = REALTIMEOFDAY
if(rtod - last_tgs_check < TGS_STATUS_THROTTLE)
return
return new /datum/tgs_message_content("Please wait a few seconds before using this command again.")
last_tgs_check = rtod
var/server = CONFIG_GET(string/server)
return "[GLOB.round_id ? "Round #[GLOB.round_id]: " : ""][GLOB.clients.len] players, Mode: [GLOB.master_mode]; Round [SSticker.HasRoundStarted() ? (SSticker.IsRoundInProgress() ? "Active" : "Finishing") : "Starting"] -- [server ? server : "[world.internet_address]:[world.port]"]"

var/datum/tgs_chat_embed/structure/embed = new()
embed.title = "Server Status"
embed.url = "byond://[world.internet_address]:[world.port]"
embed.fields += new /datum/tgs_chat_embed/field("Round", "[GLOB.round_id ? "Round #[GLOB.round_id]" : "Not started"]")
embed.fields += new /datum/tgs_chat_embed/field("Players", length(GLOB.player_list))
embed.fields += new /datum/tgs_chat_embed/field("Admins", length(GLOB.admins))
embed.fields += new /datum/tgs_chat_embed/field("Round Time", ROUND_TIME)
embed.fields += new /datum/tgs_chat_embed/field("Time Dilation", "[SStime_track.time_dilation_current]% ([SStime_track.time_dilation_avg]% avg)")

var/datum/tgs_message_content/status = new()
status.embed = embed

return status

/datum/tgs_chat_command/ahelp
name = "ahelp"
Expand All @@ -61,7 +90,7 @@
/datum/tgs_chat_command/ahelp/Run(datum/tgs_chat_user/sender, params)
var/list/all_params = splittext(params, " ")
if(all_params.len < 2)
return "Insufficient parameters"
return new /datum/tgs_message_content("Insufficient parameters")
var/target = all_params[1]
all_params.Cut(1, 2)
var/id = text2num(target)
Expand All @@ -70,10 +99,10 @@
if(AH)
target = AH.initiator_ckey
else
return "Ticket #[id] not found!"
return new /datum/tgs_message_content("Ticket #[id] not found.")
var/res = TgsPm(target, all_params.Join(" "), sender.friendly_name)
if(res != "Message Successful")
return res
return new /datum/tgs_message_content(res)

/datum/tgs_chat_command/namecheck
name = "namecheck"
Expand All @@ -83,18 +112,25 @@
/datum/tgs_chat_command/namecheck/Run(datum/tgs_chat_user/sender, params)
params = trim(params)
if(!params)
return "Insufficient parameters"
return new /datum/tgs_message_content("Please specify a target.")
log_admin("Chat Name Check: [sender.friendly_name] on [params]")
message_admins("Name checking [params] from [sender.friendly_name]")
return keywords_lookup(params, 1)
return new /datum/tgs_message_content(keywords_lookup(params, 1))

/datum/tgs_chat_command/adminwho
name = "adminwho"
help_text = "Lists administrators currently on the server"
admin_only = TRUE

/datum/tgs_chat_command/adminwho/Run(datum/tgs_chat_user/sender, params)
return tgsadminwho()
var/datum/tgs_chat_embed/structure/embed = new()
embed.title = "Admins"
embed.description = tgsadminwho()

var/datum/tgs_message_content/adminwho = new()
adminwho.embed = embed

return adminwho

GLOBAL_LIST(round_end_notifiees)

Expand All @@ -107,7 +143,7 @@ GLOBAL_LIST(round_end_notifiees)
if(!SSticker.IsRoundInProgress() && SSticker.HasRoundStarted())
return "[sender.mention], the round has already ended!"
LAZYSET(GLOB.round_end_notifiees, sender.mention, TRUE)
return "I will notify [sender.mention] when the round ends."
return new /datum/tgs_message_content( "I will notify [sender.mention] when the round ends.")

/datum/tgs_chat_command/sdql
name = "sdql"
Expand All @@ -116,15 +152,24 @@ GLOBAL_LIST(round_end_notifiees)

/datum/tgs_chat_command/sdql/Run(datum/tgs_chat_user/sender, params)
if(GLOB.AdminProcCaller)
return "Unable to run query, another admin proc call is in progress. Try again later."
return new /datum/tgs_message_content("Unable to run query, another admin proc call is in progress. Try again later.")
GLOB.AdminProcCaller = "CHAT_[sender.friendly_name]" //_ won't show up in ckeys so it'll never match with a real admin
var/list/results = world.SDQL2_query(params, GLOB.AdminProcCaller, GLOB.AdminProcCaller)
GLOB.AdminProcCaller = null
if(!results)
return "Query produced no output"
return new /datum/tgs_message_content("Query produced no output.")
var/list/text_res = results.Copy(1, 3)
var/list/refs = results.len > 3 ? results.Copy(4) : null
. = "[text_res.Join("\n")][refs ? "\nRefs: [refs.Join(" ")]" : ""]"

var/datum/tgs_chat_embed/structure/embed = new()
embed.title = "SDQL Query Results"
embed.description = text_res.Join("\n")
embed.fields += new /datum/tgs_chat_embed/field("Refs", refs ? refs.Join("\n") : "None")

var/datum/tgs_message_content/sdql = new()
sdql.embed = embed

return sdql

/datum/tgs_chat_command/reload_admins
name = "reload_admins"
Expand All @@ -134,8 +179,48 @@ GLOBAL_LIST(round_end_notifiees)
/datum/tgs_chat_command/reload_admins/Run(datum/tgs_chat_user/sender, params)
ReloadAsync()
log_admin("[sender.friendly_name] reloaded admins via chat command.")
return "Admins reloaded."
return new /datum/tgs_message_content("Admins reloaded.")

/datum/tgs_chat_command/reload_admins/proc/ReloadAsync()
set waitfor = FALSE
load_admins()

/datum/tgs_chat_command/manifest
name = "manifest"
help_text = "Displays the current crew manifest"

/datum/tgs_chat_command/manifest/Run(datum/tgs_chat_user/sender, params)
var/list/manifest = SSovermap.get_manifest()

var/datum/tgs_chat_embed/structure/embed = new()
embed.title = "__Crew Manifest:__"

if(!length(manifest))
embed.description = "No crew manifest available."
else
for(var/ship in manifest)
var/list/members = manifest[ship]
var/datum/tgs_chat_embed/field/ship_field = new(ship, members.Join("\n"))
ship_field.is_inline = TRUE
embed.fields += ship_field

var/datum/tgs_message_content/manifest_content = new()
manifest_content.embed = embed

return manifest_content

/datum/tgs_chat_command/who
name = "who"
help_text = "Displays the current player list"

/datum/tgs_chat_command/who/Run(datum/tgs_chat_user/sender, params)
var/datum/tgs_chat_embed/structure/embed = new()
embed.title = "__Players:__"

for(var/client/player as anything in GLOB.clients)
embed.description += "[player.ckey]\n"

var/datum/tgs_message_content/who = new()
who.embed = embed

return who
14 changes: 3 additions & 11 deletions code/modules/admin/verbs/adminhelp.dm
Original file line number Diff line number Diff line change
Expand Up @@ -735,19 +735,11 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)


/proc/tgsadminwho()
var/list/message = list("Admins: ")
var/list/admin_keys = list()
for(var/adm in GLOB.admins)
var/client/C = adm
admin_keys += "[C][C.holder.fakekey ? "(Stealth)" : ""][C.is_afk() ? "(AFK)" : ""]"
for(var/client/admin as anything in GLOB.admins)
admin_keys += "[admin][admin.holder.fakekey ? "(Stealth)" : ""][admin.is_afk() ? "(AFK)" : ""]"

for(var/admin in admin_keys)
if(LAZYLEN(message) > 1)
message += ", [admin]"
else
message += "[admin]"

return jointext(message, "")
return jointext(admin_keys, "\n")

/proc/keywords_lookup(msg,external)

Expand Down
4 changes: 2 additions & 2 deletions code/modules/admin/verbs/panicbunker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ GLOBAL_LIST_EMPTY(bunker_passthrough)

/datum/tgs_chat_command/addbunkerbypass/Run(datum/tgs_chat_user/sender, params)
if(!CONFIG_GET(flag/sql_enabled))
return "The Database is not enabled!"
return new /datum/tgs_message_content("The Database is not enabled!")

GLOB.bunker_passthrough |= ckey(params)

GLOB.bunker_passthrough[ckey(params)] = world.realtime
SSpersistence.SavePanicBunker() //we can do this every time, it's okay
log_admin("[sender.friendly_name] has added [params] to the current round's bunker bypass list.")
message_admins("[sender.friendly_name] has added [params] to the current round's bunker bypass list.")
return "[params] has been added to the current round's bunker bypass list."
return new /datum/tgs_message_content("[params] has been added to the current round's bunker bypass list.")

/datum/controller/subsystem/persistence/proc/LoadPanicBunker()
var/bunker_path = file("data/bunker_passthrough.json")
Expand Down
11 changes: 5 additions & 6 deletions code/modules/discord/tgs_commands.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

/datum/tgs_chat_command/notify/Run(datum/tgs_chat_user/sender, params)
if(!CONFIG_GET(string/chat_announce_new_game))
return "Notifcations are currently disabled"
return new /datum/tgs_message_content("New round notifications are currently disabled.")

for(var/member in SSdiscord.notify_members) // If they are in the list, take them out
if(member == sender.mention)
SSdiscord.notify_members -= sender.mention
return "You will no longer be notified when the server restarts"
if(sender.mention in SSdiscord.notify_members) // If they are in the list, take them out
SSdiscord.notify_members -= sender.mention
return new /datum/tgs_message_content("You will no longer be notified when the round ends")

// If we got here, they arent in the list. Chuck 'em in!
SSdiscord.notify_members += sender.mention
return "You will now be notified when the server restarts"
return new /datum/tgs_message_content("You will now be notified when the server restarts")

0 comments on commit 88b91d1

Please sign in to comment.