operations

package
v0.0.0-...-6d2f78d Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package operations provides a centralized gateway for processing requests on Discord API operations.

Index

Constants

View Source
const (
	CreateRoleString = "CreateRole"
	UnknownString    = "unknown"
)

RequestType string representations.

View Source
const APIErrorCodeMaxRoles = 30005

APIErrorCodeMaxRoles is the Discord API error code for max roles.

Variables

This section is empty.

Functions

func AddRoleToMember

func AddRoleToMember(session *discordgo.Session, guildID, userID, roleID string) error

AddRoleToMember adds the role associated with the provided roleID to the user associated with the provided userID, in the guild associated with the provided guildID.

func BotHasChannelPermission

func BotHasChannelPermission(session *discordgo.Session, channel *discordgo.Channel) error

BotHasChannelPermission checks if the bot has view permissions for the channel. If the bot does have the view permission, BotHasChannelPermission returns nil.

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

IsDeadlineExceeded checks if the provided error wraps context.DeadlineExceeded.

func IsForbiddenResponse

func IsForbiddenResponse(err error) bool

IsForbiddenResponse checks if the provided error wraps *discordgo.RESTError. If it does, IsForbiddenResponse returns true if the response code is equal to http.StatusForbidden.

func IsMaxGuildsResponse

func IsMaxGuildsResponse(err error) bool

IsMaxGuildsResponse checks if the provided error wraps *discordgo.RESTError. If it does, IsMaxGuildsResponse returns true if the response code is equal to http.StatusBadRequest and the error code is 30005.

func LookupGuild

func LookupGuild(session *discordgo.Session, guildID string) (*discordgo.Guild, error)

LookupGuild returns a *discordgo.Guild from the session's internal state cache. If the guild is not found in the state cache, LookupGuild will query the Discord API for the guild and add it to the state cache before returning it.

func RemoveRoleFromMember

func RemoveRoleFromMember(session *discordgo.Session, guildID, userID, roleID string) error

RemoveRoleFromMember removes the role associated with the provided roleID from the user associated with the provided userID, in the guild associated with the provided guildID.

func ShouldLogDebug

func ShouldLogDebug(err error) bool

ShouldLogDebug checks if the provided error should be logged at a debug level.

Types

type CreateRoleRequest

type CreateRoleRequest struct {
	Guild     *discordgo.Guild
	RoleName  string
	RoleColor int
}

CreateRoleRequest is a request to create a new role.

type Gateway

type Gateway struct {
	Session *discordgo.Session
	// contains filtered or unexported fields
}

Gateway is a centralized construct to process operation requests by de-duplicating identical simultaneous requests and providing the result to all of the callers.

func NewGateway

func NewGateway(session *discordgo.Session) *Gateway

NewGateway returns a new *Gateway ready to process requests.

func (*Gateway) Process

func (gateway *Gateway) Process(request *Request) <-chan singleflight.Result

Process will process the provided request and send back the result to the provided ResultChannel. The caller should type check the result it receives to determine if an error was sent or the result is of the type it expects.

type Request

type Request struct {
	Type       RequestType
	CreateRole *CreateRoleRequest
}

Request is an operations request to be processed.

type RequestType

type RequestType int

RequestType represents a type of operations request.

const CreateRole RequestType = iota

CreateRole is a RequestType enumeration.

func (RequestType) String

func (rt RequestType) String() string

String returns the string representation for the given RequestType.

Jump to

Keyboard shortcuts

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