Append to Command

Been looking around on different topics and the docs but haven’t found a way to do this. Is it possible to have a command that appends to an existing one?

For example, it’d work like:

!favorites → UserA
!addfav UserB → !favorites is then “UserA, UserB”
!addfav UserC → !favorites is then “UserA, UserB, UserC”

Basically looking for a way to reference the current command response in the alias and add the new query parameter at the end.

!addcom !addfav -a=!editcom !favorites <current_response>, $(query)

Didn’t see anything in the argument list that’d work like that and not sure calling the NightbotAPI via the urlfetch argument is a good idea or even supported.

Appreciate any thoughts, thanks!

@satic

Not possible to do natively in Nightbot, but a workaround exists using ehsan’s quote API.


Click this link. It will generate three links and two tokens, a public token (8 characters long) and a private token (16 characters long). The public token is located within the first generated link. The private token is located within both the second and third generated links. The tokens are found after token= and before &data=$(querystring) Copy them down and keep them somewhere safe!

I set up 3 commands below: !favorites which shows the list of phrases you have compiled, !addfav (mod-only) which lets you append a new phrase to the list, and !resetfav (mod-only) which clears the list. Copy and paste the following setups into chat. Replace PUBLIC_TOKEN with your public token and PRIVATE_TOKEN with your private token:

!addcom -cd=5 !favorites $(eval a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`;a.startsWith(`~`)?a.split(`~`).filter(c=>c!=``).join(`, `):`No favorite found.`)

!addcom -ul=mod !addfav $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=~$(querystring))`;` `)

!addcom -ul=mod !resetfav $(eval a=`$(urlfetch https://twitch.center/customapi/delquote?token=PRIVATE_TOKEN&clear=1)`;` `)

@RokettoJanpu

Thanks, working as expected! One question, is it possible to change the “empty” list text that’s returned?

Right now its says “There are no quotes added”, curious if I can customize that to say something different. Would that be handled inside the eval javascript?

For folks reference this I got it working below. I will let RokettoJanpu chime in if there is an easier/better way to do this.

!addcom -cd=5 !favorites $(eval a=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`;if(a.startsWith(`~`)) { b=a.split(`~`).filter(c=>c!=``).join(`, `) } else { `No favorite found.`})
1 Like

Literally just saw this and was about to reply, but what you suggested is more or less along the lines of what I would’ve done.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.