|
1 | 1 | // tgstation-server DMAPI
|
| 2 | +// The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in IETF RFC 2119. |
2 | 3 |
|
3 |
| -#define TGS_DMAPI_VERSION "7.1.2" |
| 4 | +#define TGS_DMAPI_VERSION "7.2.0" |
4 | 5 |
|
5 | 6 | // All functions and datums outside this document are subject to change with any version and should not be relied on.
|
6 | 7 |
|
7 | 8 | // CONFIGURATION
|
8 | 9 |
|
9 |
| -/// Create this define if you want to do TGS configuration outside of this file. |
| 10 | +/// Consumers SHOULD create this define if you want to do TGS configuration outside of this file. |
10 | 11 | #ifndef TGS_EXTERNAL_CONFIGURATION
|
11 | 12 |
|
12 |
| -// Comment this out once you've filled in the below. |
| 13 | +// Consumers MUST comment this out once you've filled in the below and are not using [TGS_EXTERNAL_CONFIGURATION]. |
13 | 14 | #error TGS API unconfigured
|
14 | 15 |
|
15 |
| -// Uncomment this if you wish to allow the game to interact with TGS 3.. |
| 16 | +// Consumers MUST uncomment this if you wish to allow the game to interact with TGS version 3. |
16 | 17 | // This will raise the minimum required security level of your game to TGS_SECURITY_TRUSTED due to it utilizing call()().
|
17 | 18 | //#define TGS_V3_API
|
18 | 19 |
|
|
52 | 53 |
|
53 | 54 | #ifndef TGS_FILE2TEXT_NATIVE
|
54 | 55 | #ifdef file2text
|
55 |
| -#error Your codebase is re-defining the BYOND proc file2text. The DMAPI requires the native version to read the result of world.Export(). You can fix this by adding "#define TGS_FILE2TEXT_NATIVE file2text" before your override of file2text to allow the DMAPI to use the native version. This will only be used for world.Export(), not regular file accesses |
| 56 | +#error Your codebase is re-defining the BYOND proc file2text. The DMAPI requires the native version to read the result of world.Export(). You SHOULD fix this by adding "#define TGS_FILE2TEXT_NATIVE file2text" before your override of file2text to allow the DMAPI to use the native version. This will only be used for world.Export(), not regular file accesses |
56 | 57 | #endif
|
57 | 58 | #define TGS_FILE2TEXT_NATIVE file2text
|
58 | 59 | #endif
|
|
152 | 153 | //REQUIRED HOOKS
|
153 | 154 |
|
154 | 155 | /**
|
155 |
| - * Call this somewhere in [/world/proc/New] that is always run. This function may sleep! |
| 156 | + * Consumers MUST call this somewhere in [/world/proc/New] that is always run. This function may sleep! |
156 | 157 | *
|
157 | 158 | * * event_handler - Optional user defined [/datum/tgs_event_handler].
|
158 | 159 | * * minimum_required_security_level: The minimum required security level to run the game in which the DMAPI is integrated. Can be one of [TGS_SECURITY_ULTRASAFE], [TGS_SECURITY_SAFE], or [TGS_SECURITY_TRUSTED].
|
| 160 | + * * http_handler - Optional user defined [/datum/tgs_http_handler]. |
159 | 161 | */
|
160 |
| -/world/proc/TgsNew(datum/tgs_event_handler/event_handler, minimum_required_security_level = TGS_SECURITY_ULTRASAFE) |
| 162 | +/world/proc/TgsNew(datum/tgs_event_handler/event_handler, minimum_required_security_level = TGS_SECURITY_ULTRASAFE, datum/tgs_http_handler/http_handler) |
161 | 163 | return
|
162 | 164 |
|
163 | 165 | /**
|
164 |
| - * Call this when your initializations are complete and your game is ready to play before any player interactions happen. |
| 166 | + * Consumers MUST this when your initializations are complete and your game is ready to play before any player interactions happen. |
165 | 167 | *
|
166 | 168 | * This may use [/world/var/sleep_offline] to make this happen so ensure no changes are made to it while this call is running.
|
167 | 169 | * Afterwards, consider explicitly setting it to what you want to avoid this BYOND bug: http://www.byond.com/forum/post/2575184
|
|
170 | 172 | /world/proc/TgsInitializationComplete()
|
171 | 173 | return
|
172 | 174 |
|
173 |
| -/// Put this at the start of [/world/proc/Topic]. |
| 175 | +/// Consumers MUST run this macro at the start of [/world/proc/Topic]. |
174 | 176 | #define TGS_TOPIC var/tgs_topic_return = TgsTopic(args[1]); if(tgs_topic_return) return tgs_topic_return
|
175 | 177 |
|
176 |
| -/** |
177 |
| - * Call this as late as possible in [world/proc/Reboot] (BEFORE ..()). |
178 |
| - */ |
| 178 | +/// Consumers MUST call this as late as possible in [world/proc/Reboot] (BEFORE ..()). |
179 | 179 | /world/proc/TgsReboot()
|
180 | 180 | return
|
181 | 181 |
|
|
269 | 269 | /// The [/datum/tgs_chat_channel] the user was from.
|
270 | 270 | var/datum/tgs_chat_channel/channel
|
271 | 271 |
|
272 |
| -/// User definable handler for TGS events. |
| 272 | +/// User definable handler for TGS events This abstract version SHOULD be overridden to be used. |
273 | 273 | /datum/tgs_event_handler
|
274 | 274 | /// If the handler receieves [TGS_EVENT_HEALTH_CHECK] events.
|
275 | 275 | var/receive_health_checks = FALSE
|
|
283 | 283 | set waitfor = FALSE
|
284 | 284 | return
|
285 | 285 |
|
286 |
| -/// User definable chat command. |
| 286 | +/// User definable handler for HTTP calls. This abstract version MUST be overridden to be used. |
| 287 | +/datum/tgs_http_handler |
| 288 | + |
| 289 | +/** |
| 290 | + * User definable callback for executing HTTP GET requests. |
| 291 | + * MUST perform BYOND sleeps while the request is in flight. |
| 292 | + * MUST return a [/datum/tgs_http_result]. |
| 293 | + * SHOULD log its own errors |
| 294 | + * |
| 295 | + * url - The full URL to execute the GET request for including query parameters. |
| 296 | + */ |
| 297 | +/datum/tgs_http_handler/proc/PerformGet(url) |
| 298 | + CRASH("[type]/PerformGet not implemented!") |
| 299 | + |
| 300 | +/// Result of a [/datum/tgs_http_handler] call. MUST NOT be overridden. |
| 301 | +/datum/tgs_http_result |
| 302 | + /// HTTP response as text |
| 303 | + var/response_text |
| 304 | + /// Boolean request success flag. Set for any 2XX response code. |
| 305 | + var/success |
| 306 | + |
| 307 | +/** |
| 308 | + * Create a [/datum/tgs_http_result]. |
| 309 | + * |
| 310 | + * * response_text - HTTP response as text. Must be provided in New(). |
| 311 | + * * success - Boolean request success flag. Set for any 2XX response code. Must be provided in New(). |
| 312 | + */ |
| 313 | +/datum/tgs_http_result/New(response_text, success) |
| 314 | + if(response_text && !istext(response_text)) |
| 315 | + CRASH("response_text was not text!") |
| 316 | + |
| 317 | + src.response_text = response_text |
| 318 | + src.success = success |
| 319 | + |
| 320 | +/// User definable chat command. This abstract version MUST be overridden to be used. |
287 | 321 | /datum/tgs_chat_command
|
288 | 322 | /// The string to trigger this command on a chat bot. e.g `@bot name ...` or `!tgs name ...`.
|
289 | 323 | var/name = ""
|
|
296 | 330 |
|
297 | 331 | /**
|
298 | 332 | * Process command activation. Should return a [/datum/tgs_message_content] to respond to the issuer with.
|
| 333 | + * MUST be implemented |
299 | 334 | *
|
300 |
| - * sender - The [/datum/tgs_chat_user] who issued the command. |
301 |
| - * params - The trimmed string following the command `/datum/tgs_chat_command/var/name]. |
| 335 | + * * sender - The [/datum/tgs_chat_user] who issued the command. |
| 336 | + * * params - The trimmed string following the command `/datum/tgs_chat_command/var/name]. |
302 | 337 | */
|
303 | 338 | /datum/tgs_chat_command/proc/Run(datum/tgs_chat_user/sender, params)
|
304 | 339 | CRASH("[type] has no implementation for Run()")
|
305 | 340 |
|
306 |
| -/// User definable chat message. |
| 341 | +/// User definable chat message. MUST NOT be overridden. |
307 | 342 | /datum/tgs_message_content
|
308 |
| - /// The tring content of the message. Must be provided in New(). |
| 343 | + /// The string content of the message. Must be provided in New(). |
309 | 344 | var/text
|
310 | 345 |
|
311 | 346 | /// The [/datum/tgs_chat_embed] to embed in the message. Not supported on all chat providers.
|
312 | 347 | var/datum/tgs_chat_embed/structure/embed
|
313 | 348 |
|
| 349 | +/** |
| 350 | + * Create a [/datum/tgs_message_content]. |
| 351 | + * |
| 352 | + * * text - The string content of the message. |
| 353 | + */ |
314 | 354 | /datum/tgs_message_content/New(text)
|
315 | 355 | ..()
|
316 | 356 | if(!istext(text))
|
|
319 | 359 |
|
320 | 360 | src.text = text
|
321 | 361 |
|
322 |
| -/// User definable chat embed. Currently mirrors Discord chat embeds. See https://discord.com/developers/docs/resources/channel#embed-object-embed-structure for details. |
| 362 | +/// User definable chat embed. Currently mirrors Discord chat embeds. See https://discord.com/developers/docs/resources/message#embed-object for details. |
323 | 363 | /datum/tgs_chat_embed/structure
|
324 | 364 | var/title
|
325 | 365 | var/description
|
|
331 | 371 | /// Colour must be #AARRGGBB or #RRGGBB hex string.
|
332 | 372 | var/colour
|
333 | 373 |
|
334 |
| - /// See https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure for details. |
| 374 | + /// See https://discord.com/developers/docs/resources/message#embed-object-embed-image-structure for details. |
335 | 375 | var/datum/tgs_chat_embed/media/image
|
336 | 376 |
|
337 |
| - /// See https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure for details. |
| 377 | + /// See https://discord.com/developers/docs/resources/message#embed-object-embed-thumbnail-structure for details. |
338 | 378 | var/datum/tgs_chat_embed/media/thumbnail
|
339 | 379 |
|
340 |
| - /// See https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure for details. |
| 380 | + /// See https://discord.com/developers/docs/resources/message#embed-object-embed-video-structure for details. |
341 | 381 | var/datum/tgs_chat_embed/media/video
|
342 | 382 |
|
343 | 383 | var/datum/tgs_chat_embed/footer/footer
|
|
346 | 386 |
|
347 | 387 | var/list/datum/tgs_chat_embed/field/fields
|
348 | 388 |
|
349 |
| -/// Common datum for similar discord embed medias. |
| 389 | +/// Common datum for similar Discord embed medias. |
350 | 390 | /datum/tgs_chat_embed/media
|
351 | 391 | /// Must be set in New().
|
352 | 392 | var/url
|
353 | 393 | var/width
|
354 | 394 | var/height
|
355 | 395 | var/proxy_url
|
356 | 396 |
|
| 397 | +/// Create a [/datum/tgs_chat_embed]. |
357 | 398 | /datum/tgs_chat_embed/media/New(url)
|
358 | 399 | ..()
|
359 | 400 | if(!istext(url))
|
360 | 401 | CRASH("[/datum/tgs_chat_embed/media] created with no url!")
|
361 | 402 |
|
362 | 403 | src.url = url
|
363 | 404 |
|
364 |
| -/// See https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure for details. |
| 405 | +/// See https://discord.com/developers/docs/resources/message#embed-object-embed-footer-structure for details. |
365 | 406 | /datum/tgs_chat_embed/footer
|
366 | 407 | /// Must be set in New().
|
367 | 408 | var/text
|
368 | 409 | var/icon_url
|
369 | 410 | var/proxy_icon_url
|
370 | 411 |
|
| 412 | +/// Create a [/datum/tgs_chat_embed/footer]. |
371 | 413 | /datum/tgs_chat_embed/footer/New(text)
|
372 | 414 | ..()
|
373 | 415 | if(!istext(text))
|
374 | 416 | CRASH("[/datum/tgs_chat_embed/footer] created with no text!")
|
375 | 417 |
|
376 | 418 | src.text = text
|
377 | 419 |
|
378 |
| -/// See https://discord.com/developers/docs/resources/channel#embed-object-embed-provider-structure for details. |
| 420 | +/// See https://discord.com/developers/docs/resources/message#embed-object-embed-provider-structure for details. |
379 | 421 | /datum/tgs_chat_embed/provider
|
380 | 422 | var/name
|
381 | 423 | var/url
|
382 | 424 |
|
383 |
| -/// See https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure for details. Must have name set in New(). |
| 425 | +/// See https://discord.com/developers/docs/resources/message#embed-object-embed-author-structure for details. Must have name set in New(). |
384 | 426 | /datum/tgs_chat_embed/provider/author
|
385 | 427 | var/icon_url
|
386 | 428 | var/proxy_icon_url
|
387 | 429 |
|
| 430 | +/// Create a [/datum/tgs_chat_embed/footer]. |
388 | 431 | /datum/tgs_chat_embed/provider/author/New(name)
|
389 | 432 | ..()
|
390 | 433 | if(!istext(name))
|
391 | 434 | CRASH("[/datum/tgs_chat_embed/provider/author] created with no name!")
|
392 | 435 |
|
393 | 436 | src.name = name
|
394 | 437 |
|
395 |
| -/// See https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure for details. Must have name and value set in New(). |
| 438 | +/// See https://discord.com/developers/docs/resources/message#embed-object-embed-field-structure for details. |
396 | 439 | /datum/tgs_chat_embed/field
|
| 440 | + /// Must be set in New(). |
397 | 441 | var/name
|
| 442 | + /// Must be set in New(). |
398 | 443 | var/value
|
399 | 444 | var/is_inline
|
400 | 445 |
|
| 446 | +/// Create a [/datum/tgs_chat_embed/field]. |
401 | 447 | /datum/tgs_chat_embed/field/New(name, value)
|
402 | 448 | ..()
|
403 | 449 | if(!istext(name))
|
|
0 commit comments