Action

omg.lol Status

Posted by podiboq, Last update 6 days ago

UPDATES

6 days ago

The action has been updated to accept multi-line statuses, inspired by a request from @ctt.

Now, the action will post the complete current draft, and will not only accept one or two lines as before.

The emoji or image associated with the status must be present as an emoji positioned as the first character of the draft. If no emoji is present at the start of the draft, a default emoji will be used for the status (the note emoji).

Thank you for using this action!

show all updates...

6 days ago

The action has been updated to accept multi-line statuses, inspired by a request from @ctt.

Now, the action will post the complete current draft, and will not only accept one or two lines as before.

The emoji or image associated with the status must be present as an emoji positioned as the first character of the draft. If no emoji is present at the start of the draft, a default emoji will be used for the status (the note emoji).

Thank you for using this action!

6 days ago

6 days ago

6 days ago

6 days ago

about 3 years ago

  • The API Key and the username are now stored in Drafts Credentials
  • The code has been revisited and explained
  • The status can now be added in 1 or 2 lines

A simple action to update your omg.lol status…

Drafts Credentials keeps your API key and username private. 🤘

Usage

If an emoji is detected as the first character of your draft, it will be used as the status emoji. If not, the 📝 emoji will be used. :)

Steps

  • script

    // >>> Main methods
    
    // Extract first grapheme cluster (including surrogate pairs)
    function getFirstGrapheme(str) {
      if (typeof Intl !== "undefined" && Intl.Segmenter) {
        let segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
        let segments = [...segmenter.segment(str)];
        return segments.length > 0 ? segments[0].segment : "";
      }
      return str.charAt(0);
    }
    
    // Function to detect emoji using Unicode code point ranges commonly used for emojis
    function isEmoji(char) {
      let code = char.codePointAt(0);
      return (
        (code >= 0x1F600 && code <= 0x1F64F) || // Emoticons
        (code >= 0x1F300 && code <= 0x1F5FF) || // Misc Symbols and Pictographs
        (code >= 0x1F680 && code <= 0x1F6FF) || // Transport & Map
        (code >= 0x2600 && code <= 0x26FF)   || // Misc symbols
        (code >= 0x2700 && code <= 0x27BF)   || // Dingbats
        (code >= 0x1F900 && code <= 0x1F9FF) || // Supplemental Symbols and Pictographs
        (code >= 0x1FA70 && code <= 0x1FAFF) || // Symbols & Pictographs Extended-A
        (code >= 0x1F1E6 && code <= 0x1F1FF)    // Regional indicator symbols (flags)
      );
    }
    
    // >>> Action logic
    
    // Storing/getting the omg.lol credentials in Draft's Credential instead of the action code directly
    var credential = Credential.create("omg.lol status", "Keep privately your omg.lol API key and your username");
    credential.addTextField("omg_username", "Your username");
    credential.addPasswordField("omg_api_key", "API Key");
    credential.authorize();
    
    // Get the values and store them in our own variables
    let omg_api_key = credential.getValue("omg_api_key")
    let omg_username = credential.getValue("omg_username")
    
    // Let's init our main variables
    let emoji = ''
    let status = ''
    
    // Let's get the full text of the current Draft
    let content = draft.content;
    let lines = content.split("\n");
    
    // If an emoji is used at the beginning of the message
    // we'll use it as the status emoji
    let line = draft.lines[0]; // get first line of draft (the emoji must be at the beginning)
    
    if (line) {
    	let firstChar = getFirstGrapheme(line);
    
    	if (isEmoji(firstChar)) {
    	  emoji = firstChar
    	  status = content.slice(firstChar.length); // everything except the first emoji
    	} else {
    	  emoji = '📝'
    	  status = content
    	}
    
    	// If we have an emoji and a status, we'll update the omg.lol status :)
    	if (emoji !== '' && status !== '') {
    	  var http = HTTP.create();
    	  var response = http.request({
    	    "url": "https://api.omg.lol/address/" + omg_username + "/statuses",
    	    "method": "POST",
    	    "data": {
    	      "emoji": emoji,
    	      "content": status
    	    },
    	    "headers": {
    	      "Authorization": "Bearer " + omg_api_key
    	    }
    	  });
    	}
    }
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.