Call Nightbot command within eval()?

Hi, my intention is to modify the song request command implementation to only allow a user to request a song if they are following the channel. This would be trivial to accomplish if a “followers” level existed – but it seems that the devs are disinclined to add this level.

I have browsed the forums and have found that in the past the response is “That doesn’t make sense.”

This response dismisses why someone would want to do this:
This feature is desirable because it provides a fair exchange between broadcasters who want to increase their followers and non-following viewers who want to request a song.

The exchange doesn’t cost either party anything and both parties benefit from this implementation: a viewer can request a song and a broadcaster can add a new follower. Yes, I realize it’s just as easy for a viewer to un-follow after requesting a song, but I place greater odds on the outcome that users won’t un-follow after making a request. Even if 90% of users unfollow after making a request (which seems highly unlikely) then the broadcaster is still adding new followers regardless.

So I began creating an eval command to determine whether the user is following and perform a song request if true. The pseudo-implementation would be something like:

$(eval isFollowing ? `!sr $(query)` : "Sorry message";)

I have tried to find similar requests related to calling Nightbot commands within eval on the forums but haven’t been able to find a post specifically related to my question.

I have also tried to locate the implementation of !sr or !songs request foo but haven’t seen the code anywhere, so there doesn’t seem to be a way to mock up the !sr command in the eval.

The simplest solution seems like it would be a call to the !sr command and supply it with $(query) (though it’s not clear if this is possible)

The next simplest solution might be to paste the !sr code as an expression that returns when some condition is true.

Alternatively, it seems that it might be possible to kludge something together with Nightbot API to post a request to the queue but it’s not clear from the API songrequest documentation whether this is feasible, or how it could be achieved using $(urlfetch) and supplying q=$(query) where $(query) is the song name or address supplied by the user.

Here’s the code I’ve written in an attempt to implement the simple case (just call the !sr command):

 $(eval 
 var followQuery = `$(urlfetch https://2g.be/twitch/following.phpuser=$(touser)&channel=$(channel))`; 
 var isFollowing = followQuery.includes("has been following");
 isFollowing ? `!sr $(query)` : "Sorry, $(touser), song requests are only available for followers.";
 )

The statement evaluates correctly (as in, returns true if following and sorry message if not; the !sr query above is stub for the desired behavior) – I only need help with the return when the condition is true: calling the song request command correctly, mocking the implementation of it, or supplying a custom call to the API.

Any suggestions?

You can’t call a command from within eval at this time, unfortunately. If you want to hit our API you can, but you’d need to build a remote script that urlfetch calls within the command.

Thanks night! I figured this might be the case, but I wanted to double-check before I went down that road of cobbling together a remote script in the event that a simpler solution was available.

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