Skip to content

Commit

Permalink
chore(Util): added common semi-constant pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesuaheli committed Jan 1, 2025
1 parent 6456a22 commit 3edec80
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
3 changes: 1 addition & 2 deletions modules/random/handleSubcommandDice.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ func (cmd subcommandDice) appCmd() *discordgo.ApplicationCommandOption {
}

func (cmd subcommandDice) optionRange() *discordgo.ApplicationCommandOption {
minValueTwo := float64(2)
return &discordgo.ApplicationCommandOption{
Type: discordgo.ApplicationCommandOptionInteger,
Name: lang.GetDefault(tp + "option.dice.option.range"),
NameLocalizations: *util.TranslateLocalization(tp + "option.dice.option.range"),
Description: lang.GetDefault(tp + "option.dice.option.range.description"),
DescriptionLocalizations: *util.TranslateLocalization(tp + "option.dice.option.range.description"),
Required: false,
MinValue: &minValueTwo,
MinValue: util.FloatTwo(),
}
}

Expand Down
6 changes: 2 additions & 4 deletions modules/random/handleSubcommandTeams.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,26 @@ func (cmd subcommandTeams) optionMembers() *discordgo.ApplicationCommandOption {
}

func (cmd subcommandTeams) optionTeamSize() *discordgo.ApplicationCommandOption {
minValueTwo := float64(2)
return &discordgo.ApplicationCommandOption{
Type: discordgo.ApplicationCommandOptionInteger,
Name: lang.GetDefault(tp + "option.teams.option.team_size"),
NameLocalizations: *util.TranslateLocalization(tp + "option.teams.option.team_size"),
Description: lang.GetDefault(tp + "option.teams.option.team_size.description"),
DescriptionLocalizations: *util.TranslateLocalization(tp + "option.teams.option.team_size.description"),
Required: false,
MinValue: &minValueTwo,
MinValue: util.FloatTwo(),
}
}

func (cmd subcommandTeams) optionTeamAmount() *discordgo.ApplicationCommandOption {
minValueOne := float64(1)
return &discordgo.ApplicationCommandOption{
Type: discordgo.ApplicationCommandOptionInteger,
Name: lang.GetDefault(tp + "option.teams.option.team_amount"),
NameLocalizations: *util.TranslateLocalization(tp + "option.teams.option.team_amount"),
Description: lang.GetDefault(tp + "option.teams.option.team_amount.description"),
DescriptionLocalizations: *util.TranslateLocalization(tp + "option.teams.option.team_amount.description"),
Required: false,
MinValue: &minValueOne,
MinValue: util.FloatOne(),
}
}

Expand Down
39 changes: 39 additions & 0 deletions util/universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import (

var log = logger.New("Util")

var (
constIntZero int64 = 0
constIntOne = constIntZero + 1
constIntTwo = constIntOne + 1
constFloatZero float64 = 0
constFloatOne = constFloatZero + 1
constFloatTwo = constFloatOne + 1
)

// ContainsInt reports whether at least one of num is at least once anywhere in i.
func ContainsInt(i []int, num ...int) bool {
for _, x := range i {
Expand Down Expand Up @@ -75,3 +84,33 @@ func ShiftL[T any](s []T, t ...T) (first T) {
}
return first
}

// IntZero returns a pointer to an [int64] with the value 0.
func IntZero() *int64 {
return &constIntZero
}

// IntOne returns a pointer to an [int64] with the value 1.
func IntOne() *int64 {
return &constIntOne
}

// IntTwo returns a pointer to an [int64] with the value 2.
func IntTwo() *int64 {
return &constIntTwo
}

// FloatZero returns a pointer to a [float64] with the value 0.
func FloatZero() *float64 {
return &constFloatZero
}

// FloatOne returns a pointer to a [float64] with the value 1.
func FloatOne() *float64 {
return &constFloatOne
}

// FloatTwo returns a pointer to a [float64] with the value 2.
func FloatTwo() *float64 {
return &constFloatTwo
}

0 comments on commit 3edec80

Please sign in to comment.