You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
858 B

package utils
import (
"math/rand"
"time"
"github.com/bwmarrin/discordgo"
)
// TruncateString UTF8 truncation of string to `i` length
func TruncateString(s string, i int) string {
runes := []rune(s)
if len(runes) > i {
return string(runes[:i])
}
return s
}
// SliceContainsChannelType looks for int value in a slice
func SliceContainsChannelType(s []discordgo.ChannelType, e discordgo.ChannelType) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
// SliceContainsString looks for int value in a slice
func SliceContainsString(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
// RandIdx returns a random number within the specified range.
func RandIdx(n int) uint {
if n == 0 {
return 0
}
rand.Seed(time.Now().UnixNano())
return uint(rand.Intn(n))
}