How to use and debug javascript in Nightbot?

Hi I’m new here and I am working on a boop command. In short I want it to display one of two messages:

“X has booped themself!” or “X has booped Y!” with X and Y being user names.

If a user types it in chat it’ll be the form of !boop or !boop Y.

So my first impulse is to use $(eval) and argument $(1) to start.

I have:

$(eval 
 $(1) == null ? "You have been booped" : "You have booped $(1)"
)

This results in error and I’m pretty sure it’s how the JS is interpretting $(1). Is there a standard for parsing arguments into JS to be used?

With Eval, do I need to return something for it to work properly?

And what’s the standard for debugging nightbot? I know this is alot of questions but I’m really curious as to how this works.

@vizzioso Keep arguments in JS string format, e.g. "$(1)", '$(touser)', "$(query)".Try this:

$(eval a=decodeURIComponent(`$(querystring)`);a==``?`$(user) has booped themself!`:`$(user) has booped `+a+`!`)
1 Like

That matches my use case perfectly, but if I only want 0 or 1 argument shouldn’t there be a way to extract it just by calling it and assigning it to a variable?

Sure, then just set

a=decodeURIComponent(`$(1)`)

You could of course set

a=`$(1)`

But you’ll run into an error if the input contains a backtick.

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