From 938f4318c7dcd3754adc7d206c0e5376913200b9 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 21 Aug 2024 22:21:57 +0200 Subject: [PATCH 1/6] fix: $roll being 0-indexed --- internal/commands/roll/roll.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/commands/roll/roll.go b/internal/commands/roll/roll.go index 6cc78a2..4238660 100644 --- a/internal/commands/roll/roll.go +++ b/internal/commands/roll/roll.go @@ -32,9 +32,10 @@ func New() *Command { func (c *Command) Run(s *discordgo.Session, m *discordgo.MessageCreate, parts []string) pkg.CommandResult { if len(parts) >= 2 { number, err := strconv.Atoi(parts[1]) - if err == nil && number >= 1 { + if err == nil && number >= 2 { + v := 1 + rand.Intn(number-2) response := discordgo.MessageSend{ - Content: fmt.Sprintf("%s, %d", m.Author.Mention(), rand.Intn(number)), + Content: fmt.Sprintf("%s, %d", m.Author.Mention(), v), } s.ChannelMessageSendComplex(m.ChannelID, &response) } From f909da38717a25eb8705ccf98a54bbb728129015 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 21 Aug 2024 22:22:43 +0200 Subject: [PATCH 2/6] added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e70418..2a37752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2023-04-10 - Add basic support for slash commands. (#81) +- Fix: $roll is now 1-"indexed". (#139) ## Undated From 911fc7d8ca1489e44d9256d4c89e1f55bf739ee8 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 21 Aug 2024 22:27:14 +0200 Subject: [PATCH 3/6] xd --- internal/commands/roll/roll.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/roll/roll.go b/internal/commands/roll/roll.go index 4238660..324158c 100644 --- a/internal/commands/roll/roll.go +++ b/internal/commands/roll/roll.go @@ -33,7 +33,7 @@ func (c *Command) Run(s *discordgo.Session, m *discordgo.MessageCreate, parts [] if len(parts) >= 2 { number, err := strconv.Atoi(parts[1]) if err == nil && number >= 2 { - v := 1 + rand.Intn(number-2) + v := 1 + rand.Intn(number-1) response := discordgo.MessageSend{ Content: fmt.Sprintf("%s, %d", m.Author.Mention(), v), } From 221ed5ae098ce52913c397e25be878f4ad734b36 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 21 Aug 2024 22:28:16 +0200 Subject: [PATCH 4/6] change $roll to only have user cooldown --- internal/commands/roll/roll.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/roll/roll.go b/internal/commands/roll/roll.go index 324158c..7e25b59 100644 --- a/internal/commands/roll/roll.go +++ b/internal/commands/roll/roll.go @@ -40,7 +40,7 @@ func (c *Command) Run(s *discordgo.Session, m *discordgo.MessageCreate, parts [] s.ChannelMessageSendComplex(m.ChannelID, &response) } } - return pkg.CommandResultFullCooldown + return pkg.CommandResultUserCooldown } func (c *Command) Description() string { From c418f83d620fb5418f910f664efc5c0c06456fe7 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 21 Aug 2024 22:34:06 +0200 Subject: [PATCH 5/6] more xd --- internal/commands/roll/roll.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/commands/roll/roll.go b/internal/commands/roll/roll.go index 7e25b59..5179cb1 100644 --- a/internal/commands/roll/roll.go +++ b/internal/commands/roll/roll.go @@ -32,8 +32,8 @@ func New() *Command { func (c *Command) Run(s *discordgo.Session, m *discordgo.MessageCreate, parts []string) pkg.CommandResult { if len(parts) >= 2 { number, err := strconv.Atoi(parts[1]) - if err == nil && number >= 2 { - v := 1 + rand.Intn(number-1) + if err == nil && number >= 1 { + v := 1 + rand.Intn(number) response := discordgo.MessageSend{ Content: fmt.Sprintf("%s, %d", m.Author.Mention(), v), } From 7123336a00550aece53bdbf9ee8f61aade8eddfa Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 21 Aug 2024 22:36:11 +0200 Subject: [PATCH 6/6] use reply --- internal/commands/roll/roll.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/commands/roll/roll.go b/internal/commands/roll/roll.go index 5179cb1..ac2b634 100644 --- a/internal/commands/roll/roll.go +++ b/internal/commands/roll/roll.go @@ -9,6 +9,7 @@ import ( "github.com/pajbot/basecommand" "github.com/pajbot/pajbot2-discord/pkg" "github.com/pajbot/pajbot2-discord/pkg/commands" + "github.com/pajbot/pajbot2-discord/pkg/utils" ) var _ pkg.Command = &Command{} @@ -34,10 +35,8 @@ func (c *Command) Run(s *discordgo.Session, m *discordgo.MessageCreate, parts [] number, err := strconv.Atoi(parts[1]) if err == nil && number >= 1 { v := 1 + rand.Intn(number) - response := discordgo.MessageSend{ - Content: fmt.Sprintf("%s, %d", m.Author.Mention(), v), - } - s.ChannelMessageSendComplex(m.ChannelID, &response) + response := fmt.Sprintf("%d", v) + utils.Reply(s, m, response) } } return pkg.CommandResultUserCooldown