FranciscoG / DerpyBot

A Dubtrack.fm Bot using DubAPI and Firebase
MIT License
3 stars 2 forks source link

Add more customization to triggers #36

Open FranciscoG opened 6 years ago

FranciscoG commented 6 years ago

As of now we have the following

%me% - insert the person's name into a trigger %dj% - insert the current DJ's name into a trigger +prop - make the current trigger give a prop point +flow - to add flow points

other possibilities

for example right now if you use +prop you get this: @%dj% now has 137 props :fist:

maybe something like +prop=heart will change it to this @%dj% now has 137 props :heart:

so when we add a dank or trippy point system we can simple use them +dank or +trippy and also use the same system where you can set the icon +dank=smoking

examples: %% GET {url} FROM https://random.dog/woof.json %% GET {file} FROM https://random.dog/meow you can also access sub properties of the json just using the dot notation. It will use lodash.get internally %% GET data.images[1].url from https://whatever.com/api

FranciscoG commented 5 years ago

I really really want to do the GET JSON one.

%% GET key.to[2].item FROM url %%

Strict syntax Trigger must begin and end with the %%

  1. First word must be GET
  2. Second word must be the "path" to the item in the JSON object
  3. Third word must by FROM
  4. Fourth word must be the full url
FranciscoG commented 5 years ago

I'm sure Dubtrack already does this but I will sanitize the return before putting it in the chat

FranciscoG commented 5 years ago

started this work in 1.24.0

using "{ .... }" instead of "%% ... %%"

for now only simple GET requests work

see this comment for an example of how to create this kind of special code trigger

FranciscoG commented 5 years ago

need to add Accept/Content-type JSON headers

FranciscoG commented 5 years ago

these commands can possibly be replaced with the new trigger code but I need to extend what I've done

most of them return JSON but some don't

!fact just uses the response body as is, plain text

!todayfact uses today's date so will have to provide those a util constants

var month = new Date().getMonth() + 1;
var day = new Date().getDate();

!urban combines three different parts of an API return

!translate just builds a URL and puts it on screen, not api calls so have to consider that as well

and finally, figure out a way to search and filter triggers. Could !wasitbrad be done in trigger code?

Keywords:

GET - means that this code block will be making a URL get request

GET JSON.<pathToData> - the json. signals that there will be a json response and everything after the dot will be the path to traverse using lodash.get in the object

GET TEXT - will signal that the response is too be treated as plain text

FROM <url> - set the URL to make a request from

Constants

Still thinking about how to format them. For now inside brackets will do i guess. Trying to figure out what wont clash {M} - will be the current month as Int: var month = new Date().getMonth() + 1;

{D} - will be the today's date: var day = new Date().getDate();

FranciscoG commented 5 years ago

!urban combines three different parts of an API return

// get the first reponse
 var first = json.list[0];

  let def = first.definition;
  let word = first.word;
  let link = first.permalink;

  bot.sendChat(`*${word}* - ${def} ${link}`);

GET JSON.list[0] FROM <url> FORMAT "${word} - ${definition} ${link}"

makes the api call from the url sets json.list[0] as a local var: var obj = json.list[0] then parses the templates replacing the words using them as keys from the local var

FORMAT string - parse string and replace each ${key} with value of obj[key]

FranciscoG commented 5 years ago

More Keywords

FLOW - makes the trigger add a flow point FLOW emoji - use a different emoji PROP PROP emoji

very similar to the normal way of doing it (+prop=ghost) but slightly modified to follow the syntax I'm creating

FranciscoG commented 5 years ago

note to self, the input in the chat box has a character limit of 255 but the input in the DM panel does not have a character limit