Adding an or part to my command

i’m very new to this bot and programming bots in general, so the question is i have this command is a !love command the whole command is

$(eval if (“$(query)” == “streamer”) { var loveMessage = "streamer love ";} else { var loveMessage = “Existe $(urlfetch https://beta.decapi.me/random/number/0/100)% <3 between $(user) and $(query)!”;}loveMessage; )

and in the (“$(query)” == “streamer” || “streamer2”) i want to put more than just one, put other aliases like with the @ or just a nickname and such, can someone tell me a command to “or” there?
thanks

EDIT: i researched more and found how to do it, thanks, for those interested you use this || and it should be like (“$(query)” == “streamer” || “streamer2”)
edit²: it didnt work, so still need to know

You were right by using || for an ‘or’ statement, however you’re not comparing anything on the right side, it should be something like:
"$(query)" == "streamer" || "$(query)" == "streamer2"
However if you want to add alot more then 2 names, it might be easier/shorter to store the names in an array and check if the user is in the array. Example: https://www.w3schools.com/jsref/jsref_includes_array.asp

so if i wanted to use the array it would go like ("$(query)" == [ “streamer”, “streamer2”, “streamer3”, “etc”] ) ?
sorry im very nub in javascript

1 Like

Case-sensitive search for streamer name in input:

$(eval a=[`streamer1`,`streamer2`,`streamer3`,`etc`];a.includes(decodeURIComponent(`$(querystring)`))?`message to display if input contains a streamer name`:`message to display if input does not contain a streamer name`)

Case-insensitive search for streamer name in input:

$(eval a=[`streamer1`,`streamer2`,`streamer3`,`etc`];for(i=0;i<a.length;i++){a[i]=a[i].toLowerCase();}a.includes(decodeURIComponent(`$(querystring)`).toLowerCase())?`message to display if input contains a streamer name`:`message to display if input does not contain a streamer name`)

it totally worked ! thanks
just out of curiosity, i noticed that Its a bit different than the other one, is this just that the way of phrasing is different or it needs to be like that? and how would it be like if i wanted to add another response for another name? like say user 1 and that would trigger a third response.

btw I’m very grateful for the help guys

1 Like

The first solution xgerhard suggested was:

"$(query)" == "streamer1" || "$(query)" == "streamer2"

This is the way you write an “OR” conditional. It checks whether the input ("$(query)") is the same as the first streamer name OR the same as the second streamer name and returns either true or false.

The second solution he suggested was what I just wrote:

a=[`streamer1`,`streamer2`,`streamer3`,`etc`];
a.includes(decodeURIComponent(`$(querystring)`))

This is the way you store all of the streamer names inside an array (the list of streamer names contained inside the brackets []) and checks whether any of the items in that array match the input (a.includes()), and returns true or false.


To have a unique response for a certain streamer name, just add another conditional afterwards that checks whether the input is the same as that streamer name and reassigns a new value to the loveMessage variable (rewrites the response).

so can i do like

a=[streamer1,streamer2,streamer3,etc];
a.includes(decodeURIComponent($(querystring)))
b=[user1,user2,user3,etc];
b.includes(decodeURIComponent($(querystring)))
message to display if input contains a streamer name:
message if contains the user name:
message to display if input does not contain either name)

is it right ? i think i need to add something to link the responses, but i dont know what

noting that the streamer 1, 2 and user 1,2 are aliasses, so in this case user and streamer are one person each.

1 Like

What exactly are you trying to do? Do you want to output a unique response for each streamer name?

3 responses one for streamer a(lets say ivan), one for user b(lets say roketto) and one for neither.

1 Like

Having a unique response for each streamer name, for a small list of streamer names (3 names in this case) you’re better off using a couple of conditionals:

$(eval 
a=decodeURIComponent(`$(querystring)`);
msg=`default message if input does not match any streamer name`;
if(a==`streamer1`){
msg=`message if input is streamer1`;
}
if(a==`streamer2`){
msg=`message if input is streamer2`;
}
msg;
)

i tested and it works partially, the message when the input is not any streamer doesn’t appear at all, any word goes to the first response, but second one works just fine

1 Like

Condensed version with unnecessary white spaces removed that should work:

$(eval a=decodeURIComponent(`$(querystring)`);msg=`default message if input does not match any streamer name`;if(a==`streamer1`){msg=`message if input is streamer1`;}if(a==`streamer2`){msg=`message if input is streamer2`;}msg;)

Ola tudo bom
Guvjubjkbbjbckgincujguvufuviguvubcbigivu

it got the same problem

1 Like

Tested this in chat. It works as expected (case-sensitive search which means the command will not ignore capitalization in the input):

Copy and paste this into chat and try it out. The inputs that will trigger the two unique responses are streamer1 and streamer2. All other inputs (including alternate capitalizations) will result in the default message output.

!addcom !testing $(eval a=decodeURIComponent(`$(querystring)`);msg=`default message if input does not match any streamer name`;if(a==`streamer1`){msg=`message if input is streamer1`;}if(a==`streamer2`){msg=`message if input is streamer2`;}msg;)

Once you are confident the command works fine, replace streamer1 and streamer2 with your streamer names.


Case-insensitive search just in case this is what you’re looking for too:

!addcom !testing $(eval a=decodeURIComponent(`$(querystring)`).toLowerCase();msg=`default message if input does not match any streamer name`;if(a==`streamer1`.toLowerCase()){msg=`message if input is streamer1`;}if(a==`streamer2`.toLowerCase()){msg=`message if input is streamer2`;}msg;)
1 Like

it worked and its exactly what i wanted, you are a life saver, thank you so much
edit: promise last question, how would i put more than one aliasses in this? i tried this, and it didnt work

if

1 Like

Looks like you’re trying to have the same response for two streamer names. Use an OR conditional:

if(a==`streamer1`.toLowerCase()||a==`other streamer`.toLowerCase())

thanks, that is what i wanted. you rock !

1 Like

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