Urlfetch with result from a previous urlfetch?

I used the free google translate API to make a translation command for nightbot. The problem is the occasional times where someone writes something well outside ToS or channel-rules in another language and we then end up translating it.
Logical solution is to pass the text through a profanity-filter after translation to english.
I’ve found a good API for this but the problem I’m having is how do I pass the translated text (so a variable) to the next urlfetch?

If I do :

$(eval translated=$(urlfetch [translationAPI]&q="$(querystring)"); profanity=$(urlfetch [filterAPI]&q="translated"))

It obviously doesn’t recognize the variable im trying to pass to the 2nd urlfetch and just checks the string “translated” for profanity.
I also tried nesting the translateAPI within the filterAPI like this:

$(eval profanity=$(urlfetch [filterAPI]&q="$(urlfetch [translationAPI]&q='$(querystring)')"))

but then it doesn’t want to acknowledge the fact that querystring is a variable…

Anyone have any ideas/solutions? Technically i could just have an array of profanity in the eval that I compare the translated text to, but that’s far less accurate then some of the good APIs.

Hey @n3n0x!

That’s what alias commands are for! When you call an urlfetch, it executes them when the command is called, so the text you send to the profanity API is the one the user sent to be translated.

So basically you need your translate command as it was before, and once it’s done, you call the profanity command as an alias, it’ll send the output of the translate command to the profanity filter.

An alias command is like a regular command, it’s just called after the one that was called at first.

1 Like

That’s genius! So simple. Can’t believe I didn’t think of that before. Thank you :slight_smile:

2 Likes

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