Documentation ¶
Overview ¶
Package operations provides a centralized gateway for processing requests on Discord API operations.
Index ¶
- Constants
- func AddRoleToMember(session *discordgo.Session, guildID, userID, roleID string) error
- func BotHasChannelPermission(session *discordgo.Session, channel *discordgo.Channel) error
- func IsDeadlineExceeded(err error) bool
- func IsForbiddenResponse(err error) bool
- func IsMaxGuildsResponse(err error) bool
- func LookupGuild(session *discordgo.Session, guildID string) (*discordgo.Guild, error)
- func RemoveRoleFromMember(session *discordgo.Session, guildID, userID, roleID string) error
- func ShouldLogDebug(err error) bool
- type CreateRoleRequest
- type Gateway
- type Request
- type RequestType
Constants ¶
const ( CreateRoleString = "CreateRole" UnknownString = "unknown" )
RequestType string representations.
const APIErrorCodeMaxRoles = 30005
APIErrorCodeMaxRoles is the Discord API error code for max roles.
Variables ¶
This section is empty.
Functions ¶
func AddRoleToMember ¶
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 ¶
BotHasChannelPermission checks if the bot has view permissions for the channel. If the bot does have the view permission, BotHasChannelPermission returns nil.
func IsDeadlineExceeded ¶
IsDeadlineExceeded checks if the provided error wraps context.DeadlineExceeded.
func IsForbiddenResponse ¶
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 ¶
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 ¶
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 ¶
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 ¶
ShouldLogDebug checks if the provided error should be logged at a debug level.
Types ¶
type CreateRoleRequest ¶
CreateRoleRequest is a request to create a new role.
type Gateway ¶
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 ¶
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.