util

package
v0.0.0-...-d3fc29d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChannelTagPattern = regexp.MustCompile("<#([0-9]{18})>")
View Source
var UserTagPattern = regexp.MustCompile("<@!([0-9]{18})>")

Functions

func AppendUnique

func AppendUnique(list []string, s string) []string

func BuildChannelTag

func BuildChannelTag(cid string) string

Returns the discord channel tag for channel with ID cid

func BuildUserTag

func BuildUserTag(uid string) string

Returns the discord user tag for user with ID uid

func Contains

func Contains(list []string, s string) bool

func CreationTime

func CreationTime(ID string) (t time.Time, err error)

CreationTime returns the creation time of a Snowflake ID relative to the creation of Discord. Taken from https://github.com/Moonlington/FloSelfbot/blob/master/commands/commandutils.go#L117

func Index

func Index(list []string, s string) int

Returns the first found index of s in list, else -1

func IsUserInServer

func IsUserInServer(s *DG.Session, gid, uid string) bool

Return true if the user uid is a member of the server gid

func IsValidChannel

func IsValidChannel(s *DG.Session, gid, cid string) bool

Return true if cid is a valid channel in the guild identifed by gid

func Max

func Max(arr []int) int

func MemberName

func MemberName(m *DG.Member) string

func Remove

func Remove(list []string, s string) []string

func StripChannelTag

func StripChannelTag(cid string) (string, bool)

Return true and the channel ID if the input string matched the channel tag format

func StripUserTag

func StripUserTag(uid string) (string, bool)

Return true and the user ID if the input string matched the user tag format

func Timestamp

func Timestamp(t time.Time) string

Returns the discord user tag for user with ID uid

func ToHashMap

func ToHashMap[T comparable](arr []T) map[T]bool

func ToSlice

func ToSlice[T any](dict map[string]T) []T

Types

type RNG

type RNG struct {
	*rand.Rand
}

func NewRNG

func NewRNG() RNG

NewRNG returns a new Random Number Generator

func (RNG) PercentChance

func (r RNG) PercentChance(rate int) bool

PercentChance generates a random number generator, and returns true if it is strictly inferior to 100. In other terms, it randomizes a `Rate%` probability.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL