discord

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const Scheme = "discord"

Scheme is the identifying part of this service's configuration URL

Variables

This section is empty.

Functions

func CreateAPIURLFromConfig

func CreateAPIURLFromConfig(config *Config) string

CreateAPIURLFromConfig takes a discord config object and creates a post url

func CreateItemsFromPlain added in v0.4.0

func CreateItemsFromPlain(plain string, splitLines bool) (items []types.MessageItem, omitted int)

CreateItemsFromPlain creates a set of MessageItems that is compatible with Discords webhook payload

Types

type Config

type Config struct {
	standard.EnumlessConfig
	WebhookID  string `url:"host"`
	Token      string `url:"user"`
	Title      string `key:"title"      default:""`
	Username   string `key:"username"   default:""         desc:"Override the webhook default username"`
	Avatar     string `key:"avatar,avatarurl"     default:""         desc:"Override the webhook default avatar with specified URL"`
	Color      uint   `key:"color"      default:"0x50D9ff" desc:"The color of the left border for plain messages"   base:"16"`
	ColorError uint   `key:"colorError" default:"0xd60510" desc:"The color of the left border for error messages"   base:"16"`
	ColorWarn  uint   `key:"colorWarn"  default:"0xffc441" desc:"The color of the left border for warning messages" base:"16"`
	ColorInfo  uint   `key:"colorInfo"  default:"0x2488ff" desc:"The color of the left border for info messages"    base:"16"`
	ColorDebug uint   `key:"colorDebug" default:"0x7b00ab" desc:"The color of the left border for debug messages"   base:"16"`
	SplitLines bool   `key:"splitLines" default:"Yes"      desc:"Whether to send each line as a separate embedded item"`
	JSON       bool   `` /* 139-byte string literal not displayed */
}

Config is the configuration needed to send discord notifications

func (*Config) GetURL

func (config *Config) GetURL() *url.URL

GetURL returns a URL representation of it's current field values

func (*Config) LevelColors added in v0.4.0

func (config *Config) LevelColors() (colors [types.MessageLevelCount]uint)

LevelColors returns an array of colors with a MessageLevel index

func (*Config) SetURL

func (config *Config) SetURL(url *url.URL) error

SetURL updates a ServiceConfig from a URL representation of it's field values

type Service

type Service struct {
	standard.Standard
	// contains filtered or unexported fields
}

Service providing Discord as a notification service

func (*Service) Initialize

func (service *Service) Initialize(configURL *url.URL, logger types.StdLogger) error

Initialize loads ServiceConfig from configURL and sets logger for this Service

func (*Service) Send

func (service *Service) Send(message string, params *types.Params) error

Send a notification message to discord

func (*Service) SendItems added in v0.4.0

func (service *Service) SendItems(items []types.MessageItem, params *types.Params) error

SendItems sends items with additional meta data and richer appearance

type WebhookPayload added in v0.4.0

type WebhookPayload struct {
	Embeds    []embedItem `json:"embeds"`
	Username  string      `json:"username,omitempty"`
	AvatarURL string      `json:"avatar_url,omitempty"`
}

WebhookPayload is the webhook endpoint payload

func CreatePayloadFromItems added in v0.4.0

func CreatePayloadFromItems(items []types.MessageItem, title string, colors [types.MessageLevelCount]uint, omitted int) (WebhookPayload, error)

CreatePayloadFromItems creates a JSON payload to be sent to the discord webhook API

Jump to

Keyboard shortcuts

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