towerdiscord

package module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowedMentions

type AllowedMentions struct {
	Parse []string
	Roles []snowflake.ID
	Users []snowflake.ID
}

type Attachment

type Attachment struct {
	ID          int    `json:"id"`
	Filename    string `json:"filename,omitempty"`
	Description string `json:"description,omitempty"`
	ContentType string `json:"content_type,omitempty"`
	Size        int    `json:"size,omitempty"`
	URL         string `json:"url,omitempty"`
	ProxyURL    string `json:"proxy_url,omitempty"`
	Height      int    `json:"height,omitempty"`
	Width       int    `json:"width,omitempty"`
	Ephemeral   bool   `json:"ephemeral,omitempty"`
}

type Auth

type Auth struct {
	Type  string
	Token string
}

type Client

type Client interface {
	Do(*http.Request) (*http.Response, error)
}

type CodeBlockBuilder

type CodeBlockBuilder interface {
	Build(w io.Writer, value []any) error
	BuildError(w io.Writer, err error) error
}

type DataEncoder

type DataEncoder interface {
	ContentType() string
	Encode(w io.Writer, value any) error
	FileExtension() string
}

type Discord

type Discord struct {
	// contains filtered or unexported fields
}

func NewDiscordBot

func NewDiscordBot(webhook string, opts ...DiscordOption) *Discord

NewDiscordBot creates a new discord bot.

func (Discord) Name

func (d Discord) Name() string

Name implements tower.Messenger interface.

func (Discord) PostWebhookJSON

func (d Discord) PostWebhookJSON(ctx context.Context, web *WebhookContext) error

func (Discord) PostWebhookMultipart

func (d Discord) PostWebhookMultipart(ctx context.Context, web *WebhookContext) error

func (Discord) SendMessage

func (d Discord) SendMessage(ctx context.Context, msg tower.MessageContext)

SendMessage implements tower.Messenger interface.

func (Discord) Wait

func (d Discord) Wait(ctx context.Context) error

Wait implements tower.Messenger interface.

type DiscordErrorResponse

type DiscordErrorResponse struct {
	Code       int             `json:"code"`
	Message    string          `json:"message"`
	StatusCode int             `json:"status_code"`
	Raw        json.RawMessage `json:"raw"`
}

func (DiscordErrorResponse) Error

func (d DiscordErrorResponse) Error() string

func (DiscordErrorResponse) PrintJSON

func (d DiscordErrorResponse) PrintJSON()

func (DiscordErrorResponse) String

func (d DiscordErrorResponse) String() string

type DiscordOption added in v0.6.1

type DiscordOption interface {
	// contains filtered or unexported methods
}

func WithBucket added in v0.6.1

func WithBucket(bucket bucket.Bucket) DiscordOption

func WithCache added in v0.6.1

func WithCache(cache cache.Cacher) DiscordOption

WithCache sets the cache engine.

func WithClient added in v0.6.1

func WithClient(client Client) DiscordOption

func WithCodeBlockBuilder added in v0.6.1

func WithCodeBlockBuilder(codeBlockBuilder CodeBlockBuilder) DiscordOption

func WithCooldown added in v0.6.1

func WithCooldown(cooldown time.Duration) DiscordOption

func WithDataEncoder added in v0.6.1

func WithDataEncoder(dataEncoder DataEncoder) DiscordOption

func WithEmbedBuilder added in v0.6.1

func WithEmbedBuilder(builder EmbedBuilder) DiscordOption

func WithGlobalKey added in v0.6.1

func WithGlobalKey(key string) DiscordOption

func WithHook added in v0.6.1

func WithHook(hook Hook) DiscordOption

func WithName added in v0.6.1

func WithName(name string) DiscordOption

WithName sets the name of this messenger.

func WithSemaphore added in v0.6.1

func WithSemaphore(sem chan struct{}) DiscordOption

WithSemaphore sets the number of concurrent workers.

func WithTrace added in v0.6.1

func WithTrace(trace tower.TraceCapturer) DiscordOption

WithTrace sets the tracer.

type Embed

type Embed struct {
	// Title of embed.
	Title string `json:"title,omitempty"`
	// Type of embed (always "rich" for webhook embeds).
	Type string `json:"type,omitempty"`
	// Description of embed.
	Description string `json:"description,omitempty"`
	// URL of embed.
	Url string `json:"url,omitempty"`
	// Timestamp of embed content.
	Timestamp string `json:"timestamp,omitempty"`
	// Color code of the embed.
	Color int `json:"color,omitempty"`
	// Footer information.
	Footer *EmbedFooter `json:"footer,omitempty"`
	// Image information.
	Image *EmbedImage `json:"image,omitempty"`
	// Thumbnail information.
	Thumbnail *EmbedThumbnail `json:"thumbnail,omitempty"`
	// Video information.
	Video *EmbedVideo `json:"video,omitempty"`
	// Provider information.
	Provider *EmbedProvider `json:"provider,omitempty"`
	// Author information.
	Author *EmbedAuthor `json:"author,omitempty"`
	// Fields information.
	Fields []*EmbedField `json:"fields,omitempty"`
}

type EmbedAuthor

type EmbedAuthor struct {
	// Name of author.
	Name string `json:"name,omitempty"`
	// URL of author.
	Url string `json:"url,omitempty"`
	// URL of author icon (only supports http(s) and attachments).
	IconUrl string `json:"icon_url,omitempty"`
	// A proxied url of author icon.
	ProxyIconUrl string `json:"proxy_icon_url,omitempty"`
}

type EmbedBuilder

type EmbedBuilder interface {
	BuildEmbed(ctx context.Context, msg tower.MessageContext, info *ExtraInformation) ([]*Embed, []bucket.File)
}

type EmbedBuilderFunc

type EmbedBuilderFunc func(ctx context.Context, msg tower.MessageContext, info *ExtraInformation) ([]*Embed, []bucket.File)

func (EmbedBuilderFunc) BuildEmbed

func (e EmbedBuilderFunc) BuildEmbed(ctx context.Context, msg tower.MessageContext, info *ExtraInformation) ([]*Embed, []bucket.File)

type EmbedField

type EmbedField struct {
	// Name of the field.
	Name string `json:"name"`
	// Value of the field.
	Value string `json:"value"`
	// Inline states Whether this field should display inline.
	Inline bool `json:"inline,omitempty"`
}

type EmbedFooter

type EmbedFooter struct {
	// Footer text.
	Text string `json:"text"`
	// URL of footer icon (only supports http(s) and attachments).
	IconUrl string `json:"icon_url,omitempty"`
	// A proxied url of footer icon.
	ProxyIconUrl string `json:"proxy_icon_url,omitempty"`
}

type EmbedImage

type EmbedImage struct {
	// Source url of image (only supports http(s) and attachments).
	Url string `json:"url,omitempty"`
	// A proxied url of the image.
	ProxyUrl string `json:"proxy_url,omitempty"`
	// Height of image.
	Height int `json:"height,omitempty"`
	// Width of image.
	Width int `json:"width,omitempty"`
}

type EmbedProvider

type EmbedProvider struct {
	// Name of provider.
	Name string `json:"name,omitempty"`
	// URL of provider.
	Url string `json:"url,omitempty"`
}

type EmbedThumbnail

type EmbedThumbnail struct {
	// Source url of thumbnail (only supports http(s) and attachments).
	Url string `json:"url,omitempty"`
	// A proxied url of the thumbnail.
	ProxyUrl string `json:"proxy_url,omitempty"`
	// Height of thumbnail.
	Height int `json:"height,omitempty"`
	// Width of thumbnail.
	Width int `json:"width,omitempty"`
}

type EmbedVideo

type EmbedVideo struct {
	// Source url of video.
	Url string `json:"url,omitempty"`
	// A proxied url of the video.
	ProxyUrl string `json:"proxy_url,omitempty"`
	// Height of video.
	Height int `json:"height,omitempty"`
	// Width of video.
	Width int `json:"width,omitempty"`
}

type ExtraInformation

type ExtraInformation struct {
	Iteration        int
	CooldownTimeEnds time.Time
	CacheKey         string
	ThreadID         snowflake.ID
}

type HTTPErrorResponse

type HTTPErrorResponse struct {
	Code    int             `json:"code"`
	Errors  json.RawMessage `json:"errors"`
	Message string          `json:"message"`
}

type HighlightHint

type HighlightHint interface {
	DiscordHighlight() string
}

type Hook

type Hook interface {
	PreMessageHook(ctx context.Context, web *WebhookContext) context.Context
	PostMessageHook(ctx context.Context, web *WebhookContext, err error)
	PreBucketUploadHook(ctx context.Context, web *WebhookContext) context.Context
	PostBucketUploadHook(ctx context.Context, web *WebhookContext, results []bucket.UploadResult)
}

type ImageSizeHint

type ImageSizeHint interface {
	ImageSize() (height, width int)
}

type JSONCodeBlockBuilder

type JSONCodeBlockBuilder struct{}

func (JSONCodeBlockBuilder) Build

func (J JSONCodeBlockBuilder) Build(w io.Writer, value []any) error

func (JSONCodeBlockBuilder) BuildError

func (J JSONCodeBlockBuilder) BuildError(w io.Writer, e error) error

type JSONDataEncoder

type JSONDataEncoder struct{}

func (JSONDataEncoder) ContentType

func (J JSONDataEncoder) ContentType() string

func (JSONDataEncoder) Encode

func (J JSONDataEncoder) Encode(w io.Writer, value any) error

func (JSONDataEncoder) FileExtension

func (J JSONDataEncoder) FileExtension() string

type MimetypeHint

type MimetypeHint interface {
	Mimetype() string
}

type NoopHook

type NoopHook struct{}

func (NoopHook) PostBucketUploadHook

func (n NoopHook) PostBucketUploadHook(context.Context, *WebhookContext, []bucket.UploadResult)

func (NoopHook) PostMessageHook

func (n NoopHook) PostMessageHook(context.Context, *WebhookContext, error)

func (NoopHook) PreBucketUploadHook

func (n NoopHook) PreBucketUploadHook(ctx context.Context, _ *WebhookContext) context.Context

func (NoopHook) PreMessageHook

func (n NoopHook) PreMessageHook(ctx context.Context, _ *WebhookContext) context.Context

type QueueItem

func NewQueueItem

func NewQueueItem(ctx context.Context, messageContext tower.MessageContext) QueueItem

type WebhookContext

type WebhookContext struct {
	Message tower.MessageContext
	Files   []bucket.File
	Payload *WebhookPayload
	Extra   *ExtraInformation
	// Populated on PostMessageHook, otherwise Nil.
	//
	// Body is the response body from Discord.
	// Nil if the request failed to receive response from Discord.
	ResponseBody []byte
	// Populated on PostMessageHook if the request received response from Discord, otherwise nil.
	// Body is already consumed. Use ResponseBody instead to read the response body.
	Response *http.Response
}

type WebhookFile

type WebhookFile struct {
	Name        string
	ContentType string
}

type WebhookPayload

type WebhookPayload struct {
	Wait            bool             `json:"-"`
	ThreadID        snowflake.ID     `json:"-"`
	Content         string           `json:"content,omitempty"`
	Username        string           `json:"username,omitempty"`
	AvatarURL       string           `json:"avatarURL,omitempty"`
	TTS             bool             `json:"TTS,omitempty"`
	Embeds          []*Embed         `json:"embeds,omitempty"`
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
	Attachments     []*Attachment    `json:"attachments,omitempty"`
}

func (*WebhookPayload) BuildMultipartPayloadJSON

func (w *WebhookPayload) BuildMultipartPayloadJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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