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

tried through eval to receive both responses from fetch requests

with querystring

$(eval a=`$(urlfetch$(channel))`;b=`$(urlfetch`;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$(channel))`;b=`$(urlfetch`;c=b.replace('%randUser',a);c=c.replace('%user',$(user));c;)


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$(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:

	`${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$(channel))`;q=decodeURIComponent(`$(querystring)`);$(urlfetch

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$(channel))`;t=`$(urlfetch`#`))`;t[Math.floor(Math.random() * (t.length-1))];)

screenshot 2020-06-02 001

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

$(eval t=`$(urlfetch`;t=t.replace(`%randUser`,`$(urlfetch$(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$(channel))`;q=decodeURIComponent(`$(querystring)`);$(urlfetch

And here’s the content of the paste:

	`${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:


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
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`;q=decodeURIComponent(`$(querystring)`).split(` `);!q?t.replace(`%randUser`,`$(urlfetch$(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]}`);)```

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.