Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This script should work on the Second Life/OpenSimulator platforms (including OpenSim forks).
- //YOU MUST AGREE TO THE FOLLOWING TERMS AND CONDITIONS TO USE THIS SCRIPT IN ANYWAY.
- //Do NOT ask for help, this script is provided as is, free of charge and should not be paid for.
- //You are not entitled to any future upgrades free of charge.
- //You are not entitled to any support of this script of any kind from the author.
- //You cannot and will not blame the author of this script for any data loss whilst using this script.
- //You agree that this script comes without any warranty of any kind.
- //If you are not fluent in LSL at all, ask someone you know who is, otherwise you might get a bit confused.
- //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,
- //so make sure you know where the blame is.
- //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).
- //Yes Linden Lab, you can use this as well, but the same rules apply!
- //See https://discordapp.com/developers/docs/resources/webhook for more information on how to format json
- //Contributors:
- //TBG Renfold
- //END
- //The usual http request key. Do what you want with it.
- key REQUEST_KEY;
- //Add your discord webhook url below. Otherwise, fail.
- string WEBHOOK_URL = "";
- // Wait for a repsonse from the webhook server? (Default: TRUE)
- integer WEBHOOK_WAIT = TRUE;
- //This is not mandatory, it's just used for this example.
- string slurl(key AvatarID)
- {
- string regionname = llGetRegionName();
- vector pos = llList2Vector(llGetObjectDetails(AvatarID, [ OBJECT_POS ]), 0);
- return "http://maps.secondlife.com/secondlife/"
- + llEscapeURL(regionname) + "/"
- + (string)llRound(pos.x) + "/"
- + (string)llRound(pos.y) + "/"
- + (string)llRound(pos.z) + "/";
- }
- //An example function that formats the data to json for posting to the discord webhook.
- key PostToDiscord(key AvatarID, string Message)
- {
- //USERNAME & SLURL variables are only for vanity reasons, but are used within this example.
- string USERNAME = llGetUsername(AvatarID);
- string SLURL = slurl(AvatarID);
- //Anything in the json list values are fair game, edit at will.
- list json = [
- "content", "Any content here",
- "username", llGetObjectName(),
- "embeds",
- llList2Json(JSON_ARRAY,
- [
- llList2Json(JSON_OBJECT,
- [
- "author", llList2Json(JSON_OBJECT,
- [
- "name", USERNAME,
- "icon_url", "https://my-secondlife-agni.akamaized.net/users/" + USERNAME + "/thumb_sl_image.png",
- "url", "http://my.secondlife.com/" + USERNAME
- ]),
- "color", "3447003",
- "content", "This is the main content",
- "title", "TITLE HERE (Object slurl used as link url in this example)",
- "description", Message,
- "fields", llList2Json(JSON_ARRAY,
- [
- llList2Json(JSON_OBJECT,
- [
- "inline", "true",
- "name", USERNAME,
- "value", "https://my-secondlife-agni.akamaized.net/users/"
- ])
- ]),
- "footer", llList2Json(JSON_OBJECT,
- [
- "icon_url", "https://cdn.discordapp.com/embed/avatars/0.png",
- "text", "Footer message"
- ]),
- "image", llList2Json(JSON_OBJECT,
- [
- "url", "https://cdn.discordapp.com/embed/avatars/0.png"
- ]),
- "thumbnail", llList2Json(JSON_OBJECT,
- [
- "url", "https://cdn.discordapp.com/embed/avatars/0.png"
- ]),
- "url", SLURL
- ])
- ]),
- "tts", "false",
- "avatar_url", "https://cdn.discordapp.com/embed/avatars/0.png"
- ];
- string query_string = "";
- if (WEBHOOK_WAIT)
- query_string += "?wait=true";
- return llHTTPRequest(WEBHOOK_URL + query_string,
- [
- HTTP_METHOD, "POST",
- HTTP_MIMETYPE, "application/x-www-form-urlencoded",
- HTTP_VERIFY_CERT,TRUE,
- HTTP_VERBOSE_THROTTLE, TRUE,
- HTTP_PRAGMA_NO_CACHE, TRUE ], llList2Json(JSON_OBJECT, json));
- }
- //The rest of this script is pretty self explanitory.
- default
- {
- state_entry()
- {
- llOwnerSay("Started");
- }
- touch_start(integer total_number)
- {
- REQUEST_KEY = PostToDiscord(llDetectedKey(0), "Any info you want can be used here.");
- }
- http_response(key request_id, integer status, list metadata, string body)
- {
- if(REQUEST_KEY == request_id)
- {
- if (WEBHOOK_WAIT)
- llOwnerSay(body);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement