create util.go

This commit is contained in:
Ryan Cavicchioni 2022-07-27 23:42:27 -05:00
parent 85b2e2b99b
commit 826ac3292f
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
3 changed files with 47 additions and 37 deletions

View File

@ -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
}

View File

@ -9,10 +9,6 @@ import (
log "github.com/sirupsen/logrus"
)
const ()
var ()
type (
TimeHandler struct{}
)

47
command/util.go Normal file
View File

@ -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()
}