Skip to content

disgoorg/snowflake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.