mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 05:56:58 +01:00
Fix older DMAPIs [DMDeploy][TGSDeploy]
This commit is contained in:
@@ -4,6 +4,8 @@ TGS_DEFINE_AND_SET_GLOBAL(tgs, null)
|
||||
var/datum/tgs_version/version
|
||||
var/datum/tgs_event_handler/event_handler
|
||||
|
||||
var/list/warned_deprecated_command_runs
|
||||
|
||||
/datum/tgs_api/New(datum/tgs_event_handler/event_handler, datum/tgs_version/version)
|
||||
. = ..()
|
||||
src.event_handler = event_handler
|
||||
|
||||
@@ -193,16 +193,19 @@
|
||||
/datum/tgs_api/v3210/ChatChannelInfo()
|
||||
return list() // :omegalul:
|
||||
|
||||
/datum/tgs_api/v3210/ChatBroadcast(message, list/channels)
|
||||
/datum/tgs_api/v3210/ChatBroadcast(datum/tgs_message_content/message, list/channels)
|
||||
if(channels)
|
||||
return TGS_UNIMPLEMENTED
|
||||
message = UpgradeDeprecatedChatMessage(message)
|
||||
ChatTargetedBroadcast(message, TRUE)
|
||||
ChatTargetedBroadcast(message, FALSE)
|
||||
|
||||
/datum/tgs_api/v3210/ChatTargetedBroadcast(message, admin_only)
|
||||
ExportService("[admin_only ? SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE : SERVICE_REQUEST_IRC_BROADCAST] [message]")
|
||||
/datum/tgs_api/v3210/ChatTargetedBroadcast(datum/tgs_message_content/message, admin_only)
|
||||
message = UpgradeDeprecatedChatMessage(message)
|
||||
ExportService("[admin_only ? SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE : SERVICE_REQUEST_IRC_BROADCAST] [message.text]")
|
||||
|
||||
/datum/tgs_api/v3210/ChatPrivateMessage(message, datum/tgs_chat_user/user)
|
||||
UpgradeDeprecatedChatMessage(message)
|
||||
return TGS_UNIMPLEMENTED
|
||||
|
||||
/datum/tgs_api/v3210/SecurityLevel()
|
||||
|
||||
@@ -49,4 +49,7 @@
|
||||
sender = "<@[sender]>"
|
||||
|
||||
user.mention = sender
|
||||
return stc.Run(user, params) || TRUE
|
||||
var/datum/tgs_message_content/result = stc.Run(user, params)
|
||||
result = UpgradeDeprecatedCommandResponse(result, command)
|
||||
|
||||
return result?.text || TRUE
|
||||
|
||||
@@ -263,7 +263,8 @@
|
||||
for(var/I in channels)
|
||||
var/datum/tgs_chat_channel/channel = I
|
||||
ids += channel.id
|
||||
message = list("message" = message, "channelIds" = ids)
|
||||
message = UpgradeDeprecatedChatMessage(message)
|
||||
message = list("message" = message.text, "channelIds" = ids)
|
||||
if(intercepted_message_queue)
|
||||
intercepted_message_queue += list(message)
|
||||
else
|
||||
@@ -275,14 +276,16 @@
|
||||
var/datum/tgs_chat_channel/channel = I
|
||||
if (!channel.is_private_channel && ((channel.is_admin_channel && admin_only) || (!channel.is_admin_channel && !admin_only)))
|
||||
channels += channel.id
|
||||
message = list("message" = message, "channelIds" = channels)
|
||||
message = UpgradeDeprecatedChatMessage(message)
|
||||
message = list("message" = message.text, "channelIds" = channels)
|
||||
if(intercepted_message_queue)
|
||||
intercepted_message_queue += list(message)
|
||||
else
|
||||
Export(TGS4_COMM_CHAT, message)
|
||||
|
||||
/datum/tgs_api/v4/ChatPrivateMessage(message, datum/tgs_chat_user/user)
|
||||
message = list("message" = message, "channelIds" = list(user.channel.id))
|
||||
message = UpgradeDeprecatedChatMessage(message)
|
||||
message = list("message" = message.text, "channelIds" = list(user.channel.id))
|
||||
if(intercepted_message_queue)
|
||||
intercepted_message_queue += list(message)
|
||||
else
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
|
||||
var/datum/tgs_chat_command/sc = custom_commands[command]
|
||||
if(sc)
|
||||
var/result = sc.Run(u, params)
|
||||
if(result == null)
|
||||
result = ""
|
||||
return result
|
||||
var/datum/tgs_message_content/result = sc.Run(u, params)
|
||||
result = UpgradeDeprecatedCommandResponse(result, command)
|
||||
|
||||
return result?.text
|
||||
return "Unknown command: [command]!"
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
var/list/intercepted_message_queue
|
||||
|
||||
var/list/custom_commands
|
||||
var/list/warned_deprecated_command_runs
|
||||
|
||||
var/list/test_merges
|
||||
var/datum/tgs_revision_information/revision
|
||||
@@ -299,7 +298,8 @@
|
||||
RequireInitialBridgeResponse()
|
||||
return revision
|
||||
|
||||
/datum/tgs_api/v5/proc/UpgradeDeprecatedChatMessage(datum/tgs_message_content/message, senderName)
|
||||
// Common proc b/c it's used by the V3/V4 APIs
|
||||
/datum/tgs_api/proc/UpgradeDeprecatedChatMessage(datum/tgs_message_content/message)
|
||||
if(!istext(message))
|
||||
return message
|
||||
|
||||
|
||||
@@ -31,22 +31,27 @@
|
||||
var/datum/tgs_chat_command/sc = custom_commands[command]
|
||||
if(sc)
|
||||
var/datum/tgs_message_content/response = sc.Run(u, params)
|
||||
|
||||
// Backwards compatibility, used to return a string
|
||||
if(istext(response))
|
||||
warned_deprecated_command_runs = warned_deprecated_command_runs || list()
|
||||
if(!warned_deprecated_command_runs[command])
|
||||
TGS_WARNING_LOG("Custom chat command \"[command]\" is still returning a string. This behaviour is deprecated, please upgrade it to return a [/datum/tgs_message_content].")
|
||||
warned_deprecated_command_runs[command] = TRUE
|
||||
|
||||
response = new /datum/tgs_message_content(response)
|
||||
|
||||
var/list/topic_response = list()
|
||||
if(!istype(response))
|
||||
TGS_ERROR_LOG("Custom chat command \"[command]\" should return a [/datum/tgs_message_content]! Got: \"[response]\"")
|
||||
response = null
|
||||
response = UpgradeDeprecatedCommandResponse(response, command)
|
||||
|
||||
topic_response[DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE_MESSAGE] = response?.text
|
||||
topic_response[DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE] = response?._interop_serialize()
|
||||
return json_encode(topic_response)
|
||||
return TopicResponse("Unknown custom chat command: [command]!")
|
||||
|
||||
// Common proc b/c it's used by the V3/V4 APIs
|
||||
/datum/tgs_api/proc/UpgradeDeprecatedCommandResponse(datum/tgs_message_content/response, command)
|
||||
// Backwards compatibility, used to return a string
|
||||
if(istext(response))
|
||||
warned_deprecated_command_runs = warned_deprecated_command_runs || list()
|
||||
if(!warned_deprecated_command_runs[command])
|
||||
TGS_WARNING_LOG("Custom chat command \"[command]\" is still returning a string. This behaviour is deprecated, please upgrade it to return a [/datum/tgs_message_content].")
|
||||
warned_deprecated_command_runs[command] = TRUE
|
||||
|
||||
return new /datum/tgs_message_content(response)
|
||||
|
||||
var/list/topic_response = list()
|
||||
if(!istype(response))
|
||||
TGS_ERROR_LOG("Custom chat command \"[command]\" should return a [/datum/tgs_message_content]! Got: \"[response]\"")
|
||||
return null
|
||||
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user