Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros activated from comment (#) and sentence display ("") #142

Closed
Sumirre opened this issue Mar 11, 2022 · 1 comment
Closed

Macros activated from comment (#) and sentence display ("") #142

Sumirre opened this issue Mar 11, 2022 · 1 comment
Assignees

Comments

@Sumirre
Copy link

Sumirre commented Mar 11, 2022

Hey,
My issue is pretty simple and I'm probably just missing something.
The pattern of my macros are single letters "o" and "s".
When I want to make a comment to it, containing the same small letters, macros are being repeated, even tho everything past # should be ignored by the bot. In the result when I write a comment "# snake in sorrow", it will trigger "s" macro 2 additional times and "o" also two additional times, making bot showing the error.

It looks like this:

  1. when I use comment with big O and S: https://i.imgur.com/IpSOT6S.png
  2. when I use comment with small o and s: https://i.imgur.com/GBBTYk0.png

Here are the 2 macros I have on my server:
1st macro: "o"
;$1i:[<=4]{" dodge failed"}{$1i:[5..7]{" weak dodge"}{$1i:[8..12]{" successful dodge"}{$1i:[>=13]{" critical dodge"}}}} False
To trigger I use, for example: !1d14+2o or just !d14o

2nd macro: "s"
d10;1d10;$1c[>=$2];"DL $2 | rolls [@1] | successes $3" True
To trigger I use, for exampple: !3s

While testing it I also realised that the first macro is being interrupted by activating 2nd macro because of the "successful" word, which contains said "s" ( https://i.imgur.com/AmOQTmV.png )
So, the question is -> is this issue to be somehow fixed or should I just use longer patterns that are impossible to be repeated in any word?
The 2nd option seems to me a bit odd since on the other server a friend of mine has macros named "p" or "k" or "s" also and nothing is being trigerred like that (neither by # comment nor macro sentence display in "")
I tried to use False for Regular expression too, hoping that it will change something but it doesn't affect anything.

@obiwankennedy
Copy link
Member

There are 2 methods of substitution to transform macro to real command.
The last parameter of macro adding command defined the method you want.

# Method 1 - Find and replace (when you put False at the end)

The first substitution mode is very simple. It is simple find and replace. It is up to you to find solution and to use pattern which will only be present once in your command.

Each macro is tested in the order of appearence when you send !macro list command.

Example:

If you have these 3 macros (in that order):

  • s => +20
  • i => +1d6
  • o => i:[>20]{"Success"}{"Failure"}

If you roll:

  • !1d6s it will become => !1d6+20
  • !1d6i it will become => !1d6+1d6
  • !1d6is it will become => !1d6+1d6+20
  • !4d6o it will become => !4d6i:[>20]{"Success"}{"Failure"}

Now, you add these 3 macro (in that order):

  • o => i:[>20]{"Success"}{"Failure"}
  • s => +20
  • i => +1d6

If you roll:

  • !1d6s => !1d6+20
  • !1d6i => !1d6+1d6
  • !4d6o => !4d6i:[>20]{"Success"}{"Failure"} => !4d6i:[>20]{"Succe+20+20"}{"Failure"} => !4d6+1d6:[>20]{"Succe+20+20"}{"Fa+1d6lure"}

This method is really simple and perfect if you have no changing part or if the changing part of your command is at the beginning or the end of your command.

  • K => d10e10k # old L5R system

in game:
!6K4 => 6d10e10k4

The 6 is number of roll dice and the 4 is the number of kept dice. In this case we are lucky there are at the beginning and the end of the command.

As you see the order of command can help but in some cases it is simpler to use the second method.

# The second method - Regular expression

Regular expressions are a standardized way to find pattern in text.
Basically you can say: "If the command starts with a number, then it must be a W, after that another number following by a comma and at the end it must another number, in this case the macro is triggered.".
So regular expression allows you to make real complex pattern in order to make sure the substitution will take place in when it should.

Example:
!macro add ([0-9]+)W([0-9]+),([0-9]+) \1d10e[>\2]+\3 True
Usage:
!8W6,2 => 8d10e[>6]+2

As you see, in this case we have changing part at the beginning, at the end and in the middle (the 6).
In that case, it is important to use the regular expression method to replace \2 by the 6.

# In your case:
Let's define some of your macro with regular expression:

!macro add ^([0-9]+)s$  \1d10;1d10;$1c[>=$2];"DL $2 | rolls [@1] | successes $3" True

Then:
!3s => 3d10;1d10;$1c[>=$2];"DL $2 | rolls [@1] | successes $3"

## Won't work (I mean the substitution won't work but if the command is a valid one, it will run them)
!3s+2
!8d10s;"Sorted: @1"


!macro add ^(.*)o$ \1;$1i:[<=4]{" dodge failed"}{$1i:[5..7]{" weak dodge"}{$1i:[8..12]{" successful dodge"}{$1i:[>=13]{" critical dodge"}}}} False

Then:

  • !1d14+2o => 1d14;$1i:[<=4]{" dodge failed"}{$1i:[5..7]{" weak dodge"}{$1i:[8..12]{" successful dodge"}{$1i:[>=13]{" critical dodge"}}}}
  • !d14o => d10;$1i:[<=4]{" dodge failed"}{$1i:[5..7]{" weak dodge"}{$1i:[8..12]{" successful dodge"}{$1i:[>=13]{" critical dodge"}}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants