Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MH+ presents, super simple Local chat to discord relay
- //join us! => https://discord.me/SLguru/
- //my blog => https://sl-memo.blogspot.com/
- //reference https://discord.com/developers/docs/resources/webhook
- // (modify required) ///////////////////////////////////////////////////
- string WEBHOOK_URL = "";
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // WebHook format
- // WEBHOOK_URL =
- // |----------------------------------------------------------------------------------------------------------------------|
- // https://discord.com/api/webhooks/123456789012345678/abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcd
- // |~~~~~~~~~~~~~~~~~~|
- // |WEBHOOK_CHANNEL = |
- // |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // |WEBHOOK_TOKEN =
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /*
- sample:
- for single-channel
- string WEBHOOK_URL = "https://discord.com/api/webhooks/123456789012345678/abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcd";
- for forum-channel(with thread-id)
- string WEBHOOK_URL = "https://discord.com/api/webhooks/123456789012345678/abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcd?thread_id=1234567890123456789";
- */
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- list REQUEST_List;
- integer G_Handle = 0;
- integer SW = FALSE;
- default{
- on_rez(integer i){
- llResetScript();
- }
- state_entry(){
- if(WEBHOOK_URL != ""){
- llOwnerSay("Touch to start the relay");
- }else{
- llOwnerSay("Edit the script and set the Discord Hook URL (WEBHOOK_URL).");
- }
- }
- touch_start(integer total_number){
- if(SW = !SW){
- //start
- llOwnerSay("relay start.");
- G_Handle = llListen(0, "", NULL_KEY, "");
- }else{
- //stop
- llOwnerSay("relay stop.");
- llListenRemove(G_Handle);
- REQUEST_List =[];
- }
- }
- listen(integer channel, string name, key id, string message){
- //
- string User_NAME = llGetUsername(id);
- string User_DISP = llGetDisplayName(id);
- list json;
- if(User_NAME == "" && User_DISP == ""){// is object
- json = [
- "username", name,
- "content", message,
- "avatar_url", "https://my-secondlife-agni.akamaized.net/assets/default/avatar_thumb.png"
- ];
- }else{
- json = [
- "username", User_DISP + " (" + User_NAME + ")",
- "content", message,
- "avatar_url", "https://my-secondlife-agni.akamaized.net/users/" + User_NAME + "/thumb_sl_image.png"
- ];
- }
- //if the image is not registered, a display error will occur, but it will be the icon defined by the webhook.
- key REQUEST_KEY = llHTTPRequest(WEBHOOK_URL,
- [
- HTTP_METHOD, "POST",
- HTTP_MIMETYPE, "application/json",
- HTTP_VERIFY_CERT,TRUE,
- HTTP_VERBOSE_THROTTLE, TRUE,
- HTTP_PRAGMA_NO_CACHE, TRUE
- ], llList2Json(JSON_OBJECT, json));
- REQUEST_List += [REQUEST_KEY];
- }
- http_response(key request_id, integer status, list metadata, string body){
- integer p = llListFindList(REQUEST_List,[request_id]);
- if(~p){
- if(status < 200 || status > 206) llOwnerSay("status = " + (string)status + " ;body = " + body);
- REQUEST_List = llDeleteSubList(REQUEST_List,p,p);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement