beelzebub

package module
v0.0.0-...-7245f98 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 18 Imported by: 1

README

beelzebub

A client for Discord's HTTP REST API.

Structure

Beelzebub draws inspiration from skwair/harmony in terms of design.

Discord resources that are instanced and scoped to an ID, or more, live in their own packages, which can be found in the flies directory. Each resource can be created with its respective method (e.g., Guild(), User(), etc) found on the main Devil type.

Some resources do not have a respective subpackage. One such instance of this is Emoji, as they are scoped to a Guild. So to perform operations on an Emoji, one would first need to create a Guild resource (henceforth "Fly" (because Beelzebub, get it?)) with its respective factory, and then perform whatever operations needed.

Tests

You may have noticed there are no tests of any kind in this package. Perhaps controversially, due to the nature of what Beelzebub does, I've opted to omit tests. The consequences of this decision are noted, but I'm going to roll with the punches. If you have the willpower, time, and/or patience to write unit tests, by all means, go ahead and PR it.

License

MIT

Documentation

Overview

Package beelzebub implements a REST API client for Discord.

Index

Constants

View Source
const (
	// BaseURL is the root of Discord's API, unversioned.
	BaseURL = "https://discord.com/api/v"

	// Version denotes what version of the API we're using.
	Version = "9"

	// RootURL is the root of Discord's API, versioned.
	RootURL = BaseURL + Version

	// ContentType is the default Content-Type header used by Beelzebub.
	ContentType = "application/json"

	// Accept is the default Accept header used by Beelzebub.
	Accept = "application/json"

	// UserAgent is the default User-Agent header used by Beelzebub.
	UserAgent = "DiscordBot (https://github.com/disaccord/beelzebub, %s)"
)

Variables

This section is empty.

Functions

func HTTPClient

func HTTPClient(c *http.Client) defaultClientOption

HTTPClient sets the *http.Client on a DefaultClient.

Types

type ClientOption

type ClientOption func(*Devil)

ClientOption configures a Devil.

func WithRestClient

func WithRestClient(rc flies.RestClient) ClientOption

WithRestClient sets the internal RestClient used by a Devil.

type CreateGuildOptions

type CreateGuildOptions struct {
	Name                        string                                `json:"name"`
	Region                      null.String                           `json:"region,omitempty"`
	Icon                        string                                `json:"icon,omitempty"`
	VerificationLevel           sigil.VerificationLevel               `json:"verification_level,omitempty"`
	DefaultMessageNotifications sigil.DefaultMessageNotificationLevel `json:"default_message_notifications,omitempty"`
	ExplicitContentFilter       sigil.ExplicitContentFilterLevel      `json:"explicit_content_filter,omitempty"`
	Roles                       []*sigil.Role                         `json:"roles,omitempty"`
	Channels                    []*sigil.Channel                      `json:"channels,omitempty"`
	AFKChannelID                null.String                           `json:"afk_channel_id,omitempty"`
	AFKTimeout                  int                                   `json:"afk_timeout,omitempty"`
	SystemChannelID             string                                `json:"system_channel_id,omitempty"`
	SystemChannelFlags          sigil.SystemChannelFlag               `json:"system_channel_flags,omitempty"`
}

CreateGuildOptions contains parameters used to configure a Guild upon creation. The only required field is `Name`.

type Devil

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

Devil is an HTTP client responsible for interacting with Discord's API.

func New

func New(defaultToken string, opts ...ClientOption) (*Devil, error)

New creates a new Devil with the given token and options. The token is used as a default for when a resource is not configured to use another.

func (*Devil) Application

func (d *Devil) Application(id string) *application.Fly

Application is a shorthand for `*Devil.ApplicationWithToken(id, "")`.

func (*Devil) ApplicationWithToken

func (d *Devil) ApplicationWithToken(id, token string) *application.Fly

ApplicationWithToken creates a new Fly to manage an Application. If omitted, `token` will be set to `*Devil.defaultToken`.

func (*Devil) Channel

func (d *Devil) Channel(id string) *channel.Fly

Channel is shorthand for `*Devil.ChannelWithToken(id, "")`.

func (*Devil) ChannelWithToken

func (d *Devil) ChannelWithToken(id, token string) *channel.Fly

ChannelWithToken creates a new Fly to manage a Channel. If omitted, `token` will be set to `*Devil.defaultToken`.

func (*Devil) CreateGuild

func (d *Devil) CreateGuild(ctx context.Context, opts *CreateGuildOptions) (*sigil.Guild, error)

CreateGuild creates a new Guild with the options. This can only be used by a bot in 10 guilds or less.

func (*Devil) GetGateway

func (d *Devil) GetGateway(ctx context.Context) (*GetGatewayResponse, error)

GetGateway retreives a connection URL for Discord's Gateway. The return value should be cached, and this method should then only be called when connecting with the cached value fails.

func (*Devil) GetUser

func (d *Devil) GetUser(ctx context.Context, id string) (*sigil.User, error)

GetUser fetches a User by their ID.

func (*Devil) Guild

func (d *Devil) Guild(id string) *guild.Fly

Guild is a shorthand for `*Devil.GuildWithToken(id, "")`.

func (*Devil) GuildWithToken

func (d *Devil) GuildWithToken(id, token string) *guild.Fly

GuildWithToken creates a new Fly to manage a Guild. If omitted, `token` will be set to `*Devil.defaultToken`.

func (*Devil) Invite

func (d *Devil) Invite(code string) *invite.Fly

Invite is shorthand for `*Devil.InviteWithToken(code, "")`.

func (*Devil) InviteWithToken

func (d *Devil) InviteWithToken(code, token string) *invite.Fly

InviteWithToken creates a new Fly to manage an Invite. If omitted, `token` will be set to `*Devil.defaultToken`.

func (*Devil) ListVoiceRegions

func (d *Devil) ListVoiceRegions(ctx context.Context) ([]*sigil.VoiceRegion, error)

ListVoiceRegions fetches the list of Voice Regions.

func (*Devil) Stage

func (d *Devil) Stage(id string) *stage.Fly

Stage is shorthand for `*Devil.StageWithToken(id, "")`.

func (*Devil) StageWithToken

func (d *Devil) StageWithToken(id, token string) *stage.Fly

StageWithToken creates a Fly to manage a Stage. If omitted, `token` is set to `*Devil.defaultToken`.

func (*Devil) TokenedWebhook

func (d *Devil) TokenedWebhook(id, token string) *webhook.TokenFly

TokenedWebhook creates a Fly to manage an unauthenticated Webhook.

func (*Devil) User

func (d *Devil) User() *user.Fly

User is shorthand for `*Devil.UserWithToken(id, "")`.

func (*Devil) UserWithToken

func (d *Devil) UserWithToken(token string) *user.Fly

UserWithToken creates a new Fly to manage a User. If omitted, `token` will be set to `*Devil.defaultToken`.

func (*Devil) Webhook

func (d *Devil) Webhook(id string) *webhook.Fly

Webhook is shorthand for `*Devil.WebhookWithToken(id, "")`.

func (*Devil) WebhookWithToken

func (d *Devil) WebhookWithToken(id, token string) *webhook.Fly

WebhookWithToken creates a Fly to manage an authenticated Webhook using the given token. If omitted, `token` is set to `*Devil.defaultToken`.

type GetGatewayResponse

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

GetGatewayResponse is the response sent by Discord when requesting a URL to the gateway.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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