Hello there folks!
I’ve been starting to mess around with customapi’s to expand my command repertoire,
in this particular case I am trying to expand the amount of randomly selected answers I can parse from a command.
Take a “hug” command for instance, with several responses:
$(eval const responses = ['$(user) has decided to give $(query) a big hug!', '$(user) just slipped their arms around $(query).', '$(query) just got tackled and cuddled by $(user)!', 'I believe that $(user) likes $(query) very much. Hugs!', 'Free hugs for $(query)!', 'Dawwww, $(user) and $(query) are adorable.']; if(!
$(query)){
Please tell us who you’d like to share the love with! (!hug username)}else{responses[Math.floor(Math.random() * responses.length)];})
Now this allows me to have multiple responses to the command being used, and is a lot of fun for the viewers of the channels I moderate. Sadly using this method, you rapidly run into the 400 caracter limit for nightbot commands.
So little old me decided 'Why not use a $(customapi) and host a text file and a php file online, and just have the php code call up a random line from the text file?!
It’d look something like this:
<?php
$f_contents = file("hug.txt");
$line = $f_contents[rand(0, count($f_contents) - 1)];
print_r($line)
?>
Of course, I ran into the obvious issue here that $(user) and $(query) are simply returned as such, in text form. Instead of being used as parameters. And that makes perfect sense to me.
But I can not for the love of God find how to accomplish this!
I know it can be done, as demonstrated by the “!followage” command:
$(touser) Has Been Following $(channel) on Twitch since $(customapi http://api.newtimenow.com/follow-length/?channel=$(channel)&user=$(touser))
where both $(channel) and $(touser) are parameters that are used in the customapi http://api.newtimenow.com/follow-length/
But what I can not grasp is how to transcribe these variables into code that could use them.
Does this mean that $(channel) and $(touser) are put into two variables (channel and user) ?
Would I be able to simply use those two variables without declaring them?
Do I need to have a line in my .php to call these variables?
Esentially, how can I incorporate these things into my custom api.
If this has already been answered somewhere, I’m sorry for wasting your time, but I could simply not find it.
If it hasn’t, I’d be more than delighted to know some more about this.
Thank you for your time reading this.