Action

omg.lol Status

Posted by podiboq, Last update 2 months ago

UPDATES

2 months 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… Your API key and your username are kept privately in Drafts Credentials 🤘

Usage

Format #1 :

emoji message

Example :

🎉 This is my new status

Format #2 :

emoji
message

Example :

🎉
This is my new status

Steps

  • script

    // Storing 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();
    
    // We'll 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")
    
    // Using the code from the "Remove blank lines" action
    // (c) dchar - https://actions.getdrafts.com/a/1Er
    function deblank(s) {
      return s.split('\n').filter(l => l.trim()).join('\n');
    }
    
    // Let's get the text of the current Draft (and remove any empty lines)
    // let content = editor.getText();
    // let lines = content.split("\n");
    let content = deblank( draft.content );
    let lines = content.split("\n");
    
    // We'll check if the status is on 
    // 	==> 1 line (emoji message) 
    //	or 
    // 	==> 2 lines (emoji / message)
    let emoji = ''
    let status = ''
    
    if(lines.length == 1) {
      let words = lines[0].split(' ');
      emoji = words[0];
      words[0] = '';
      status = words.join(' ').trim();
    }
    else if(lines.length == 2) {
      emoji = lines[0]
      status = lines[1]
    } 
    else {
      alert('The status should be on 1 or 2 lines, but you have more than that...')
    }
    
    // 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.