webhook

package module
v0.0.0-...-9dad123 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 8 Imported by: 0

README

Webhook

Webhook is a bare bone package for working with discord webhooks.

Example

simple plain text

package main

import "github.com/Karitham/webhook"

const emojiURL = "https://cdn.discordapp.com/emojis/801874189526368256.gif"

func main() {
	wh := webhook.New("discord url here")

	wh.With(&webhook.Webhook{
		Username:  "Captain'Hook",
		AvatarURL: emojiURL,
		Content:   "This is the content of the message, it's plain text",
	})

	wh.Run()
}

with file as an attachement

	resp, _ := http.Get(emojiURL)
	defer resp.Body.Close()

	wh.With(&webhook.Webhook{
		Username:  "nanabongo",
		AvatarURL: emojiURL,
		Files: []Attachment{{
				Body:     resp.Body,
				Filename: "nanabongo.gif",
			},
		},
	})

	wh.Run()

To have the file embed itself send an image with the embed object with it's url being attachment://<filename> and attach to file as an attachment

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Body     io.Reader
	Filename string
}

Attachement is the files attached to the request

type Author

type Author struct {
	Name    string `json:"name"`
	URL     string `json:"url"`
	IconURL string `json:"icon_url"`
}

Author is the author object

type Embed

type Embed struct {
	Author      Author  `json:"author"`
	Footer      Footer  `json:"footer"`
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Thumbnail   Image   `json:"thumbnail"`
	Image       Image   `json:"image"`
	URL         string  `json:"url"`
	Fields      []Field `json:"fields"`
	Color       int64   `json:"color"`
}

Embed is the embed object

type Field

type Field struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

Field is the field object inside an embed

type Footer struct {
	Text    string `json:"text"`
	IconURL string `json:"icon_url"`
}

Footer is the footer of the embed

type Hook

type Hook struct {
	Webhook *Webhook
	Client  *http.Client
	// contains filtered or unexported fields
}

Hook is the toplevel object. It contains a Webhook object and everything required to send it. It's optimised for reusability, so it has an embedded http.Client. You can modify the client yourself if you want to change the defaults.

func New

func New(URL string) *Hook

New returns a new webhook with the designated URL.

func (*Hook) Run

func (h *Hook) Run() error

Run the webhook with the preconfigured settings

func (*Hook) With

func (h *Hook) With(w *Webhook)

type Image

type Image struct {
	URL string `json:"url"`
}

Image is an image possibly contained inside the embed

type Webhook

type Webhook struct {
	Username  string       `json:"username"`
	AvatarURL string       `json:"avatar_url"`
	Content   string       `json:"content"`
	Embeds    []Embed      `json:"embeds"`
	Files     []Attachment `json:"-"`
}

Webhook is the webhook object sent to discord

Jump to

Keyboard shortcuts

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