-
Notifications
You must be signed in to change notification settings - Fork 10
/
discord_example.lsl
59 lines (51 loc) · 1.7 KB
/
discord_example.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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/json",
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);
}
}
}