-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update roll command, added joinNumbers #58
Conversation
making it so you can do `!roll 2d6+10` and get `Bot: user rolled 12 from 2d6+10: (1, 1) + 10`
now with a test for the roll function @slugalisk shall i redo this without regex? or is this readable / strict enough? |
commands.go
Outdated
if strings.Contains(parts[1], "d") { | ||
parts := strings.Split(parts[1], "d") | ||
args = []string{parts[1], parts[0]} | ||
if math.MaxInt64/numDice <= numSides || numDice > 100 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
math.MaxInt64/numDice <= numSides
is meant to check whether or not this could cause integer overflow. we also need to factor in the modifier now
commands.go
Outdated
if len(parts) < 2 { | ||
return | ||
// Define a regular expression to extract dice rolling information | ||
regexPattern := `^!roll\s+(\d+)d(\d+)\s*([+\-]\s*\d+)?(.*?)$` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also support rolls
with an s
commands.go
Outdated
} | ||
|
||
var sum, _ = compute(m.Message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: sum, _ := ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit: need to check error here and return without responding to invalid input
commands_test.go
Outdated
@@ -20,3 +21,29 @@ func TestParseModifiers(t *testing.T) { | |||
} | |||
// fmt.Println(err.Error()) | |||
} | |||
|
|||
func TestCompute(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
commands.go
Outdated
if !strings.HasPrefix(m.Message, "!roll") { | ||
return | ||
} | ||
func compute(input string) (int, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call this computeRoll
or something more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 🚀
making it so you can do
!roll 2d6+10
and getBot: user rolled 12 from 2d6+10: (1, 1) + 10