Skip to content

Commit

Permalink
feat(Random): added reroll of dice
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesuaheli committed Dec 28, 2024
1 parent 233542a commit 313df3c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions modules/random/handleSubcommandDice.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"cake4everybot/util"
"fmt"
"math/rand/v2"
"strconv"

"github.com/bwmarrin/discordgo"
)
Expand Down Expand Up @@ -74,18 +75,33 @@ func (cmd subcommandDice) handle() {
if cmd.diceRange != nil {
diceRange = int(cmd.diceRange.IntValue())
}
cmd.ReplyComplex(cmd.roll(diceRange))
}

func (cmd subcommandDice) handleComponent(ids []string) {
switch id := util.ShiftL(ids); id {
case "reroll":
diceRange, _ := strconv.Atoi(util.ShiftL(ids))
cmd.ReplyComplexUpdate(cmd.roll(diceRange))
return
default:
log.Printf("Unknown component interaction ID in subcommand dice: %s %s", id, ids)
}
}

func (cmd subcommandDice) roll(diceRange int) (data *discordgo.InteractionResponseData) {
data = &discordgo.InteractionResponseData{}

diceResult := rand.IntN(diceRange) + 1
data.Embeds = util.SimpleEmbedf(0xFF7D00, lang.GetDefault(tp+"msg.dice.roll"), diceResult)

rerollButton := util.CreateButtonComponent(
fmt.Sprintf("random.dice.reroll.%d", diceRange),
"",
discordgo.PrimaryButton,
util.GetConfigComponentEmoji("random.dice.reroll"),
)
components := []discordgo.MessageComponent{discordgo.ActionsRow{Components: []discordgo.MessageComponent{rerollButton}}}
data.Components = []discordgo.MessageComponent{discordgo.ActionsRow{Components: []discordgo.MessageComponent{rerollButton}}}

cmd.ReplyComponentsSimpleEmbedf(components, 0xFF7D00, lang.GetDefault(tp+"msg.dice.roll"), diceResult)
}

func (cmd subcommandDice) handleComponent(ids []string) {
return data
}

0 comments on commit 313df3c

Please sign in to comment.