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

Update roll command, added joinNumbers #58

Merged
merged 15 commits into from
Nov 12, 2023
Merged

Conversation

real-salad
Copy link
Contributor

making it so you can do !roll 2d6+10 and get Bot: user rolled 12 from 2d6+10: (1, 1) + 10

making it so you can do `!roll 2d6+10` and get `Bot: user rolled 12 from 2d6+10: (1, 1) + 10`
@real-salad
Copy link
Contributor Author

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 {
Copy link
Member

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+)?(.*?)$`
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sum, _ := ...

Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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?

Copy link
Member

@slugalisk slugalisk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 🚀

@slugalisk slugalisk merged commit 7ff4265 into MemeLabs:master Nov 12, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants