disgoorg / snowflake

Golang discord snowflake implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Reference Go Report Go Version License Disgo Version Disgo Discord

snowflake

snowflake is a golang library for parsing snowflake IDs from discord. This package provides a custom snowflake.ID type which has various utility methods for parsing discord snowflakes.

Installing

go get github.com/disgoorg/snowflake/v2

Usage

id := snowflake.ID(123456789012345678)

// deconstructs the snowflake ID into its components timestamp, worker ID, process ID, and increment
id.Deconstruct()

// the time.Time when the snowflake ID was generated
id.Time()

// the worker ID which the snowflake ID was generated
id.WorkerID()

// the process ID which the snowflake ID was generated
id.ProcessID()

// tje sequence when the snowflake ID was generated
id.Sequence()

// returns the string representation of the snowflake ID
id.String()

// returns a new snowflake ID with worker ID, process ID, and sequence set to 0
// this can be used for various pagination requests to the discord api
id := snowflake.New(time.Now())

// returns a snowflake ID from an environment variable
id := snowflake.GetEnv("guild_id")

// returns a snowflake ID from an environment variable and a bool indicating if the key was found
id, found := snowflake.LookupEnv("guild_id")

// returns the string as a snowflake ID or an error
id, err := snowflake.Parse("123456789012345678")

// returns the string as a snowflake ID or panics if an error occurs
id := snowflake.MustParse("123456789012345678")

License

Distributed under the License. See LICENSE for more information.

About

Golang discord snowflake implementation

License:Apache License 2.0


Languages

Language:Go 100.0%