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

Asked Dec 4, 2020·5 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

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.

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

5 replies

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

python
!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)

python
!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 :

\
**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.

This thread can be closed.

Thanks potatoeaterlove ! ❤️

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

python
!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

Didn't find your answer? The community is on Discord.

Ask on Discord