diff --git a/README.md b/README.md new file mode 100644 index 0000000..22c6248 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Discord Webhook Client Api. + +Discord webhook example for Second Life/Opensimulator + +Allows you to post messages to your Discord server from Second Life or Opensimulator objects. + +This script is aimed at developers, not the general public, even though you are more than welcome to use it. + +See https://discordapp.com/developers/docs/resources/webhook for more information on how to format json + +In Second Life: +Get it delivered to your inventory: https://marketplace.secondlife.com/p/Discord-Webhook-Api-Client/13515102 diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..1885487 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-midnight \ No newline at end of file diff --git a/discord_embed_example.lsl b/discord_embed_example.lsl new file mode 100644 index 0000000..386cdf9 --- /dev/null +++ b/discord_embed_example.lsl @@ -0,0 +1,70 @@ +key REQUEST_KEY; + +string WEBHOOK_CHANNEL = ""; +string WEBHOOK_TOKEN = ""; +string WEBHOOK_URL = "https://discordapp.com/api/webhooks/"; +integer WEBHOOK_WAIT = TRUE; + +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) + "/"; +} + +key PostToDiscord(key AvatarID, string Message) +{ + string SLURL = slurl(AvatarID); + list json = [ + "username", llGetObjectName() + "", + "embeds", + llList2Json(JSON_ARRAY, + [ + llList2Json(JSON_OBJECT, + [ + "color", "100000", + "title", "More info (uses url setting as link)", + "description", llGetUsername(AvatarID) + ": " + Message + "\nProfile: http://my.secondlife.com/" + llGetUsername(AvatarID) + "\nLocation: " + SLURL, + "url", SLURL + ]) + ]), + "avatar_url", "https://my-secondlife-agni.akamaized.net/users/" + llGetUsername(AvatarID) + "/sl_image.png" + ]; + string query_string = ""; + if (WEBHOOK_WAIT) + query_string += "?wait=true"; + + return llHTTPRequest(WEBHOOK_URL + WEBHOOK_CHANNEL + "/" + WEBHOOK_TOKEN + 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)); +} + +default +{ + state_entry() + { + + } + + touch_start(integer total_number) + { + REQUEST_KEY = PostToDiscord(llDetectedKey(0), "Help point info from script :P"); + } + http_response(key request_id, integer status, list metadata, string body) + { + if(REQUEST_KEY == request_id) + { + if (WEBHOOK_WAIT) + llOwnerSay(body); + } + } +} \ No newline at end of file diff --git a/discord_example.lsl b/discord_example.lsl new file mode 100644 index 0000000..2bd1815 --- /dev/null +++ b/discord_example.lsl @@ -0,0 +1,59 @@ +key REQUEST_KEY; + +string WEBHOOK_CHANNEL = ""; +string WEBHOOK_TOKEN = ""; +string WEBHOOK_URL = "https://discordapp.com/api/webhooks/"; +integer WEBHOOK_WAIT = TRUE; + +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) + "/"; +} + +key PostToDiscord(key AvatarID, string Message) +{ + list json = [ + "username", llGetObjectName() + "", + "content", llGetUsername(AvatarID) + ": " + Message + "\n\nProfile: http://my.secondlife.com/" + llGetUsername(AvatarID) + "\nLocation: " + slurl(AvatarID), + "avatar_url", "https://my-secondlife-agni.akamaized.net/users/" + llGetUsername(AvatarID) + "/sl_image.png" + ]; + string query_string = ""; + if (WEBHOOK_WAIT) + query_string += "?wait=true"; + + return llHTTPRequest(WEBHOOK_URL + WEBHOOK_CHANNEL + "/" + WEBHOOK_TOKEN + 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)); +} + +default +{ + state_entry() + { + + } + + touch_start(integer total_number) + { + REQUEST_KEY = PostToDiscord(llDetectedKey(0), "Help point info from script :P"); + } + http_response(key request_id, integer status, list metadata, string body) + { + if(REQUEST_KEY == request_id) + { + if (WEBHOOK_WAIT) + llOwnerSay(body); + } + } +} \ No newline at end of file diff --git a/discord_full_embed_example.lsl b/discord_full_embed_example.lsl new file mode 100644 index 0000000..b76f8aa --- /dev/null +++ b/discord_full_embed_example.lsl @@ -0,0 +1,80 @@ +key REQUEST_KEY; + +string WEBHOOK_CHANNEL = ""; +string WEBHOOK_TOKEN = ""; +string WEBHOOK_URL = "https://discordapp.com/api/webhooks/"; +integer WEBHOOK_WAIT = TRUE; + +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) + "/"; +} + +key PostToDiscord(key AvatarID, string Message) +{ + string SLURL = slurl(AvatarID); + list json = [ + "username", llGetObjectName() + "", + "embeds", + llList2Json(JSON_ARRAY, + [ + llList2Json(JSON_OBJECT, + [ + "color", "100000", + "title", "More info (uses url setting as link, also the authors name links to the url)", + "description", llGetUsername(AvatarID) + ": " + Message + "\nProfile: http://my.secondlife.com/" + llGetUsername(AvatarID) + "\nLocation: " + SLURL, + "url", SLURL, + "author", llList2Json(JSON_OBJECT, + [ + "name", "Author Name", + "icon_url", "https://my-secondlife-agni.akamaized.net/users/" + llGetUsername(AvatarID) + "/sl_image.png" + ]), + "footer", llList2Json(JSON_OBJECT, + [ + "icon_url", "https://my-secondlife-agni.akamaized.net/users/" + llGetUsername(AvatarID) + "/sl_image.png", + "text", "Any footer text" + ]) + ]) + ]), + "avatar_url", "https://my-secondlife-agni.akamaized.net/users/alethiaisland.engineer/thumb_sl_image.png" + ]; + string query_string = ""; + if (WEBHOOK_WAIT) + query_string += "?wait=true"; + + return llHTTPRequest(WEBHOOK_URL + WEBHOOK_CHANNEL + "/" + WEBHOOK_TOKEN + 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)); +} + +default +{ + state_entry() + { + + } + + touch_start(integer total_number) + { + REQUEST_KEY = PostToDiscord(llDetectedKey(0), "Help point info from script :P"); + } + http_response(key request_id, integer status, list metadata, string body) + { + if(REQUEST_KEY == request_id) + { + if (WEBHOOK_WAIT) + llOwnerSay(body); + } + } +} \ No newline at end of file