add helpers for privileges and random numbers

This commit is contained in:
lyx0 2022-08-07 21:43:09 +02:00
parent cfb320b017
commit c327491925
2 changed files with 64 additions and 0 deletions

26
pkg/common/privs.go Normal file
View file

@ -0,0 +1,26 @@
package common
import "github.com/gempir/go-twitch-irc/v3"
// ElevatedPrivsMessage is checking a given message twitch.PrivateMessage
// if it came from a moderator/vip/or broadcaster and returns a bool
func ElevatedPrivsMessage(message twitch.PrivateMessage) bool {
if message.User.Badges["moderator"] == 1 ||
message.User.Badges["vip"] == 1 ||
message.User.Badges["broadcaster"] == 1 {
return true
} else {
return false
}
}
// ModPrivsMessage is checking a given message twitch.PrivateMessage
// if it came from a moderator or broadcaster and returns a bool
func ModPrivsMessage(message twitch.PrivateMessage) bool {
if message.User.Badges["moderator"] == 1 ||
message.User.Badges["broadcaster"] == 1 {
return true
} else {
return false
}
}

38
pkg/common/random.go Normal file
View file

@ -0,0 +1,38 @@
package common
import (
"fmt"
"math/rand"
"strconv"
"time"
)
// StrGenerateRandomNumber generates a random number from
// a given max value as a string
func StrGenerateRandomNumber(max string) int {
num, err := strconv.Atoi(max)
if num < 1 {
return 0
}
if err != nil {
fmt.Printf("Supplied value %v is not a number", num)
return 0
} else {
rand.Seed(time.Now().UnixNano())
return rand.Intn(num)
}
}
// GenerateRandomNumber returns a random number from
// a given max value as a int
func GenerateRandomNumber(max int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(max)
}
// GenerateRandomNumberRange returns a random number
// over a given minimum and maximum range.
func GenerateRandomNumberRange(min int, max int) int {
return (rand.Intn(max-min) + min)
}