From 3edec805bba975b349cbe1b6639884f48875a687 Mon Sep 17 00:00:00 2001 From: Kesuaheli Date: Wed, 1 Jan 2025 19:31:52 +0100 Subject: [PATCH] chore(Util): added common semi-constant pointers --- modules/random/handleSubcommandDice.go | 3 +- modules/random/handleSubcommandTeams.go | 6 ++-- util/universal.go | 39 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/modules/random/handleSubcommandDice.go b/modules/random/handleSubcommandDice.go index dcf7d4b..d917eae 100644 --- a/modules/random/handleSubcommandDice.go +++ b/modules/random/handleSubcommandDice.go @@ -53,7 +53,6 @@ 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"), @@ -61,7 +60,7 @@ func (cmd subcommandDice) optionRange() *discordgo.ApplicationCommandOption { 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(), } } diff --git a/modules/random/handleSubcommandTeams.go b/modules/random/handleSubcommandTeams.go index 4cc63ae..da85c26 100644 --- a/modules/random/handleSubcommandTeams.go +++ b/modules/random/handleSubcommandTeams.go @@ -69,7 +69,6 @@ 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"), @@ -77,12 +76,11 @@ func (cmd subcommandTeams) optionTeamSize() *discordgo.ApplicationCommandOption 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"), @@ -90,7 +88,7 @@ func (cmd subcommandTeams) optionTeamAmount() *discordgo.ApplicationCommandOptio 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(), } } diff --git a/util/universal.go b/util/universal.go index 8904c6e..14b01e0 100644 --- a/util/universal.go +++ b/util/universal.go @@ -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 { @@ -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 +}