Skip to content

Commit

Permalink
Add the files.
Browse files Browse the repository at this point in the history
  • Loading branch information
TBGRenfold committed Aug 5, 2019
1 parent b428c2a commit fafcf86
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-midnight
70 changes: 70 additions & 0 deletions discord_embed_example.lsl
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
59 changes: 59 additions & 0 deletions discord_example.lsl
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
80 changes: 80 additions & 0 deletions discord_full_embed_example.lsl
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit fafcf86

Please sign in to comment.