custom slap conmmands

There are different ways to make a slap command, but I would like to make commands in the quote system using templates with the choice of querystring or random user
how it should look
templates quote system

%user slap %randUser
%randUser dodged slap %user
etc

tried through eval to receive both responses from fetch requests

with querystring

$(eval a=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;b=`$(urlfetch http://twitch.center/customapi/quote?token=0ff178fe&no_id=1)`;q=decodeURIComponent("$(querystring)");q?`.me ${b.replace('%randUser',q).replace('%user',$(user))}`:`.me ${b.replace('%randUser',a).replace('%user',$(user))}`)

without querystring

$(eval a=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;b=`$(urlfetch http://twitch.center/customapi/quote?token=0ff178fe&no_id=1)`;c=b.replace('%randUser',a);c=c.replace('%user',$(user));c;)

etc

but constantly getting
$(user) is not defined // in this case QZMTCH is not defined

the question is, can two fetch requests be used in one eval?
is it possible to somehow make it so that it is possible to use random messages perhaps even sometimes without a user where instead of a user there would be a nightbot?
help solve this problem

1 Like

Hey @qzmtch!

Why exactly use the quote system? You don’t need it for a simple slap command like the one you’re thinking about, it’s pretty much a waste of resources. There is much more simple:

 !addcom !slap $(eval r=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`; `$(query)`?`$(user) slaps ${decodeURIComponent(`$(querystring)`)}.`:`$(user) slaps ${r}.`;)

Basically r is the random viewer, and then we test if there’s a $(query), if yes, we use it, if no, we use r, the random viewer.

1 Like

yes, but then you can’t make teams with different texts, with different actions, such as where instead of the user there is a nightbot, or when randUser did something to the user

1 Like

Edited to avoid errors

Ok, I see what you want to do now, then I think using Pastebin would still be a better solution. Create an account and make a private paste that won’t expire.
And the paste will look like this for example:

r=Math.floor(Math.random()*3);
if(r==0){
	`${q}`?`${u} slaps ${q}`:`${u} slaps ${t}`;}
else if(r==1){
	`${t} dodged a slap from ${u}`;}
else if(r==2){
	t==`nightbot`?`Get out of here, Nightbot!`:`Welcome in ${t}`;}

Then the command would look like this:

!addcom !randomresponse $(eval u=`$(user)`;t=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;q=decodeURIComponent(`$(querystring)`);$(urlfetch https://pastebin.com/raw/XXXXXXXX))

Replace XXXXXXXX by the paste ID.

1 Like

I try, while it turns out only
Right-hand side of ‘instanceof’ is not an object

so far, only with this code it turned out without error to display a message, but only one character

$(eval r=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;t=`$(urlfetch https://pastebin.com/raw/wm56xdC2.split(`#`))`;t[Math.floor(Math.random() * (t.length-1))];)
screenshot

screenshot 2020-06-02 001

trial and error, I found a way that works for me, using a quote system

$(eval t=`$(urlfetch http://twitch.center/customapi/quote?token=0ff178fe&no_id=1)`;t=t.replace(`%randUser`,`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`).replace(`%user`,`$(user)`);t;)

then I want to customize the command so that you can use querystring, and maybe the second argument, such as

!slap nick nick
the first argument will be the one who slaps, and the second one who gets

If someone else can improve the code that I wrote above with a quotation system or pastebin (which never worked for me), please write in the comments, I would really like to see the implementation of these features, from those who know how to write this or that code in short.
Thanks to all
PS one more request, I looked at the forum a few topics about pastebin, one more request, I looked at the forum on several topics about pastebin, and I would like from those who know more than me how to use pastebin to extend the code, it just came up with the idea of making more replaceable variables in the template quote system, besides %user %randUser add %rand (randomNumber) etc
if possible, then write in the answer how to do it correctly, without errors
thanks in advance

Sorry for the trouble, got a couple of busy days and I didn’t have time to test the command I was giving you, $(urlfetch) can be a bit of a pain sometimes, my bad, anyway, here’s the solutiom, I tested it this time, and this will answer your question on how to extend code with a Pastebin as well.

So here’s the command:

$(eval u=`$(user)`;t=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;q=decodeURIComponent(`$(querystring)`);$(urlfetch https://pastebin.com/raw/XXXXXXXX))

And here’s the content of the paste:

r=Math.floor(Math.random()*3);
if(r==0){
	`${q}`?`${u} slaps ${q}`:`${u} slaps ${t}`;}
else if(r==1){
	`${t} dodged a slap from ${u}`;}
else if(r==2){
	t==`nightbot`?`Get out of here, Nightbot!`:`Welcome in ${t}`;}

Notice how I declare every variables I use in the paste before using $(urlfetch) to call the paste, I do it this way because Nightbot doesn’t replace variables such as $(user) if the code comes from the paste.
The idea behind the code in the paste is that since I have 3 different possible responses, I generate a random number between 0 and 2 and then from there I select which response Nightbot will give.


And regarding your question with having two arguments, you can do it like so:

q=decodeURIComponent(`$(querystring)`).split(` `);`q[0] slaps q[1]`;

However you’ll have to adapt it to fit your current command, this is the main idea without tests to handle potential errors.

1 Like

thank you very much, then I will try to expand :slightly_smiling_face:

2 Likes

Let us know if you need further help when expanding it.

1 Like

well, thanks if something doesn’t work out, I’ll ask you :ok_hand:

1 Like

there is a minor problem with the length, if you write the command
!slap nick
and if you write
!slap
it will be the same length 1

then somehow I will try, but I would like you to suggest some sort of option how to make !slap replace with random, and not an empty string as with !slap nick

PS here is the command i tried to do

$(eval t=`$(urlfetch http://twitch.center/customapi/quote?token=99f7959a&no_id=1)`;q=decodeURIComponent(`$(querystring)`).split(` `);!q?t.replace(`%randUser`,`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`).replace(`%user`,`$(user)`):q.length==1?t.replace(`%randUser`,`${q[0]}`).replace(`%user`,`$(user)`):t.replace(`%randUser`,`${q[1]}`).replace(`%user`,`${q[0]}`))
1 Like

That’s because q has never a length of 0 since we split with a space with .split(` `).

The solution is to replace your !q?: test with !`$(query)`?: since $(query)` can be empty.
I tried the following code and it works as intended:

$(eval t=`%user slaps %randUser`;q=decodeURIComponent(`$(querystring)`).split(` `);!`$(query)`?t.replace(`%randUser`,`RANDOM_USER`).replace(`%user`,`$(user)`):q.length==1?t.replace(`%randUser`,`${q[0]}`).replace(`%user`,`$(user)`):t.replace(`%randUser`,`${q[1]}`).replace(`%user`,`${q[0]}`);)```
2 Likes

thanks, it works for me, I will know that $(query) can be empty :slightly_smiling_face:

1 Like

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