utils

package
v0.0.0-...-e2e6f4c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReadLimitReached = errors.New("Read limit reached")

Functions

func AZ_09

func AZ_09(s string) bool

AZ_09 checks if all characters in a string are [a-zA-Z0-9_]

func AddPrefix

func AddPrefix(s, pfx string) string

AddPrefix adds pfx at the start of s, if s does not already start with pfx.

func Arg

func Arg(s []string, i int) string

Arg safely returns index i of a string array.

func Display

func Display(login, display string) string

func Elapsed

func Elapsed(t time.Duration) string

Elapsed returns a human-readable duration string where readability is more important than being precise.

func ElapsedAgo

func ElapsedAgo(t time.Time) string

ElapsedAgo returns either a timestring with " ago" suffix or "on " followed by a date.

func ElapsedSeconds

func ElapsedSeconds(t int64) string

func Field

func Field(s string, f byte, n int) string

Field returns the n'th field of s, separated by f. Returns empty string if the field does not exist.

func FormatElapsedAgo

func FormatElapsedAgo(s string) string

func IsSmallUnum

func IsSmallUnum(s string) bool

IsSmallUnum returns whether is a small unsigned integer.

func IsUnsigned

func IsUnsigned(s string) bool

func NoBing

func NoBing(s string) string

func Nonce

func Nonce() string

func OwnAddress

func OwnAddress() string

OwnAddress attempts to determine a local address used for internal communication. Should probably be replaced with "ip route get" for the relevant remote party.

func Ratio

func Ratio(msg string) float64

func StripHTML

func StripHTML(v string) string

func Trailer

func Trailer(s string, f byte, n int) string

Trailer returns the remaining strings after the first n f-delimited fields.

func TrimRight

func TrimRight(s string) string

TrimRight removes characters that are commonly used to bypass Twitch duplicate message detection.

func WithTimeout

func WithTimeout(ctx context.Context) (context.Context, context.CancelFunc)

WithTimeout returns a context with a small timeout, appropriate for command handling.

Types

type LimitReader

type LimitReader struct {
	N int64
	R io.Reader
}

LimitReader is used to enforce read limits.

func (*LimitReader) Read

func (lr *LimitReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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