Editing a command from within command without replacing $(query)

Context

In a racing game, you have to complete three laps. I have a !laps command which takes as arguments the times for both lap 1 and lap 2 and gives the time for lap 3 needed to beat the world record (actually this is more complicated than that but it is not relevant for explaining what I am trying to do).

For instance :
!laps 33.6 33.2
Needs a 33.1 lap 3 to improve WR.

NB : In the real version of this command, there are not always two arguments.

If the streamer changes track, he needs to update the WR time.

If the world record time was hardcoded in the laps command, changing its value in the middle of 500 characters of tightly packed javascript code would be annoying (the streamer knows nothing about computer programming, so if he messes up a semicolon for instance, he will not be able to fix it).

Current solution

I’m using a back-end command !__laps_ which takes 3 arguments : first the world record time, then the lap 1 time and the lap 2 time. Then I define the !laps command as an alias.

!addcom !laps -a=!__laps_ wrTime $(query)

The world record time is still hardcoded but this is much nicer to edit.

What I am trying to do

I am trying to make a !setwrtime command which modifies the world record time. This will be more convenient than editing by hand the !laps command. Besides any moderator will be abble to change the world record time (no need to know how !laps works).

My best guess (potatoeaterlove’s solution)
!addcom !setwrtime -ul=moderator -a=!editcom !laps $(1) $(query)

However when I call !laps 1000 for instance, $(query) gets replaced as well.

Minimal working example

NB : I modify the user level for !__laps_ afterwards in order to save characters.

!addcom !__laps_ $(eval $(1) - $(2) - $(3))

!editcom !__laps_ -ul=moderator

!addcom !laps -a=!__laps_ 144.863 $(query)

# does not work
!addcom !setwrtime -ul=moderator -a=!editcom !laps $(1) $(query)

Solution (thanks potatoeaterlove)

!addcom !setwrtime -ul=moderator -a=!editcom !laps $(1) $(eval String.fromCharCode(36,40,113,117,101,114,121,41))

!addcom !laps -a=!__laps_

!addcom !__laps_ -ul=moderator $(eval $(1)-$(2)-$(3))

!setwrtime 1000

You can just edit the other command you don’t need to reinclude the alias to my knowledge that should stay the same.

EDIT :

Ok I understood what you meant. The issue is that $(query) gets replaced as well.

I typed :

!addcom !setwrtime -ul=moderator -a=!editcom !laps $(1) $(query)


Previous Message:

I understood what you suggested as :

!addcom !setwrtime -ul=moderator -a=!editcom !laps !__laps_ $(1) $(query)

After doing that, when I call !setwrtime 1000, I get “The command “!laps” has been edited successfully.” but when I call !laps 42 42 I get “__laps_ is not defined”.

Try these:

!addcom !setwrtime -ul=moderator -a=!editcom !laps !__laps_ $(1) $(eval String.fromCharCode(36,40,113,117,101,114,121,41))

!addcom !laps -a=!editcom !__laps_ NumberX $(query)

!addcom !__laps_ -ul=moderator $(eval $(1)-$(2)-$(3))

You may need to add these through the dashboard cause during my testing nightbot was acting wierd if I re added the command with a different output by not replacing it and reverting to the old output.

But if you add these right they should work as they worked for me.

1 Like

This thread can be closed.

Thanks potatoeaterlove ! :heart:

This String.FromCharCode was the clever trick I needed. I just used a slightly different version :

!addcom !setwrtime -ul=moderator -a=!editcom !laps $(1) $(eval String.fromCharCode(36,40,113,117,101,114,121,41))

!addcom !laps -a=!__laps_

!addcom !__laps_ -ul=moderator $(eval $(1)-$(2)-$(3))

!setwrtime 1000
1 Like

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