mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-12-04 04:42:48 +00:00
54cadd2f45
This commit refactors the whole package gateway as well as utils/ws (formerly utils/wsutil) and voice/voicegateway. The new refactor utilizes a design pattern involving a concurrent loop and an arriving event channel. An additional change was made to the way gateway events are typed. Before, pretty much any type will satisfy a gateway event type, since the actual type was just interface{}. The new refactor defines a concrete interface that events can implement: type Event interface { Op() OpCode EventType() EventType } Using this interface, the user can easily add custom gateway events independently of the library without relying on string maps. This adds a lot of type safety into the library and makes type-switching on Event types much more reasonable. Gateway error callbacks are also almost entirely removed in favor of custom gateway events. A catch-all can easily be added like this: s.AddHandler(func(err error) { log.Println("gateway error:, err") })
39 lines
1.5 KiB
Cheetah
39 lines
1.5 KiB
Cheetah
// Code generated by gensnowflake. DO NOT EDIT.
|
|
|
|
package {{ .Package }}
|
|
|
|
{{ $dot := "" }}
|
|
|
|
{{ if .ImportDiscord }}
|
|
{{ $dot = "discord." }}
|
|
import "github.com/diamondburned/arikawa/v3/discord"
|
|
{{ end }}
|
|
|
|
import "time"
|
|
|
|
{{ range .Snowflakes }}
|
|
|
|
// {{ .TypeName }} is the snowflake type for a {{ .TypeName }}.
|
|
type {{.TypeName}} {{$dot}}Snowflake
|
|
|
|
// Null{{.TypeName}} gets encoded into a null. This is used for optional and nullable snowflake fields.
|
|
const Null{{.TypeName}} = {{.TypeName}}({{$dot}}NullSnowflake)
|
|
|
|
func (s {{.TypeName}}) MarshalJSON() ([]byte, error) { return {{$dot}}Snowflake(s).MarshalJSON() }
|
|
func (s *{{.TypeName}}) UnmarshalJSON(v []byte) error { return (*{{$dot}}Snowflake)(s).UnmarshalJSON(v) }
|
|
|
|
// String returns the ID, or nothing if the snowflake isn't valid.
|
|
func (s {{.TypeName}}) String() string { return {{$dot}}Snowflake(s).String() }
|
|
|
|
// IsValid returns whether or not the snowflake is valid.
|
|
func (s {{.TypeName}}) IsValid() bool { return {{$dot}}Snowflake(s).IsValid() }
|
|
|
|
// IsNull returns whether or not the snowflake is null.
|
|
func (s {{.TypeName}}) IsNull() bool { return {{$dot}}Snowflake(s).IsNull() }
|
|
|
|
func (s {{.TypeName}}) Time() time.Time { return {{$dot}}Snowflake(s).Time() }
|
|
func (s {{.TypeName}}) Worker() uint8 { return {{$dot}}Snowflake(s).Worker() }
|
|
func (s {{.TypeName}}) PID() uint8 { return {{$dot}}Snowflake(s).PID() }
|
|
func (s {{.TypeName}}) Increment() uint16 { return {{$dot}}Snowflake(s).Increment() }
|
|
{{ end }}
|