Currently working on a set of custom nightbot commands and I’m running into an issue where all $(urlfetch) requests are run, irrespective of the if/else logic that surrounds them. Some pseudocode to help clarify:
Call this command !logUserID
$(eval
if ($(userlevel) == 'subscriber') {
'$(urlfetch https://myLink.com/add?data=subscriber-$(userid))'; 'subscriber logged';
} else {
'$(urlfetch https://myLink.com/add?data=$(userid))'; 'nonsub logged';
};
)
What I find is that the logic works correctly in terms of the ‘subscriber logged’ and ‘nonsub logged’ being printed to chat by nightbot when a sub vs nonsub uses !logUserID. However, when I go look at my database, I see the following entries logged:
subscriber-12345678
12345678
This indicates to me that, while the if/else logic is being executed correctly by nightbot, both of the urlfetch requests are being executed. Presumably there’s some scope issue that I’m unaware of.
At the end of the day, I really just need to be able to log things to my database conditionally based on whether someone is a sub or nonsub. Workarounds I’ve tried are the following
- Use the if/else logic to write the data to a variable and then use that in a single urlfetch request, like so:
$(eval
if ($(userlevel) == 'subscriber') {
s = 'subscriber-$(userid)';
} else {
s = '$(userid)';
}
`$(urlfetch https://myLink.com/add?data=${s})`
)
Unfortunately, I find that $(urlfetch) needs to be in ‘’ quotes to work properly and the insertion of a variable with ${s} requires `` ticks. These seem incompatible, but hopefully that’s just my lack of familiarity with javascript. This would be a totally viable solution for what I’m trying to do.
- I was alternatively hoping that Nightbot would allow redundant commands that execute different code based on the userlevel of the caller is. i.e. a follower calls !logUserID and that executes command A, while a subscriber calls !logUserID and it executes command B. However, Nightbot just yells at me for creating redundant command names and that’s that.
Hopefully this is clear enough to understand. I’ve spent a couple days trying to sort this out without any luck. Thanks in advance for any assistance!