L1ghtsh0w

Untitled

Apr 28th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. //This script should work on the Second Life/OpenSimulator platforms (including OpenSim forks).
  2.  
  3. //YOU MUST AGREE TO THE FOLLOWING TERMS AND CONDITIONS TO USE THIS SCRIPT IN ANYWAY.
  4.  
  5. //Do NOT ask for help, this script is provided as is, free of charge and should not be paid for.
  6. //You are not entitled to any future upgrades free of charge.
  7. //You are not entitled to any support of this script of any kind from the author.
  8. //You cannot and will not blame the author of this script for any data loss whilst using this script.
  9. //You agree that this script comes without any warranty of any kind.
  10.  
  11. //If you are not fluent in LSL at all, ask someone you know who is, otherwise you might get a bit confused.
  12. //If you expose your webhook url to the outside world without your permission. That is your fault! This script does not do any of those things,
  13. //so make sure you know where the blame is.
  14.  
  15. //Yes, you can use this in your products, but you may NOT sell this script (as is and/or as) a sole product (integration, usage of parts, etc... is fine).
  16. //Yes Linden Lab, you can use this as well, but the same rules apply!
  17.  
  18. //See https://discordapp.com/developers/docs/resources/webhook for more information on how to format json
  19.  
  20. //Contributors:
  21. //TBG Renfold
  22.  
  23. //END
  24.  
  25. //The usual http request key. Do what you want with it.
  26. key REQUEST_KEY;
  27.  
  28. //Add your discord webhook url below. Otherwise, fail.
  29. string WEBHOOK_URL = "";
  30.  
  31. // Wait for a repsonse from the webhook server? (Default: TRUE)
  32. integer WEBHOOK_WAIT = TRUE;
  33.  
  34. //This is not mandatory, it's just used for this example.
  35. string slurl(key AvatarID)
  36. {
  37. string regionname = llGetRegionName();
  38. vector pos = llList2Vector(llGetObjectDetails(AvatarID, [ OBJECT_POS ]), 0);
  39.  
  40. return "http://maps.secondlife.com/secondlife/"
  41. + llEscapeURL(regionname) + "/"
  42. + (string)llRound(pos.x) + "/"
  43. + (string)llRound(pos.y) + "/"
  44. + (string)llRound(pos.z) + "/";
  45. }
  46.  
  47. //An example function that formats the data to json for posting to the discord webhook.
  48. key PostToDiscord(key AvatarID, string Message)
  49. {
  50. //USERNAME & SLURL variables are only for vanity reasons, but are used within this example.
  51. string USERNAME = llGetUsername(AvatarID);
  52. string SLURL = slurl(AvatarID);
  53. //Anything in the json list values are fair game, edit at will.
  54. list json = [
  55. "content", "Any content here",
  56. "username", llGetObjectName(),
  57. "embeds",
  58. llList2Json(JSON_ARRAY,
  59. [
  60. llList2Json(JSON_OBJECT,
  61. [
  62. "author", llList2Json(JSON_OBJECT,
  63. [
  64. "name", USERNAME,
  65. "icon_url", "https://my-secondlife-agni.akamaized.net/users/" + USERNAME + "/thumb_sl_image.png",
  66. "url", "http://my.secondlife.com/" + USERNAME
  67. ]),
  68. "color", "3447003",
  69. "content", "This is the main content",
  70. "title", "TITLE HERE (Object slurl used as link url in this example)",
  71. "description", Message,
  72. "fields", llList2Json(JSON_ARRAY,
  73. [
  74. llList2Json(JSON_OBJECT,
  75. [
  76. "inline", "true",
  77. "name", USERNAME,
  78. "value", "https://my-secondlife-agni.akamaized.net/users/"
  79. ])
  80. ]),
  81. "footer", llList2Json(JSON_OBJECT,
  82. [
  83. "icon_url", "https://cdn.discordapp.com/embed/avatars/0.png",
  84. "text", "Footer message"
  85. ]),
  86. "image", llList2Json(JSON_OBJECT,
  87. [
  88. "url", "https://cdn.discordapp.com/embed/avatars/0.png"
  89. ]),
  90. "thumbnail", llList2Json(JSON_OBJECT,
  91. [
  92. "url", "https://cdn.discordapp.com/embed/avatars/0.png"
  93. ]),
  94. "url", SLURL
  95. ])
  96. ]),
  97. "tts", "false",
  98. "avatar_url", "https://cdn.discordapp.com/embed/avatars/0.png"
  99. ];
  100.  
  101. string query_string = "";
  102. if (WEBHOOK_WAIT)
  103. query_string += "?wait=true";
  104.  
  105. return llHTTPRequest(WEBHOOK_URL + query_string,
  106. [
  107. HTTP_METHOD, "POST",
  108. HTTP_MIMETYPE, "application/x-www-form-urlencoded",
  109. HTTP_VERIFY_CERT,TRUE,
  110. HTTP_VERBOSE_THROTTLE, TRUE,
  111. HTTP_PRAGMA_NO_CACHE, TRUE ], llList2Json(JSON_OBJECT, json));
  112. }
  113.  
  114. //The rest of this script is pretty self explanitory.
  115. default
  116. {
  117. state_entry()
  118. {
  119. llOwnerSay("Started");
  120. }
  121.  
  122. touch_start(integer total_number)
  123. {
  124. REQUEST_KEY = PostToDiscord(llDetectedKey(0), "Any info you want can be used here.");
  125. }
  126.  
  127. http_response(key request_id, integer status, list metadata, string body)
  128. {
  129. if(REQUEST_KEY == request_id)
  130. {
  131. if (WEBHOOK_WAIT)
  132. llOwnerSay(body);
  133. }
  134. }
  135. }
Add Comment
Please, Sign In to add comment