From 826ac3292f0087c7242bae0156893f93276abda4 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Wed, 27 Jul 2022 23:42:27 -0500 Subject: [PATCH] create util.go --- command/random.go | 33 --------------------------------- command/time.go | 4 ---- command/util.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 command/util.go diff --git a/command/random.go b/command/random.go index de4b0b2..85f840a 100644 --- a/command/random.go +++ b/command/random.go @@ -3,7 +3,6 @@ package command import ( "errors" "fmt" - "math/rand" "regexp" "strconv" "strings" @@ -227,35 +226,3 @@ func (h *CoinHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) { s.ChannelMessageSend(m.ChannelID, msg) } - -func RandInt(min int, max int) int { - return rand.Intn(max-min+1) + min -} - -func JoinInt(a []int, sep string) string { - var b []string - - b = make([]string, len(a)) - - for i, v := range a { - b[i] = strconv.Itoa(v) - } - - return strings.Join(b, sep) -} - -func SumInt(a []int) int { - var sum int - for _, v := range a { - sum += v - } - return sum -} - -func Itob(v int) bool { - if v == 1 { - return true - } - - return false -} diff --git a/command/time.go b/command/time.go index 312ed16..d4ec7b0 100644 --- a/command/time.go +++ b/command/time.go @@ -9,10 +9,6 @@ import ( log "github.com/sirupsen/logrus" ) -const () - -var () - type ( TimeHandler struct{} ) diff --git a/command/util.go b/command/util.go new file mode 100644 index 0000000..57ac981 --- /dev/null +++ b/command/util.go @@ -0,0 +1,47 @@ +package command + +import ( + "math/rand" + "net/url" + "path" + "strconv" + "strings" +) + +func RandInt(min int, max int) int { + return rand.Intn(max-min+1) + min +} + +func JoinInt(a []int, sep string) string { + var b []string + + b = make([]string, len(a)) + + for i, v := range a { + b[i] = strconv.Itoa(v) + } + + return strings.Join(b, sep) +} + +func SumInt(a []int) int { + var sum int + for _, v := range a { + sum += v + } + return sum +} + +func Itob(v int) bool { + if v == 1 { + return true + } + + return false +} + +func BuildURI(rawuri, rawpath string) string { + u, _ := url.Parse(rawuri) + u.Path = path.Join(u.Path, rawpath) + return u.String() +}