webhook

package
v2.0.0-...-d0e310c Latest Latest
Warning

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

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

Documentation

Overview

Package webhook provides support for PluralKit's dispatch webhooks.

Index

Constants

View Source
const ErrInvalidToken = errors.Sentinel("payload token doesn't match")

Variables

View Source
var EventCreators = map[DispatchEventType]func() Event{
	PingEventType:              func() Event { return new(PingEventData) },
	CreateSwitchEventType:      func() Event { return new(CreateSwitchEventData) },
	UpdateSystemEventType:      func() Event { return new(UpdateSystemEventData) },
	UpdateSettingsEventType:    func() Event { return new(UpdateSettingsEventData) },
	CreateMemberEventType:      func() Event { return new(CreateMemberEventData) },
	UpdateMemberEventType:      func() Event { return new(UpdateMemberEventData) },
	DeleteMemberEventType:      func() Event { return new(DeleteMemberEventData) },
	CreateGroupEventType:       func() Event { return new(CreateGroupEventData) },
	UpdateGroupEventType:       func() Event { return new(UpdateGroupEventData) },
	DeleteGroupEventType:       func() Event { return new(DeleteGroupEventData) },
	LinkAccountEventType:       func() Event { return new(LinkAccountEventData) },
	UnlinkAccountEventType:     func() Event { return new(UnlinkAccountEventData) },
	UpdateSystemGuildEventType: func() Event { return new(UpdateSystemGuildEventData) },
	UpdateMemberGuildEventType: func() Event { return new(UpdateMemberGuildEventData) },
	CreateMessageEventType:     func() Event { return new(CreateMessageEventData) },
	UpdateSwitchEventType:      func() Event { return new(UpdateSwitchEventData) },
	DeleteSwitchEventType:      func() Event { return new(DeleteSwitchEventData) },
	DeleteAllSwitchesEventType: func() Event { return new(DeleteAllSwitchesEventData) },
	SuccessfulImportEventType:  func() Event { return new(SuccessfulImportEventData) },
}

EventCreators are funcs used to create Event structs to unmarshal to.

Functions

This section is empty.

Types

type CreateGroupEventData

type CreateGroupEventData struct {
	Name string `json:"name"`
}

func (*CreateGroupEventData) Type

type CreateMemberEventData

type CreateMemberEventData struct {
	Name string `json:"name"`
}

func (*CreateMemberEventData) Type

type CreateMessageEventData

type CreateMessageEventData struct {
	pkgo.Message
}

func (*CreateMessageEventData) Type

type CreateSwitchEventData

type CreateSwitchEventData struct {
	pkgo.Switch
}

func (*CreateSwitchEventData) Type

type DeleteAllSwitchesEventData

type DeleteAllSwitchesEventData struct{}

func (*DeleteAllSwitchesEventData) Type

type DeleteGroupEventData

type DeleteGroupEventData struct{}

func (*DeleteGroupEventData) Type

type DeleteMemberEventData

type DeleteMemberEventData struct{}

func (*DeleteMemberEventData) Type

type DeleteSwitchEventData

type DeleteSwitchEventData struct{}

func (*DeleteSwitchEventData) Type

type DispatchEventType

type DispatchEventType string
const (
	UnknownEventType        DispatchEventType = ""
	PingEventType           DispatchEventType = "PING"
	UpdateSystemEventType   DispatchEventType = "UPDATE_SYSTEM"
	UpdateSettingsEventType DispatchEventType = "UPDATE_SETTINGS"

	CreateMemberEventType DispatchEventType = "CREATE_MEMBER"
	UpdateMemberEventType DispatchEventType = "UPDATE_MEMBER"
	DeleteMemberEventType DispatchEventType = "DELETE_MEMBER"

	CreateGroupEventType        DispatchEventType = "CREATE_GROUP"
	UpdateGroupEventType        DispatchEventType = "UPDATE_GROUP"
	UpdateGroupMembersEventType DispatchEventType = "UPDATE_GROUP_MEMBERS"
	DeleteGroupEventType        DispatchEventType = "DELETE_GROUP"

	LinkAccountEventType   DispatchEventType = "LINK_ACCOUNT"
	UnlinkAccountEventType DispatchEventType = "UNLINK_ACCOUNT"

	UpdateSystemGuildEventType DispatchEventType = "UPDATE_SYSTEM_GUILD"
	UpdateMemberGuildEventType DispatchEventType = "UPDATE_MEMBER_GUILD"

	CreateMessageEventType DispatchEventType = "CREATE_MESSAGE"

	CreateSwitchEventType        DispatchEventType = "CREATE_SWITCH"
	UpdateSwitchEventType        DispatchEventType = "UPDATE_SWITCH"
	UpdateSwitchMembersEventType DispatchEventType = "UPDATE_SWITCH_MEMBERS"
	DeleteSwitchEventType        DispatchEventType = "DELETE_SWITCH"
	DeleteAllSwitchesEventType   DispatchEventType = "DELETE_ALL_SWITCHES"

	SuccessfulImportEventType DispatchEventType = "SUCCESSFUL_IMPORT"
)

type Event

type Event interface {
	Type() DispatchEventType
}

type LinkAccountEventData

type LinkAccountEventData struct{}

func (*LinkAccountEventData) Type

type PingEventData

type PingEventData struct{}

func (*PingEventData) Type

type SuccessfulImportEventData

type SuccessfulImportEventData struct{}

func (*SuccessfulImportEventData) Type

type TokenGetter

type TokenGetter func(systemID uuid.UUID) (string, error)

TokenGetter is a function used to get a signing token for the given system ID. If it returns an error, unmarshaling is aborted.

type UnknownEventData

type UnknownEventData struct {
	json.RawMessage
}

func (*UnknownEventData) Type

type UnlinkAccountEventData

type UnlinkAccountEventData struct{}

func (*UnlinkAccountEventData) Type

type UpdateGroupEventData

type UpdateGroupEventData struct {
	Name        *string     `json:"name,omitempty"`
	DisplayName *string     `json:"display_name,omitempty"`
	Description *string     `json:"description,omitempty"`
	Icon        *string     `json:"icon,omitempty"`
	Banner      *string     `json:"banner,omitempty"`
	Color       *pkgo.Color `json:"color,omitempty"`

	Privacy *pkgo.GroupPrivacy `json:"privacy,omitempty"`
}

func (*UpdateGroupEventData) Type

type UpdateMemberEventData

type UpdateMemberEventData struct {
	Name        *string        `json:"name,omitempty"`
	DisplayName *string        `json:"display_name,omitempty"`
	Color       *pkgo.Color    `json:"color,omitempty"`
	Birthday    *pkgo.Birthday `json:"birthday,omitempty"`
	Pronouns    *string        `json:"pronouns,omitempty"`
	AvatarURL   *string        `json:"avatar_url,omitempty"`
	Banner      *string        `json:"banner,omitempty"`
	Description *string        `json:"description,omitempty"`

	ProxyTags *[]pkgo.ProxyTag `json:"proxy_tags,omitempty"`
	KeepProxy *bool            `json:"keep_proxy"`

	Privacy *pkgo.MemberPrivacy `json:"privacy,omitempty"`
}

func (*UpdateMemberEventData) Type

type UpdateMemberGuildEventData

type UpdateMemberGuildEventData struct {
	GuildID     pkgo.Snowflake `json:"guild_id"`
	DisplayName *string        `json:"display_name,omitempty"`
	AvatarURL   *string        `json:"avatar_url,omitempty"`
}

func (*UpdateMemberGuildEventData) Type

type UpdateSettingsEventData

type UpdateSettingsEventData struct {
	Timezone     *string `json:"timezone,omitempty"`
	PingsEnabled *bool   `json:"pings_enabled,omitempty"`
	LatchTimeout *int    `json:"latch_timeout,omitempty"`

	MemberDefaultPrivate *bool `json:"member_default_private,omitempty"`
	GroupDefaultPrivate  *bool `json:"group_default_private,omitempty"`
	ShowPrivateInfo      *bool `json:"show_private_info,omitempty"`

	MemberLimit *int `json:"member_limit,omitempty"`
	GroupLimit  *int `json:"group_limit,omitempty"`
}

func (*UpdateSettingsEventData) Type

type UpdateSwitchEventData

type UpdateSwitchEventData struct {
	Timestamp *time.Time `json:"timestamp,omitempty"`
	Members   *[]string  `json:"members,omitempty"`
}

func (*UpdateSwitchEventData) Type

type UpdateSystemEventData

type UpdateSystemEventData struct {
	Name        *string             `json:"name,omitempty"`
	Description *string             `json:"description,omitempty"`
	Tag         *string             `json:"tag,omitempty"`
	AvatarURL   *string             `json:"avatar_url,omitempty"`
	Banner      *string             `json:"banner,omitempty"`
	Color       *string             `json:"color,omitempty"`
	Privacy     *pkgo.SystemPrivacy `json:"privacy,omitempty"`
}

func (*UpdateSystemEventData) Type

type UpdateSystemGuildEventData

type UpdateSystemGuildEventData struct {
	GuildID         pkgo.Snowflake      `json:"guild_id"`
	ProxyingEnabled *bool               `json:"proxying_enabled,omitempty"`
	AutoproxyMode   *pkgo.AutoproxyMode `json:"autoproxy_mode,omitempty"`
	AutoproxyMember *string             `json:"autoproxy_member,omitempty"`
	Tag             *string             `json:"tag,omitempty"`
	TagEnabled      *bool               `json:"tag_enabled,omitempty"`
}

func (*UpdateSystemGuildEventData) Type

type WebhookEvent

type WebhookEvent struct {
	Type  DispatchEventType `json:"type"`
	Token string            `json:"signing_token"`

	SystemID uuid.UUID      `json:"system_id"`
	EntityID string         `json:"id,omitempty"`
	GuildID  pkgo.Snowflake `json:"guild_id,omitempty"`

	// Raw is the raw JSON data.
	Raw json.RawMessage `json:"data"`

	// Data is the unmarshalled dispatch event payload.
	// Type assertions should be made on this value.
	// All types in this value are *pointer* types.
	// Unknown events are unmarshalled as UnknownEventPayload
	Data Event `json:"-"`
}

func Decode

func Decode(r io.Reader, tkn TokenGetter) (ev WebhookEvent, err error)

Unmarshal unmarshals the given io.Reader to a WebhookEvent, and also validates the token if tkn is not nil. If the token returned by tkn is empty, the event is *not* validated.

func Unmarshal

func Unmarshal(src []byte, tkn TokenGetter) (ev WebhookEvent, err error)

Unmarshal unmarshals the given byte slice to a WebhookEvent, and also validates the token if tkn is not nil. If the token returned by tkn is empty, the event is *not* validated.

func (WebhookEvent) Snowflake

func (ev WebhookEvent) Snowflake() (pkgo.Snowflake, error)

Snowflake tries parsing the event's entity ID into an account ID

func (WebhookEvent) UUID

func (ev WebhookEvent) UUID() (uuid.UUID, error)

UUID tries parsing the event's entity ID into a UUID

Jump to

Keyboard shortcuts

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