revoltgo

package module
v0.0.0-...-346cb7f Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: BSD-3-Clause Imports: 17 Imported by: 8

README

Support server

We have a Revolt server dedicated to this project, where you can discuss the project, suggest features, or highlight issues. Join our community.

Why use revoltgo

RevoltGo logo RGO

At the time of writing, other (few) Revolt Go packages were simply unfeasible. They had:

  • Hardcoded JSON payloads
  • Poor API coverage and consistency
  • Interface{} shoved in fields they were too lazy to add a struct for
  • Hard-to-maintain codebase and odd design choices (wrapping Client and Time for each struct)
  • ... this list can go on

Features

RevoltGo as a project provides:

  • Broader, up-to-date API coverage and functionality compared to other Revolt Go projects
  • Extensive customisability due to low-level bindings
  • Consistent, cleaner, and maintainable codebase

Additionally, revoltgo provides quality-of-life features such as:

  • Permission calculator
  • Lightweight ratelimit handling
  • Automatic re-connects on websocket failures
  • State/cache updates for members, roles, channels, and servers

Getting started

Installation

Assuming that you have a working Go environment ready, all you have to do is run either of the following commands to install the package:

Stable release

go get github.com/sentinelb51/revoltgo

Latest release

go get github.com/sentinelb51/revoltgo@latest

If you do not have a Go environment ready, see how to set it up here

Usage

Now that the package is installed, you will have to import it

import "github.com/sentinelb51/revoltgo"

Then, construct a new session using your bots token, and store it in a variable. This "session" is a centralised store of all API and websocket methods at your fingertips, relevant to the bot you're about to connect with.

session := revoltgo.New("your token here")

Finally, open the websocket connection to Revolt API. Your bot will attempt to login, and if successful, will receive events from the Revolt websocket about the world it's in. Make sure to handle the error, as it can indicate any problem that could arise during the connection.

err := session.Open()

To ensure the program keeps running, and accepts signals such as Ctrl + C, make a channel and wait for a signal from said channel:

sc := make(chan os.Signal, 1)

signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc

When it's time to close the connection, simply close the session as demonstrated below.

session.Close()

Examples

The following examples are available in the examples directory:

  • ping_bot.go: A simple bot that responds to the !ping command.
  • selfbot.go: A simple self-bot that responds to the !ping command.
  • uploads.go: A simple bot that uploads the RevoltGo logo using the command "!upload"

Resource usage

The resource utilisation of the library depends on how many handlers are registered and how many objects are cached in the state. More handlers will increase CPU usage, while more objects in the state will increase memory usage.

For programs that need to be as lightweight as possible (and do not care about caching objects), they can disable the state by setting the following tracking options in Session.State:

/* Tracking options */
TrackUsers    bool
TrackServers  bool
TrackChannels bool
TrackMembers  bool
TrackEmojis   bool
TrackWebhooks bool

Windows platforms

Standalone, with state enabled, the library uses:

  • ~0.00% CPU
  • ~6.0-6.8 MB of RAM

The memory usage is expected to grow with state enabled as more objects get cached.

Linux platforms

Not tested, but it's expected to be around the same.

License: BSD 3-Clause

RevoltGo is licensed under the BSD 3-Clause License. What this means is that:

You are allowed to:
  • Modify the code, and distribute your own versions.
  • Use this library in personal, open-source, or commercial projects.
  • Include it in proprietary software, without making your project open-source.
You are not allowed to:
  • Remove or alter the license and copyright notice.
  • Use the name "RevoltGo" or its contributors for endorsements without permission.

Documentation

Overview

Package revoltgo is a Go wrapper for the Revolt API with low-level bindings - Made by @sentinelb51 - For support, join our revolt server on the GitHub README file

Index

Constants

View Source
const (
	URLUsersUsername = "/users/me/username"

	URLUsers              = "/users/%s"
	URLUsersMutual        = URLUsers + "/mutual"
	URLUsersDM            = URLUsers + "/dm"
	URLUsersFlags         = URLUsers + "/flags"
	URLUsersFriend        = URLUsers + "/friend"
	URLUsersBlock         = URLUsers + "/block"
	URLUsersProfile       = URLUsers + "/profile"
	URLUsersRelationships = URLUsers + "/relationships"

	URLUsersDefaultAvatar = URLUsers + "/default_avatar"

	URLServers         = "/servers/%s"
	URLServersAck      = URLServers + "/ack"
	URLServersChannels = URLServers + "/channels"
	URLServersMembers  = URLServers + "/members"
	URLServersMember   = URLServersMembers + "/%s"
	URLServersBans     = URLServers + "/bans"
	URLServersBan      = URLServersBans + "/%s"
	URLServersRoles    = URLServers + "/roles"
	URLServersRole     = URLServers + "/roles/%s"

	URLServersPermissions = URLServers + "/permissions/%s"

	URLChannels                 = "/channels/%s"
	URLChannelsAckMessage       = URLChannels + "/ack/%s"
	URLChannelsMessages         = URLChannels + "/messages"
	URLChannelsMessage          = URLChannelsMessages + "/%s"
	URLChannelsMessageReactions = URLChannelsMessage + "/reactions"
	URLChannelsMessageReaction  = URLChannelsMessageReactions + "/%s"
	URLChannelsTyping           = URLChannels + "/typing"
	URLChannelsInvites          = URLChannels + "/invites"
	URLChannelsInvite           = URLChannelsInvites + "/%s"
	URLChannelsPermissions      = URLChannels + "/permissions/%s"
	URLChannelsRecipients       = URLChannels + "/recipients/%s"
	URLChannelsWebhooks         = URLChannels + "/webhooks"

	URLInvites = "/invites/%s"

	URLBots       = "/bots/%s"
	URLBotsInvite = URLBots + "/invite"

	URLAuth         = "/auth"
	URLAuthAccount  = URLAuth + "/account/%s"
	URLAuthSessions = URLAuth + "/session/%s"

	URLCustom      = "/custom"
	URLCustomEmoji = URLCustom + "/emoji/%s"

	URLOnboard = "/onboard/%s"

	URLSync = "/sync/%s"

	URLPush = "/push/%s"

	URLSafetyReport = "/safety/report"
)
View Source
const (
	MessageEmbedSpecialTypeNone       = "None"
	MessageEmbedSpecialTypeGIF        = "GIF"
	MessageEmbedSpecialTypeYouTube    = "YouTube"
	MessageEmbedSpecialTypeLightspeed = "Lightspeed"
	MessageEmbedSpecialTypeTwitch     = "Twitch"
	MessageEmbedSpecialTypeSpotify    = "Spotify"
	MessageEmbedSpecialTypeSoundcloud = "Soundcloud"
	MessageEmbedSpecialTypeBandcamp   = "Bandcamp"
	MessageEmbedSpecialTypeStreamable = "Streamable"
)
View Source
const (
	UserPermissionAccess = 1 << iota
	UserPermissionViewProfile
	UserPermissionSendMessage
	UserPermissionInvite
)
View Source
const (
	PermissionManageChannel       = 2 << 0
	PermissionManageServer        = 2 << 1
	PermissionManagePermissions   = 2 << 2
	PermissionManageRole          = 2 << 3
	PermissionManageCustomisation = 2 << 4
	PermissionKickMembers         = 2 << 6
	PermissionBanMembers          = 2 << 7
	PermissionTimeoutMembers      = 2 << 8
	PermissionAssignRoles         = 2 << 9
	PermissionChangeNickname      = 2 << 10
	PermissionManageNicknames     = 2 << 11
	PermissionChangeAvatar        = 2 << 12
	PermissionRemoveAvatars       = 2 << 13
	PermissionViewChannel         = 2 << 20
	PermissionReadMessageHistory  = 2 << 21
	PermissionSendMessage         = 2 << 22
	PermissionManageMessages      = 2 << 23
	PermissionManageWebhooks      = 2 << 24
	PermissionInviteOthers        = 2 << 25
	PermissionSendEmbeds          = 2 << 26
	PermissionUploadFiles         = 2 << 27
	PermissionMasquerade          = 2 << 28
	PermissionReact               = 2 << 29
	PermissionConnect             = 2 << 30
	PermissionSpeak               = 2 << 31
	PermissionVideo               = 2 << 32
	PermissionMuteMembers         = 2 << 33
	PermissionDeafenMembers       = 2 << 34
	PermissionMoveMembers         = 2 << 35
	PermissionGrantAllSafe        = 0x000F_FFFF_FFFF_FFFF
)
View Source
const (
	UserRelationsTypeNone         = "None"
	UserRelationsTypeUser         = "User"
	UserRelationsTypeFriend       = "Friend"
	UserRelationsTypeOutgoing     = "Outgoing"
	UserRelationsTypeIncoming     = "Incoming"
	UserRelationsTypeBlocked      = "Blocked"
	UserRelationsTypeBlockedOther = "BlockedOther"
)
View Source
const VERSION = "v2.4.0"

Variables

This section is empty.

Functions

func EndpointAuthAccount

func EndpointAuthAccount(action string) string

func EndpointAuthAccountChange

func EndpointAuthAccountChange(detail string) string

func EndpointAuthAccountVerify

func EndpointAuthAccountVerify(code string) string

func EndpointAuthSession

func EndpointAuthSession(action string) string

func EndpointAutumn

func EndpointAutumn(tag string) (url string)

func EndpointAutumnFile

func EndpointAutumnFile(tag, id, size string) (url string)

func EndpointBots

func EndpointBots(bID string) string

func EndpointBotsInvite

func EndpointBotsInvite(bID string) string

func EndpointChannelAckMessage

func EndpointChannelAckMessage(cID, mID string) string

func EndpointChannels

func EndpointChannels(cID string) string

func EndpointChannelsInvite

func EndpointChannelsInvite(cID, iID string) string

func EndpointChannelsInvites

func EndpointChannelsInvites(cID string) string

func EndpointChannelsMessage

func EndpointChannelsMessage(cID, mID string) string

func EndpointChannelsMessageReaction

func EndpointChannelsMessageReaction(cID, mID, rID string) string

func EndpointChannelsMessageReactions

func EndpointChannelsMessageReactions(cID, mID string) string

func EndpointChannelsMessages

func EndpointChannelsMessages(cID string) string

func EndpointChannelsPermissions

func EndpointChannelsPermissions(sID, cID string) string

func EndpointChannelsRecipients

func EndpointChannelsRecipients(cID, mID string) string

func EndpointChannelsTyping

func EndpointChannelsTyping(cID string) string

func EndpointChannelsWebhooks

func EndpointChannelsWebhooks(cID string) string

func EndpointCustomEmoji

func EndpointCustomEmoji(eID string) string

func EndpointInvite

func EndpointInvite(sID string) string

func EndpointOnboard

func EndpointOnboard(action string) string

func EndpointPush

func EndpointPush(action string) string

func EndpointServerPermissions

func EndpointServerPermissions(sID, rID string) string

func EndpointServers

func EndpointServers(sID string) string

func EndpointServersAck

func EndpointServersAck(sID string) string

func EndpointServersBan

func EndpointServersBan(sID, uID string) string

func EndpointServersBans

func EndpointServersBans(sID string) string

func EndpointServersChannels

func EndpointServersChannels(sID string) string

func EndpointServersMember

func EndpointServersMember(sID, mID string) string

func EndpointServersMembers

func EndpointServersMembers(sID string) string

func EndpointServersRole

func EndpointServersRole(sID, rID string) string

func EndpointServersRoles

func EndpointServersRoles(sID string) string

func EndpointSync

func EndpointSync(setting string) string

func EndpointSyncSettings

func EndpointSyncSettings(sID string) string

func EndpointUsers

func EndpointUsers(uID string) string

func EndpointUsersBlock

func EndpointUsersBlock(uID string) string

func EndpointUsersDM

func EndpointUsersDM(uID string) string

func EndpointUsersDefaultAvatar

func EndpointUsersDefaultAvatar(uID string) string

func EndpointUsersFlags

func EndpointUsersFlags(uID string) string

func EndpointUsersFriend

func EndpointUsersFriend(uID string) string

func EndpointUsersMutual

func EndpointUsersMutual(uID string) string

func EndpointUsersProfile

func EndpointUsersProfile(uID string) string

func NewWithLogin

func NewWithLogin(data LoginData) (*Session, LoginResponse, error)

NewWithLogin exchanges an email and password for a session token, and then creates a new session. You are expected to store and re-use the token for future sessions.

func Ptr

func Ptr[T any](v T) *T

Ptr is a quality-of-life function to quickly return a pointer to any value

func SetBaseURL

func SetBaseURL(newURL string) error

SetBaseURL sets the base URL for the API. Make sure to call this before opening any sessions, and not during an active connection.

Types

type AbstractEventUpdate

type AbstractEventUpdate struct {
	Event

	// ID can either be a simple string or a MemberCompositeID.
	ID AbstractEventUpdateID `json:"id"`

	// RoleID is only present in ServerRoleUpdate events.
	RoleID string `json:"role_id"`

	// The updated data for a specific event
	Data json.RawMessage `json:"data"`

	// Clear is a list of keys to clear from the cache.
	Clear []string `json:"clear"`

	// Remove is a list of keys to remove from the cache.
	// Ideally the API should just stick to "clear"...
	Remove []string `json:"remove"`
}

AbstractEventUpdate is a generic event for all update events. This is mainly used to update the cache, and is not a low-level event.

func (*AbstractEventUpdate) EventChannelUpdate

func (aeu *AbstractEventUpdate) EventChannelUpdate() *EventChannelUpdate

func (*AbstractEventUpdate) EventMessageUpdate

func (aeu *AbstractEventUpdate) EventMessageUpdate() *EventMessageUpdate

func (*AbstractEventUpdate) EventServerMemberUpdate

func (aeu *AbstractEventUpdate) EventServerMemberUpdate() *EventServerMemberUpdate

func (*AbstractEventUpdate) EventServerRoleUpdate

func (aeu *AbstractEventUpdate) EventServerRoleUpdate() *EventServerRoleUpdate

func (*AbstractEventUpdate) EventServerUpdate

func (aeu *AbstractEventUpdate) EventServerUpdate() *EventServerUpdate

func (*AbstractEventUpdate) EventUserUpdate

func (aeu *AbstractEventUpdate) EventUserUpdate() *EventUserUpdate

func (*AbstractEventUpdate) EventWebhookUpdate

func (aeu *AbstractEventUpdate) EventWebhookUpdate() *EventWebhookUpdate

type AbstractEventUpdateID

type AbstractEventUpdateID struct {
	StringID string
	MemberID MemberCompositeID
}

func (*AbstractEventUpdateID) UnmarshalJSON

func (id *AbstractEventUpdateID) UnmarshalJSON(data []byte) (err error)

type Account

type Account struct {
	ID    string `json:"_id"`
	Email string `json:"email"`
}

type AccountChangeEmailData

type AccountChangeEmailData struct {
	Email           string `json:"email"`
	CurrentPassword string `json:"current_password"`
}

type AccountChangePasswordData

type AccountChangePasswordData struct {
	Password        string `json:"password"`
	CurrentPassword string `json:"current_password"`
}

type AccountCreateData

type AccountCreateData struct {
	Email    string `json:"email"`
	Password string `json:"password"`
	Invite   string `json:"invite"`
	Captcha  string `json:"captcha"`
}

type AccountDeleteConfirmData

type AccountDeleteConfirmData struct {
	Token string `json:"token"`
}

type AccountReverifyData

type AccountReverifyData struct {
	Email   string `json:"email"`
	Captcha string `json:"captcha"`
}

type Attachment

type Attachment struct {
	ID string `json:"_id"`

	// Tag / bucket this file was uploaded to
	Tag string `json:"tag"`

	// Original filename
	Filename string `json:"filename"`

	// Metadata associated with file
	Metadata *AttachmentMetadata `json:"metadata"`

	// Raw content type of this file
	ContentType string `json:"content_type"`

	// Size of this file (in bytes)
	Size int `json:"size"`

	// Whether this file was deleted
	Deleted bool `json:"deleted"`

	// Whether this file was reported
	Reported bool `json:"reported"`

	MessageID string `json:"message_id"`
	UserID    string `json:"user_id"`
	ServerID  string `json:"server_id"`
	ObjectID  string `json:"object_id"`
}

func (Attachment) URL

func (a Attachment) URL(size string) string

type AttachmentMetadata

type AttachmentMetadata struct {
	Type AttachmentMetadataType `json:"type"`

	Width  int `json:"width"`
	Height int `json:"height"`
}

type AttachmentMetadataType

type AttachmentMetadataType string
const (
	AttachmentMetadataTypeFile  AttachmentMetadataType = "File"
	AttachmentMetadataTypeText  AttachmentMetadataType = "Text"
	AttachmentMetadataTypeImage AttachmentMetadataType = "Image"
	AttachmentMetadataTypeVideo AttachmentMetadataType = "Video"
	AttachmentMetadataTypeAudio AttachmentMetadataType = "Audio"
)

type AuthType

type AuthType string
const (
	EventTypeAuthDeleteSession     AuthType = "DeleteSession"
	EventTypeAuthDeleteAllSessions AuthType = "DeleteAllSessions"
)

type Bot

type Bot struct {
	ID string `json:"_id"`

	// User ID of the bot owner
	Owner string `json:"owner"`

	// Token used to authenticate requests for this bot
	Token string `json:"token"`

	// Whether the bot is public (may be invited by anyone)
	Public bool `json:"public"`

	// Whether to enable analytics
	Analytics bool `json:"analytics"`

	// Whether this bot should be publicly discoverable
	Discoverable bool `json:"discoverable"`

	// Reserved; URL for handling interactions
	InteractionsURL string `json:"interactions_url"`

	// URL for terms of service
	TermsOfServiceURL string `json:"terms_of_service_url"`

	// URL for privacy policy
	PrivacyPolicyURL string `json:"privacy_policy_url"`

	// Enum of bot flags
	Flags int `json:"flags"`
}

type BotCreateData

type BotCreateData struct {
	Name string `json:"name"`
}

type BotEditData

type BotEditData struct {
	Name            string   `json:"name"`
	Public          bool     `json:"public"`
	Analytics       bool     `json:"analytics"`
	InteractionsURL string   `json:"interactions_url"`
	Remove          []string `json:"remove"`
}

type BotInformation

type BotInformation struct {
	Owner string `json:"owner"`
}

type BotInviteData

type BotInviteData struct {
	Server string `json:"server"`
	Group  string `json:"group"`
}

type ChangeEmail

type ChangeEmail struct {
	Ticket Ticket `json:"ticket"` // Why is this nested
}

type Channel

type Channel struct {
	ID                 string        `json:"_id"`
	Server             string        `json:"server"`
	ChannelType        ChannelType   `json:"channel_type"`
	Name               string        `json:"name"`
	Description        string        `json:"description"`
	Icon               *Attachment   `json:"icon"`
	DefaultPermissions *PermissionAD `json:"default_permissions"`
	NSFW               bool          `json:"nsfw"`

	// Recipients are populated for direct messages or groups, typically including your user ID
	Recipients []string `json:"recipients"`

	// ID of the last message sent in this channel
	LastMessageID string `json:"last_message_id"`

	// RolePermissions is a map of role ID to PermissionAD structs.
	RolePermissions map[string]*PermissionAD `json:"role_permissions"`

	// Permissions assigned to members of this group (does not apply to the owner of the group)
	Permissions *uint `json:"permissions"`

	// User ID of the owner of the group
	Owner string `json:"owner"`

	// Whether this direct message channel is currently open on both sides
	Active bool `json:"active"`
}

Channel holds information about a channel.

type ChannelEditData

type ChannelEditData struct {
	Name        string   `json:"name,omitempty"`
	Description string   `json:"description,omitempty"`
	Owner       string   `json:"owner,omitempty"`
	Icon        string   `json:"icon,omitempty"`
	NSFW        bool     `json:"nsfw,omitempty"`
	Archived    bool     `json:"archived,omitempty"`
	Remove      []string `json:"remove"`
}

type ChannelFetchedMessages

type ChannelFetchedMessages struct {
	Messages []*Message      `json:"messages"`
	Users    []*User         `json:"users"`
	Members  []*ServerMember `json:"members"`
}

type ChannelMessageBulkDeleteData

type ChannelMessageBulkDeleteData struct {
	IDs []string `json:"ids"`
}

type ChannelMessagesParams

type ChannelMessagesParams struct {
	// Maximum number of messages to fetch. For nearby messages, this is (limit + 1)
	Limit int `json:"limit,omitempty"`

	// Message ID before which messages should be fetched
	Before string `json:"before,omitempty"`

	// Message ID after which messages should be fetched
	After string `json:"after,omitempty"`

	// Message sort direction
	Sort ChannelMessagesParamsSortType `json:"sort,omitempty"`

	// Message ID to search around. Specifying this ignores Before, After, and Sort
	Nearby string `json:"nearby,omitempty"`

	// Whether to include user (and member, if server channel) objects
	IncludeUsers bool `json:"include_users,omitempty"`
}

func (ChannelMessagesParams) Encode

func (p ChannelMessagesParams) Encode() string

type ChannelMessagesParamsSortType

type ChannelMessagesParamsSortType string
const (
	ChannelMessagesParamsSortTypeRelevance ChannelMessagesParamsSortType = "Relevance"
	ChannelMessagesParamsSortTypeOldest    ChannelMessagesParamsSortType = "Oldest"
	ChannelMessagesParamsSortTypeLatest    ChannelMessagesParamsSortType = "Latest"
)

type ChannelType

type ChannelType string
const (
	ChannelTypeSavedMessages ChannelType = "SavedMessages"
	ChannelTypeText          ChannelType = "TextChannel"
	ChannelTypeVoice         ChannelType = "VoiceChannel"
	ChannelTypeDM            ChannelType = "DirectMessage"
	ChannelTypeGroup         ChannelType = "Group"
)

type CompositeChannelID

type CompositeChannelID struct {
	Channel string `json:"channel"`
	User    string `json:"user"`
}

type Emoji

type Emoji struct {
	ID        string       `json:"_id"`
	Parent    *EmojiParent `json:"parent"`
	CreatorID string       `json:"creator_id"`
	Name      string       `json:"name"`
	Animated  bool         `json:"animated"`
	NSFW      bool         `json:"nsfw"`
}

type EmojiCreateData

type EmojiCreateData struct {
	Name   string       `json:"name"`
	Parent *EmojiParent `json:"parent"`
	Nsfw   bool         `json:"nsfw"`
}

type EmojiParent

type EmojiParent struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

type Event

type Event struct {
	Type string `json:"type"`
}

type EventAuth

type EventAuth struct {
	Event
	EventType AuthType `json:"event_type"`
	UserID    string   `json:"user_id"`
	SessionID string   `json:"session_id"`

	// Only present when... I forgot.
	ExcludeSessionID string `json:"exclude_session_id"`
}

type EventAuthenticated

type EventAuthenticated struct {
	Event
}

EventAuthenticated is sent after the client has authenticated.

type EventBulk

type EventBulk struct {
	Event
	V []json.RawMessage `json:"v"`
}

type EventBulkMessageDelete

type EventBulkMessageDelete struct {
	Event
	Channel string   `json:"channel"`
	IDs     []string `json:"ids"`
}

type EventChannelAck

type EventChannelAck struct {
	Event
	ID        string `json:"id"`
	User      string `json:"user"`
	MessageID string `json:"message_id"`
}

type EventChannelCreate

type EventChannelCreate struct {
	Event
	*Channel
}

EventChannelCreate is sent when a channel is created. This is dispatched in conjunction with EventServerUpdate

type EventChannelDelete

type EventChannelDelete struct {
	Event
	ID string `json:"id"`
}

EventChannelDelete is sent when a channel is deleted.

type EventChannelGroupJoin

type EventChannelGroupJoin struct {
	Event
	ID   string `json:"id"`
	User string `json:"user"`
}

type EventChannelGroupLeave

type EventChannelGroupLeave struct {
	EventChannelGroupJoin
}

type EventChannelStartTyping

type EventChannelStartTyping struct {
	Event
	ID   string `json:"id"`
	User string `json:"user,omitempty"`
}

EventChannelStartTyping is sent when a user starts typing in a channel.

type EventChannelStopTyping

type EventChannelStopTyping struct {
	EventChannelStartTyping
}

EventChannelStopTyping is sent when a user stops typing in a channel.

type EventChannelUpdate

type EventChannelUpdate struct {
	Event
	ID    string   `json:"id"`
	Data  *Channel `json:"data"`
	Clear []string `json:"clear"`
}

EventChannelUpdate is sent when a channel is updated. Data will only contain fields that were modified.

type EventEmojiCreate

type EventEmojiCreate struct {
	Event
	*Emoji
}

type EventEmojiDelete

type EventEmojiDelete struct {
	Event
	ID string `json:"id"`
}

type EventErrorType

type EventErrorType string
const (
	EventErrorTypeLabelMe               EventErrorType = "LabelMe"
	EventErrorTypeInternalError         EventErrorType = "InternalError"
	EventErrorTypeInvalidSession        EventErrorType = "InvalidSession"
	EventErrorTypeOnboardingNotFinished EventErrorType = "OnboardingNotFinished"
	EventErrorTypeAlreadyAuthenticated  EventErrorType = "AlreadyAuthenticated"
)

type EventMessage

type EventMessage struct {
	Event
	Message
}

type EventMessageAppend

type EventMessageAppend struct {
	ID      string  `json:"id"`
	Channel string  `json:"channel"`
	Append  Message `json:"append"`
}

type EventMessageDelete

type EventMessageDelete struct {
	Event
	ID      string `json:"id"`
	Channel string `json:"channel"`
}

type EventMessageReact

type EventMessageReact struct {
	Event
	ID        string `json:"id"`
	ChannelID string `json:"channel_id"`
	UserID    string `json:"user_id"`
	EmojiID   string `json:"emoji_id"`
}

type EventMessageRemoveReaction

type EventMessageRemoveReaction struct {
	ID        string `json:"id"`
	ChannelID string `json:"channel_id"`
	EmojiID   string `json:"emoji_id"`
}

EventMessageRemoveReaction is sent when all the reactions are removed from a message.

type EventMessageUnreact

type EventMessageUnreact struct {
	EventMessageReact
}

EventMessageUnreact is sent when a user removes a singular reaction from a message.

type EventMessageUpdate

type EventMessageUpdate struct {
	Event
	ID      string  `json:"id"`
	Channel string  `json:"channel"`
	Data    Message `json:"data"`
}

type EventPong

type EventPong struct {
	Event
	Data int64 `json:"data"`
}

type EventReady

type EventReady struct {
	Event
	Users    []*User         `json:"users"`
	Servers  []*Server       `json:"servers"`
	Channels []*Channel      `json:"channels"`
	Members  []*ServerMember `json:"members"`
	Emojis   []*Emoji        `json:"emojis"`
}

EventReady provides information about objects relative to the user. This is used to populate the session's cache

type EventServerCreate

type EventServerCreate struct {
	Event
	ID       string     `json:"id"`
	Server   *Server    `json:"server"`
	Channels []*Channel `json:"channels"`
	Emojis   []*Emoji   `json:"emojis"`
}

EventServerCreate is sent when a server is created (joined).

type EventServerDelete

type EventServerDelete struct {
	Event
	ID string `json:"id"`
}

type EventServerMemberJoin

type EventServerMemberJoin struct {
	Event
	ID   string `json:"id"`
	User string `json:"user"`
}

type EventServerMemberLeave

type EventServerMemberLeave struct {
	Event
	ID     string `json:"id"`
	User   string `json:"user"`
	Reason string `json:"reason"`
}

EventServerMemberLeave is sent when a user leaves a server.

type EventServerMemberUpdate

type EventServerMemberUpdate struct {
	Event
	ID    MemberCompositeID `json:"id"`
	Data  *ServerMember     `json:"data"`
	Clear []string          `json:"clear"`
}

EventServerMemberUpdate is sent when a member is updated. Data will only contain fields that were modified.

type EventServerRoleDelete

type EventServerRoleDelete struct {
	Event
	ID     string `json:"id"`
	RoleID string `json:"role_id"`
}

type EventServerRoleUpdate

type EventServerRoleUpdate struct {
	Event
	ID     string      `json:"id"`
	RoleID string      `json:"role_id"`
	Data   *ServerRole `json:"data"`
	Clear  []string    `json:"clear"`
}

EventServerRoleUpdate is sent when a role is updated. Data will only contain fields that were modified.

type EventServerUpdate

type EventServerUpdate struct {
	Event
	ID    string   `json:"id"`
	Data  *Server  `json:"data"`
	Clear []string `json:"clear"`
}

EventServerUpdate is sent when a server is updated. Data will only contain fields that were modified.

type EventUserPlatformWipe

type EventUserPlatformWipe struct {
	Event
	UserID string `json:"user_id"`
	Flags  int    `json:"flags"`
}

type EventUserRelationship

type EventUserRelationship struct {
	Event
	ID   string `json:"id"`
	User *User  `json:"user"`
}

type EventUserSettingsUpdate

type EventUserSettingsUpdate struct {
	Event
	// Update is a tuple of (int, string); update time, and the data in JSON
	Update map[string]UpdateTuple `json:"update"`
}

type EventUserUpdate

type EventUserUpdate struct {
	Event
	ID    string   `json:"id"`
	Data  *User    `json:"data"`
	Clear []string `json:"clear"`
}

type EventWebhookCreate

type EventWebhookCreate struct {
	Event
	*Webhook
}

type EventWebhookDelete

type EventWebhookDelete struct {
	Event
	ID string `json:"id"`
}

type EventWebhookUpdate

type EventWebhookUpdate struct {
	Event
	ID     string   `json:"id"`
	Data   *Webhook `json:"data"`
	Remove []string `json:"remove"`
}

type FetchedBot

type FetchedBot struct {
	Bot  *Bot  `json:"bot"`
	User *User `json:"user"`
}

type FetchedBots

type FetchedBots struct {
	Bots  []*Bot  `json:"bots"`
	Users []*User `json:"users"`
}

type FetchedGroupMembers

type FetchedGroupMembers struct {
	Messages []*Message `json:"messages"`
	Users    []*User    `json:"users"`
}

type File

type File struct {
	// The name of the file; this is completely arbitrary because the backend determines the file-type anyway
	// However, it should not be empty, otherwise the media will not load on the client
	Name string

	// The contents of the file to be read when uploading
	Reader io.Reader
}

type FileAttachment

type FileAttachment struct {
	ID string `json:"id"`
}

FileAttachment is the response from the API when uploading a file. To upload a file, you must reference this ID in MessageSend.Attachments.

type Group

type Group struct {
	ID          string   `json:"_id"`
	OwnerID     string   `json:"owner"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Users       []string `json:"users"`
}

type GroupCreateData

type GroupCreateData struct {
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Users       []string `json:"users"`
	NSFW        bool     `json:"nsfw"`
}

GroupCreateData describes how a group should be created

type GroupSystemMessages

type GroupSystemMessages struct {
	UserJoined string `json:"user_joined,omitempty"`
	UserLeft   string `json:"user_left,omitempty"`
}

type Invite

type Invite struct {
	Type               InviteType  `json:"type"`
	ServerID           string      `json:"server_id"`
	ServerName         string      `json:"server_name"`
	ServerIcon         *Attachment `json:"server_icon"`
	ServerBanner       *Attachment `json:"server_banner"`
	ServerFlags        uint32      `json:"server_flags"`
	ChannelID          string      `json:"channel_id"`
	ChannelName        string      `json:"channel_name"`
	ChannelDescription string      `json:"channel_description"`
	UserName           string      `json:"user_name"`
	UserAvatar         *Attachment `json:"user_avatar"`
	MemberCount        uint64      `json:"member_count"`
}

type InviteCreate

type InviteCreate struct {
	Type InviteType `json:"type"`

	// ID is the code of the invite
	ID      string `json:"_id"`
	Server  string `json:"server"`
	Creator string `json:"creator"`
	Channel string `json:"channel"`
}

InviteCreate seems deprecated/no longer documented todo: remove in the future

type InviteJoin

type InviteJoin struct {
	Type     InviteType `json:"type"`
	Channels []*Channel
	Server   *Server `json:"server"`
}

type InviteType

type InviteType string
const (
	InviteTypeServer InviteType = "Server"
	InviteTypeGroup  InviteType = "Group"
)

type LoginData

type LoginData struct {
	Email        string `json:"email"`
	Password     string `json:"password"`
	FriendlyName string `json:"friendly_name"`
}

type LoginResponse

type LoginResponse struct {
	Result       string              `json:"result"`
	ID           string              `json:"_id"`
	UserID       string              `json:"user_id"`
	Token        string              `json:"token"`
	Name         string              `json:"name"`
	Subscription WebpushSubscription `json:"subscription"`
}

type MFA

type MFA struct {
	// Unvalidated or authorised MFA ticket; used to resolve the correct account
	MfaTicket string `json:"mfa_ticket"`

	// MFA response
	MfaResponse MFAResponse `json:"mfa_response"`

	// Friendly name used for the session
	FriendlyName string `json:"friendly_name"`
}

type MFAResponse

type MFAResponse struct {
	Password string `json:"password"`
}

type MemberCompositeID

type MemberCompositeID struct {
	User   string `json:"user"`
	Server string `json:"server"`
}

func (MemberCompositeID) Mention

func (m MemberCompositeID) Mention() string

type Message

type Message struct {
	ID          string          `json:"_id"`
	Nonce       string          `json:"nonce"`
	Channel     string          `json:"channel"`
	Author      string          `json:"author"`
	Webhook     *MessageWebhook `json:"webhook"`
	Content     string          `json:"content"`
	System      *MessageSystem  `json:"system"`
	Attachments []*Attachment   `json:"attachments"`
	Edited      time.Time       `json:"edited"`
	Embeds      []*MessageEmbed `json:"embeds"`
	Mentions    []string        `json:"mentions"`
	Replies     []string        `json:"replies"`

	// Map of emoji ID to array of user ID who reacted to it
	Reactions map[string][]string `json:"reactions"`

	Interactions *MessageInteractions `json:"interactions"`
	Masquerade   *MessageMasquerade   `json:"masquerade"`
}

Message contains information about a message.

type MessageEditData

type MessageEditData struct {
	Content string          `json:"content,omitempty"`
	Embeds  []*MessageEmbed `json:"embeds,omitempty"`
}

type MessageEdited

type MessageEdited struct {
	Date int `json:"$date"`
}

type MessageEmbed

type MessageEmbed struct {
	Type        string               `json:"type"`
	URL         string               `json:"url,omitempty"`
	OriginalURL string               `json:"original_url,omitempty"`
	Special     *MessageEmbedSpecial `json:"special,omitempty"`
	Title       string               `json:"title,omitempty"`
	Description string               `json:"description,omitempty"`
	Image       *MessageEmbedImage   `json:"image,omitempty"`
	Video       *MessageEmbedVideo   `json:"video,omitempty"`
	SiteName    string               `json:"site_name,omitempty"`
	IconURL     string               `json:"icon_url,omitempty"`
	Colour      string               `json:"colour,omitempty"`
}

type MessageEmbedImage

type MessageEmbedImage struct {
	Size   string `json:"size"`
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

type MessageEmbedSpecial

type MessageEmbedSpecial struct {
	Type      MessageEmbedSpecialType `json:"type"`
	ID        string                  `json:"id"`
	Timestamp time.Time               `json:"timestamp,omitempty"`

	// Identifies the type of content for types: Lightspeed, Twitch, Spotify, and Bandcamp
	ContentType string `json:"content_type"`
}

type MessageEmbedSpecialType

type MessageEmbedSpecialType string

type MessageEmbedVideo

type MessageEmbedVideo struct {
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

type MessageInteractions

type MessageInteractions struct {
	Reactions []string `json:"reactions"`

	// Whether reactions should be restricted to the given list
	RestrictReactions bool `json:"restrict_reactions"`
}

type MessageMasquerade

type MessageMasquerade struct {
	Name   string `json:"name,omitempty"`
	Avatar string `json:"avatar,omitempty"`
	Colour string `json:"colour,omitempty"`
}

type MessageReplies

type MessageReplies struct {
	ID      string `json:"id"`
	Mention bool   `json:"mention"`
}

type MessageSend

type MessageSend struct {
	Content      string               `json:"content"`
	Attachments  []string             `json:"attachments,omitempty"`
	Replies      []*MessageReplies    `json:"replies,omitempty"`
	Embeds       []*MessageEmbed      `json:"embeds,omitempty"`
	Masquerade   *MessageMasquerade   `json:"masquerade,omitempty"`
	Interactions *MessageInteractions `json:"interactions,omitempty"`
}

MessageSend is used for sending messages to channels

type MessageSystem

type MessageSystem struct {
	Type MessageSystemType `json:"type"`
	ID   string            `json:"id"`
}

type MessageSystemType

type MessageSystemType string
const (
	MessageSystemTypeText                      MessageSystemType = "text"
	MessageSystemTypeUserAdded                 MessageSystemType = "user_added"
	MessageSystemTypeUserRemove                MessageSystemType = "user_remove"
	MessageSystemTypeUserJoined                MessageSystemType = "user_joined"
	MessageSystemTypeUserLeft                  MessageSystemType = "user_left"
	MessageSystemTypeUserKicked                MessageSystemType = "user_kicked"
	MessageSystemTypeUserBanned                MessageSystemType = "user_banned"
	MessageSystemTypeChannelRenamed            MessageSystemType = "channel_renamed"
	MessageSystemTypeChannelDescriptionChanged MessageSystemType = "channel_description_changed"
	MessageSystemTypeChannelIconChanged        MessageSystemType = "channel_icon_changed"
	MessageSystemTypeChannelOwnershipChanged   MessageSystemType = "channel_ownership_changed"
)

type MessageWebhook

type MessageWebhook struct {
	Name   string `json:"name"`
	Avatar string `json:"avatar"`
}

type MutualFriendsAndServersResponse

type MutualFriendsAndServersResponse struct {
	Users   []string `json:"users"`
	Servers []string `json:"servers"`
}

type Onboarding

type Onboarding struct {
	Onboarding bool `json:"onboarding"`
}

type OnboardingCompleteData

type OnboardingCompleteData struct {
	Username string `json:"username"`
}

type PasswordResetConfirmData

type PasswordResetConfirmData struct {
	Token    string `json:"token"`
	Password string `json:"password"`

	// Whether to log out of all sessions
	RemoveSessions bool `json:"remove_sessions"`
}

type PermissionAD

type PermissionAD struct {
	Allow uint `json:"a"`
	Deny  uint `json:"d"`
}

PermissionAD describes the default allowed and denied permissions

type PermissionsSetDefaultData

type PermissionsSetDefaultData struct {
	Permissions uint `json:"permissions"`
}

type PublicBot

type PublicBot struct {
	ID          string      `json:"_id"`
	Username    string      `json:"username"`
	Avatar      *Attachment `json:"avatar"`
	Description string      `json:"description"`
}

type Ratelimiter

type Ratelimiter struct {
	sync.Mutex

	// Interval to clean-up stale ratelimit buckets.
	// Higher values will result in higher memory usage, but lower CPU, and vice versa.
	CleanInterval time.Duration
	// contains filtered or unexported fields
}

Ratelimiter silently ensures that requests do not exceed the ratelimit set by Revolt

type RootData

type RootData struct {
	Revolt   string `json:"revolt"`
	Features struct {
		Captcha struct {
			Enabled bool   `json:"enabled"`
			Key     string `json:"key"`
		} `json:"captcha"`
		Email      bool `json:"email"`
		InviteOnly bool `json:"invite_only"`
		Autumn     struct {
			Enabled bool   `json:"enabled"`
			URL     string `json:"url"`
		} `json:"autumn"`
		January struct {
			Enabled bool   `json:"enabled"`
			URL     string `json:"url"`
		} `json:"january"`
		Voso struct {
			Enabled bool   `json:"enabled"`
			URL     string `json:"url"`
			WS      string `json:"ws"`
		} `json:"voso"`
	} `json:"features"`
	WS    string `json:"ws"`
	App   string `json:"app"`
	VapID string `json:"vapid"`
	Build struct {
		CommitSha       string `json:"commit_sha"`
		CommitTimestamp string `json:"commit_timestamp"`
		SemVer          string `json:"semver"`
		OriginURL       string `json:"origin_url"`
		Timestamp       string `json:"timestamp"`
	} `json:"build"`
}

type Server

type Server struct {
	ID             string               `json:"_id"`
	Owner          string               `json:"owner"`
	Name           string               `json:"name"`
	Description    string               `json:"description"`
	Channels       []string             `json:"channels"`
	Categories     []*ServerCategory    `json:"categories"`
	SystemMessages ServerSystemMessages `json:"system_messages"`

	// Roles is a map of role ID to ServerRole structs.
	Roles map[string]*ServerRole `json:"roles"`

	DefaultPermissions *uint       `json:"default_permissions"`
	Icon               *Attachment `json:"icon"`
	Banner             *Attachment `json:"banner"`
	Flags              *uint       `json:"flags"`
	NSFW               *bool       `json:"nsfw"`
	Analytics          *bool       `json:"analytics"`
	Discoverable       *bool       `json:"discoverable"`
}

Server holds information about a server.

type ServerBan

type ServerBan struct {
	ID     MemberCompositeID `json:"_id"`
	Reason string            `json:"reason"`
}

type ServerBans

type ServerBans struct {
	Users []*User      `json:"users"`
	Bans  []*ServerBan `json:"bans"`
}

type ServerCategory

type ServerCategory struct {
	ID       string   `json:"id"`
	Title    string   `json:"title"`
	Channels []string `json:"channels"`
}

ServerCategory Server categories struct.

type ServerChannelCreateData

type ServerChannelCreateData struct {
	Type        ServerChannelCreateDataType `json:"type"`
	Name        string                      `json:"name"`
	Description string                      `json:"description,omitempty"`
	NSFW        bool                        `json:"nsfw,omitempty"`
}

type ServerChannelCreateDataType

type ServerChannelCreateDataType string
const (
	ServerChannelCreateDataTypeText  ServerChannelCreateDataType = "Text"
	ServerChannelCreateDataTypeVoice ServerChannelCreateDataType = "Voice"
)

type ServerCreateData

type ServerCreateData struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

type ServerEditData

type ServerEditData struct {
	Name           string                 `json:"name,omitempty"`
	Description    string                 `json:"description,omitempty"`
	Icon           string                 `json:"icon,omitempty"`
	Banner         string                 `json:"banner,omitempty"`
	Categories     []*ServerCategory      `json:"categories,omitempty"`
	SystemMessages *ServerSystemMessages  `json:"system_messages,omitempty"`
	Flags          int                    `json:"flags,omitempty"`
	Discoverable   *bool                  `json:"discoverable,omitempty"`
	Analytics      *bool                  `json:"analytics,omitempty"`
	Remove         []ServerEditDataRemove `json:"remove"`
}

type ServerEditDataRemove

type ServerEditDataRemove string
const (
	ServerEditDataRemoveIcon           ServerEditDataRemove = "Icon"
	ServerEditDataRemoveBanner         ServerEditDataRemove = "Banner"
	ServerEditDataRemoveCategories     ServerEditDataRemove = "Categories"
	ServerEditDataRemoveDescription    ServerEditDataRemove = "Description"
	ServerEditDataRemoveSystemMessages ServerEditDataRemove = "SystemMessages"
)

type ServerMember

type ServerMember struct {
	ID       MemberCompositeID `json:"_id"`
	JoinedAt time.Time         `json:"joined_at"`
	Nickname *string           `json:"nickname"`
	Avatar   *Attachment       `json:"avatar"`
	Roles    []string          `json:"roles"`
	Timeout  *time.Time        `json:"timeout"`
}

func (ServerMember) Mention

func (m ServerMember) Mention() string

Mention is a proxy function that calls ServerMember.ID.Mention().

type ServerMemberEditData

type ServerMemberEditData struct {
	Nickname string    `json:"nickname,omitempty"`
	Avatar   string    `json:"avatar,omitempty"`
	Roles    []string  `json:"roles,omitempty"`
	Timeout  time.Time `json:"timeout,omitempty"`
	Remove   []string  `json:"remove,omitempty"`
}

type ServerMembers

type ServerMembers struct {
	Members []*ServerMember `json:"members"`
	Users   []*User         `json:"users"`
}

type ServerRole

type ServerRole struct {
	Name        string        `json:"name"`
	Permissions *PermissionAD `json:"permissions"`
	Colour      string        `json:"colour"`
	Hoist       bool          `json:"hoist"`
	Rank        int           `json:"rank"`
}

type ServerRoleCreateData

type ServerRoleCreateData struct {
	Name string `json:"name"`
	Rank int    `json:"rank"`
}

type ServerRoleEditData

type ServerRoleEditData struct {
	Name   string   `json:"name,omitempty"`
	Colour string   `json:"colour,omitempty"`
	Hoist  *bool    `json:"hoist"`
	Rank   *int     `json:"rank"`
	Remove []string `json:"remove,omitempty"`
}

type ServerSystemMessages

type ServerSystemMessages struct {
	UserJoined string `json:"user_joined,omitempty"`
	UserLeft   string `json:"user_left,omitempty"`
	UserKicked string `json:"user_kicked,omitempty"`
	UserBanned string `json:"user_banned,omitempty"`
}

ServerSystemMessages System messages struct.

type Session

type Session struct {

	// Authorisation token
	Token string

	// The websocket connection
	Socket *gws.Conn

	// HTTP client used for the REST API
	HTTP *http.Client

	// Ratelimiter for the REST API
	Ratelimiter *Ratelimiter

	// State is a central store for all data received from the API
	State *State

	// The user agent used for REST APIs
	UserAgent string

	// Indicates whether the websocket is connected
	Connected bool

	// Whether the websocket should reconnect when the connection drops
	ShouldReconnect bool

	// Defines a custom compression algorithm for the websocket
	// By default, compression is enabled at the fastest level (1) for >=512 byte payloads
	// To enable, set gws.PermessageDeflate.Enabled true
	CustomCompression *gws.PermessageDeflate

	// Interval between sending heartbeats. Lower values update the latency faster
	// Values too high (~100 seconds) may cause Cloudflare to drop the connection
	HeartbeatInterval time.Duration

	// Heartbeat counter
	HeartbeatCount int64

	// Interval between reconnecting, if connection fails
	ReconnectInterval time.Duration

	// Last time a ping was sent
	LastHeartbeatSent time.Time

	// Last time a ping was received
	LastHeartbeatAck time.Time
	// contains filtered or unexported fields
}

Session represents a connection to the Revolt API.

func New

func New(token string) *Session

func (*Session) Account

func (s *Session) Account() (account *Account, err error)

func (*Session) AccountChangeEmail

func (s *Session) AccountChangeEmail(data AccountChangeEmailData) error

func (*Session) AccountChangePassword

func (s *Session) AccountChangePassword(data AccountChangePasswordData) error

func (*Session) AccountCreate

func (s *Session) AccountCreate(data AccountCreateData) error

func (*Session) AccountDelete

func (s *Session) AccountDelete() error

func (*Session) AccountDeleteConfirm

func (s *Session) AccountDeleteConfirm(data AccountDeleteConfirmData) error

func (*Session) AccountDisable

func (s *Session) AccountDisable() error

func (*Session) AccountReverify

func (s *Session) AccountReverify(data AccountReverifyData) error

func (*Session) AddHandler

func (s *Session) AddHandler(handler any)

AddHandler registers an event handler based on function signature

func (*Session) AttachmentUpload

func (s *Session) AttachmentUpload(file *File) (attachment *FileAttachment, err error)

func (*Session) Bot

func (s *Session) Bot(bID string) (bot *FetchedBot, err error)

Bot fetches details of a bot you own by its ID

func (*Session) BotCreate

func (s *Session) BotCreate(data BotCreateData) (bot *Bot, err error)

BotCreate creates a bot based on the data provided

func (*Session) BotDelete

func (s *Session) BotDelete(bID string) error

func (*Session) BotEdit

func (s *Session) BotEdit(id string, data BotEditData) (bot *Bot, err error)

func (*Session) BotInvite

func (s *Session) BotInvite(bID string, data BotInviteData) (err error)

BotInvite invites a bot by its ID to a server or group

func (*Session) BotPublic

func (s *Session) BotPublic(bID string) (bot *PublicBot, err error)

BotPublic fetches a public bot by its ID

func (*Session) Bots

func (s *Session) Bots() (bots *FetchedBots, err error)

Bots returns a list of bots for the current user

func (*Session) Channel

func (s *Session) Channel(cID string) (channel *Channel, err error)

Channel fetches a channel using an API call

func (*Session) ChannelBeginTyping

func (s *Session) ChannelBeginTyping(cID string) (err error)

ChannelBeginTyping is a websocket method to start typing in a channel

func (*Session) ChannelDelete

func (s *Session) ChannelDelete(cID string) (err error)

func (*Session) ChannelEdit

func (s *Session) ChannelEdit(cID string, data ChannelEditData) (channel *Channel, err error)

func (*Session) ChannelEndTyping

func (s *Session) ChannelEndTyping(cID string) (err error)

ChannelEndTyping is a websocket method to stop typing in a channel

func (*Session) ChannelInviteCreate

func (s *Session) ChannelInviteCreate(cID string) (invite *InviteCreate, err error)

func (*Session) ChannelMessage

func (s *Session) ChannelMessage(cID, mID string) (message *Message, err error)

func (*Session) ChannelMessageDelete

func (s *Session) ChannelMessageDelete(cID, mID string) error

func (*Session) ChannelMessageDeleteBulk

func (s *Session) ChannelMessageDeleteBulk(cID string, messages ChannelMessageBulkDeleteData) error

func (*Session) ChannelMessageEdit

func (s *Session) ChannelMessageEdit(cID, mID string, data MessageEditData) (message *Message, err error)

func (*Session) ChannelMessageReactionClear

func (s *Session) ChannelMessageReactionClear(cID, mID string) (err error)

ChannelMessageReactionClear clears all reactions on a message

func (*Session) ChannelMessageReactionCreate

func (s *Session) ChannelMessageReactionCreate(cID, mID, eID string) (err error)

ChannelMessageReactionCreate adds a reaction (emoji ID) to a message

func (*Session) ChannelMessageReactionDelete

func (s *Session) ChannelMessageReactionDelete(cID, mID, eID string) (err error)

ChannelMessageReactionDelete deletes a singular reaction on a message

func (*Session) ChannelMessageSend

func (s *Session) ChannelMessageSend(cID string, data MessageSend) (message *Message, err error)

func (*Session) ChannelMessages

func (s *Session) ChannelMessages(cID string, params ...ChannelMessagesParams) (messages []*Message, err error)

func (*Session) ChannelPermissionsSet

func (s *Session) ChannelPermissionsSet(sID, cID string, data PermissionAD) (err error)

func (*Session) ChannelPermissionsSetDefault

func (s *Session) ChannelPermissionsSetDefault(sID string, data PermissionAD) (err error)

func (*Session) ChannelWebhooks

func (s *Session) ChannelWebhooks(cID string) (webhooks []*Webhook, err error)

func (*Session) ChannelWebhooksCreate

func (s *Session) ChannelWebhooksCreate(cID string, data WebhookCreate) (webhook *Webhook, err error)

func (*Session) Close

func (s *Session) Close() error

Close the websocket.

func (*Session) DirectMessageCreate

func (s *Session) DirectMessageCreate(uID string) (channel *Channel, err error)

DirectMessageCreate opens a direct message channel with a user Will return an error "MissingPermission" "SendMessage" if you are not friends or blocked

func (*Session) DirectMessages

func (s *Session) DirectMessages() (channels []*Channel, err error)

DirectMessages returns a list of direct message channels.

func (*Session) Emoji

func (s *Session) Emoji(eID string) (emoji *Emoji, err error)

func (*Session) EmojiCreate

func (s *Session) EmojiCreate(eID string, data EmojiCreateData) (emoji *Emoji, err error)

func (*Session) EmojiDelete

func (s *Session) EmojiDelete(eID string) error

func (*Session) FriendAdd

func (s *Session) FriendAdd(username string) (user *User, err error)

FriendAdd sends or accepts a friend Request.

func (*Session) FriendDelete

func (s *Session) FriendDelete(username string) (user *User, err error)

FriendDelete removes a friend or declines a friend Request.

func (*Session) GroupCreate

func (s *Session) GroupCreate(data GroupCreateData) (group *Group, err error)

GroupCreate creates a group based on the data provided "Users" field is a list of user IDs that will be in the group

func (*Session) GroupMemberAdd

func (s *Session) GroupMemberAdd(cID, mID string) (err error)

func (*Session) GroupMemberDelete

func (s *Session) GroupMemberDelete(cID, mID string) (err error)

func (*Session) GroupMembers

func (s *Session) GroupMembers(cID string) (users []*User, err error)

func (*Session) Invite

func (s *Session) Invite(iID string) (invite *Invite, err error)

func (*Session) InviteDelete

func (s *Session) InviteDelete(iID string) (err error)

func (*Session) InviteJoin

func (s *Session) InviteJoin(iID string) (invite *Invite, err error)

func (*Session) Latency

func (s *Session) Latency() time.Duration

Latency returns the websocket latency

func (*Session) Login

func (s *Session) Login(data LoginData) (mfa LoginResponse, err error)

Login as a regular user instead of bot. Friendly name is used to identify the session via MFA

func (*Session) Logout

func (s *Session) Logout() error

func (*Session) MessageAck

func (s *Session) MessageAck(channelID, messageID string) (err error)

func (*Session) Onboarding

func (s *Session) Onboarding() (onboarding Onboarding, err error)

Onboarding returns whether the current account requires onboarding or whether you can continue to send requests as usual

func (*Session) OnboardingComplete

func (s *Session) OnboardingComplete(data OnboardingCompleteData) error

OnboardingComplete sets a new username, completes onboarding and allows a user to start using Revolt.

func (*Session) Open

func (s *Session) Open() (err error)

Open determines the websocket URL and establishes a connection. It also detects if you are logged in as a user or a bot.

func (*Session) PasswordReset

func (s *Session) PasswordReset(data AccountReverifyData) error

PasswordReset requests a password reset, which is sent to the email provided

func (*Session) PasswordResetConfirm

func (s *Session) PasswordResetConfirm(data PasswordResetConfirmData) error

PasswordResetConfirm confirms a password reset

func (*Session) PermissionsSet

func (s *Session) PermissionsSet(sID, rID string, data PermissionAD) (err error)

func (*Session) PermissionsSetDefault

func (s *Session) PermissionsSetDefault(sID string, data PermissionsSetDefaultData) (err error)

PermissionsSetDefault sets the permissions of a role in a server

func (*Session) PushSubscribe

func (s *Session) PushSubscribe(data WebpushSubscription) error

func (*Session) PushUnsubscribe

func (s *Session) PushUnsubscribe(data WebpushSubscription) error

func (*Session) Relationships

func (s *Session) Relationships() (relationships []*UserRelations, err error)

Relationships returns a list of relationships for the current user

func (*Session) Request

func (s *Session) Request(method, destination string, data, result any) error

Request sends a JSON Request with "method" to a destination URL - "result" will be used to decode the response into, and - "data" is the Request body which wil be encoded as JSON

- If the "data" is a *File, it will be uploaded as a multipart form This function automatically handles rate-limiting and response status codes

func (*Session) Selfbot

func (s *Session) Selfbot() bool

Selfbot returns whether the session is a selfbot

func (*Session) Server

func (s *Session) Server(id string) (server *Server, err error)

Server fetches a server by its ID

func (*Session) ServerAck

func (s *Session) ServerAck(serverID string) (err error)

func (*Session) ServerBans

func (s *Session) ServerBans(sID string) (bans []*ServerBans, err error)

func (*Session) ServerChannelCreate

func (s *Session) ServerChannelCreate(sID string, data ServerChannelCreateData) (channel *Channel, err error)

func (*Session) ServerCreate

func (s *Session) ServerCreate(data ServerCreateData) (server *Server, err error)

ServerCreate creates a server based on the data provided

func (*Session) ServerDelete

func (s *Session) ServerDelete(sID string) error

func (*Session) ServerEdit

func (s *Session) ServerEdit(id string, data ServerEditData) (server *Server, err error)

func (*Session) ServerMember

func (s *Session) ServerMember(sID, mID string) (member *ServerMember, err error)

func (*Session) ServerMemberBan

func (s *Session) ServerMemberBan(sID, mID string) (err error)

func (*Session) ServerMemberDelete

func (s *Session) ServerMemberDelete(sID, mID string) (err error)

func (*Session) ServerMemberEdit

func (s *Session) ServerMemberEdit(sID, mID string, data ServerMemberEditData) (member *ServerMember, err error)

func (*Session) ServerMemberUnban

func (s *Session) ServerMemberUnban(sID, mID string) (err error)

func (*Session) ServerMembers

func (s *Session) ServerMembers(sID string) (members *ServerMembers, err error)

func (*Session) ServerRoleDelete

func (s *Session) ServerRoleDelete(sID, rID string) (err error)

func (*Session) ServersRole

func (s *Session) ServersRole(sID, rID string) (role *ServerRole, err error)

func (*Session) ServersRoleCreate

func (s *Session) ServersRoleCreate(sID string, data ServerRoleCreateData) (role *ServerRole, err error)

func (*Session) ServersRoleEdit

func (s *Session) ServersRoleEdit(sID, rID string, data ServerRoleEditData) (role *ServerRole, err error)

func (*Session) SessionEdit

func (s *Session) SessionEdit(id string, data SessionEditData) (session SessionEditData, err error)

func (*Session) Sessions

func (s *Session) Sessions() (sessions []*Sessions, err error)

func (*Session) SessionsDelete

func (s *Session) SessionsDelete(id string) error

SessionsDelete invalidates a session with the provided ID

func (*Session) SessionsDeleteAll

func (s *Session) SessionsDeleteAll(revokeSelf bool) error

SessionsDeleteAll invalidates all sessions, including this one if revokeSelf is true

func (*Session) SetUsername

func (s *Session) SetUsername(data UsernameData) (user *User, err error)

func (*Session) SyncSettingsFetch

func (s *Session) SyncSettingsFetch(payload SyncSettingsFetchData) (data *SyncSettingsData, err error)

func (*Session) SyncSettingsSet

func (s *Session) SyncSettingsSet(payload SyncSettingsData) error

func (*Session) SyncUnreads

func (s *Session) SyncUnreads() (data []SyncUnread, err error)

func (*Session) Uptime

func (s *Session) Uptime() time.Duration

Uptime returns the approximate duration the websocket has been connected for

func (*Session) User

func (s *Session) User(uID string) (user *User, err error)

User fetches a user by their ID To fetch self, supply "@me" as the ID

func (*Session) UserBlock

func (s *Session) UserBlock(uID string) (user *User, err error)

func (*Session) UserDefaultAvatar

func (s *Session) UserDefaultAvatar(uID string) (binary []byte, err error)

func (*Session) UserEdit

func (s *Session) UserEdit(uID string, data UserEditData) (user *User, err error)

func (*Session) UserFlags

func (s *Session) UserFlags(uID string) (flags int, err error)

func (*Session) UserMutual

func (s *Session) UserMutual(uID string) (mutual []*MutualFriendsAndServersResponse, err error)

func (*Session) UserProfile

func (s *Session) UserProfile(uID string) (profile *UserProfile, err error)

func (*Session) UserUnblock

func (s *Session) UserUnblock(uID string) (user *User, err error)

func (*Session) VerifyEmail

func (s *Session) VerifyEmail(code string) (ticket ChangeEmail, err error)

func (*Session) WriteSocket

func (s *Session) WriteSocket(data any) error

WriteSocket writes data to the websocket in JSON

type SessionEditData

type SessionEditData struct {
	FriendlyName string `json:"friendly_name"`
}

type Sessions

type Sessions struct {
	ID   string `json:"_id"`
	Name string `json:"name"`
}

type State

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

func (*State) Channel

func (s *State) Channel(id string) *Channel

func (*State) ChannelPermissions

func (s *State) ChannelPermissions(user *User, channel *Channel) (uint, error)

ChannelPermissions is a utility function to calculate permissions for a user in a Channel

func (*State) Emoji

func (s *State) Emoji(id string) *Emoji

func (*State) Member

func (s *State) Member(uID, sID string) *ServerMember

func (*State) Members

func (s *State) Members(sID string) []*ServerMember

func (*State) Role

func (s *State) Role(sID, rID string) *ServerRole

func (*State) Self

func (s *State) Self() *User

func (*State) Server

func (s *State) Server(id string) *Server

func (*State) ServerPermissions

func (s *State) ServerPermissions(user *User, server *Server) (uint, error)

ServerPermissions is a utility function to calculate permissions for a user in a Server

func (*State) TrackAPICalls

func (s *State) TrackAPICalls() bool

func (*State) TrackBulkAPICalls

func (s *State) TrackBulkAPICalls() bool

func (*State) TrackChannels

func (s *State) TrackChannels() bool

func (*State) TrackEmojis

func (s *State) TrackEmojis() bool

func (*State) TrackMembers

func (s *State) TrackMembers() bool

func (*State) TrackServers

func (s *State) TrackServers() bool

func (*State) TrackUsers

func (s *State) TrackUsers() bool

func (*State) TrackWebhooks

func (s *State) TrackWebhooks() bool

func (*State) User

func (s *State) User(id string) *User

func (*State) Webhook

func (s *State) Webhook(id string) *Webhook

type SyncSettingsData

type SyncSettingsData map[string]UpdateTuple

type SyncSettingsFetchData

type SyncSettingsFetchData struct {
	Keys []string `json:"keys"`
}

type SyncUnread

type SyncUnread struct {
	ID       CompositeChannelID `json:"_id"`
	LastID   string             `json:"last_id"`
	Mentions []string           `json:"mentions"`
}

type Ticket

type Ticket struct {
	ID           string `json:"_id"`
	AccountID    string `json:"account_id"`
	Token        string `json:"token"`
	Validated    bool   `json:"validated"`
	Authorised   bool   `json:"authorised"`
	LastTOTPCode string `json:"last_totp_code"`
}

type UpdateTuple

type UpdateTuple struct {
	Timestamp time.Time       `json:"0"`
	Value     json.RawMessage `json:"1"` // Enjoy using this.
}

type User

type User struct {
	ID            string           `json:"_id"`
	Username      string           `json:"username"`
	Discriminator string           `json:"discriminator"`
	DisplayName   string           `json:"display_name"`
	Avatar        *Attachment      `json:"avatar"`
	Relations     []*UserRelations `json:"relations"`

	// Bitfield of user badges
	Badges int `json:"badges"`

	// User's active status
	Status *UserStatus `json:"status"`

	// todo: potentially deprecated
	Profile *UserProfile `json:"profile"`

	// Enum of user flags
	Flags *int `json:"flags"`

	// Racism?!1
	Privileged bool `json:"privileged"`

	// Bot information, if the user is a bot
	Bot *Bot `json:"bot"`

	// Your relationship to this user
	Relationship UserRelationshipType `json:"relationship"`

	// Whether this user is currently online
	Online bool `json:"online"`
}

func (*User) Mention

func (s *User) Mention() string

type UserEditData

type UserEditData struct {
	DisplayName string       `json:"display_name,omitempty"`
	Avatar      string       `json:"avatar,omitempty"`
	Status      *UserStatus  `json:"status,omitempty"`
	Profile     *UserProfile `json:"profile,omitempty"`
	Badges      *int         `json:"badges,omitempty"`
	Flags       *int         `json:"flags,omitempty"`
	Remove      []string     `json:"remove,omitempty"`
}

type UserProfile

type UserProfile struct {
	Content    string      `json:"content,omitempty"`
	Background *Attachment `json:"background,omitempty"`
}

type UserRelations

type UserRelations struct {
	ID     string               `json:"_id"`
	Status UserRelationshipType `json:"status"`
}

type UserRelationshipType

type UserRelationshipType string

type UserSettings

type UserSettings struct {
	Updated int
	Data    json.RawMessage
}

UserSettings TODO: This does not get decoded due to API sending tuples for some god-forsaken reason

type UserStatus

type UserStatus struct {
	Text     string             `json:"text,omitempty"`
	Presence UserStatusPresence `json:"presence"`
}

type UserStatusPresence

type UserStatusPresence string
const (
	UserStatusPresenceOnline    UserStatusPresence = "Online"
	UserStatusPresenceIdle      UserStatusPresence = "Idle"
	UserStatusPresenceFocus     UserStatusPresence = "Focus"
	UserStatusPresenceBusy      UserStatusPresence = "Busy"
	UserStatusPresenceInvisible UserStatusPresence = "Invisible"
)

type UsernameData

type UsernameData struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type Webhook

type Webhook struct {
	ID        string      `json:"id"`
	Name      string      `json:"name"`
	Avatar    *Attachment `json:"avatar"`
	ChannelID string      `json:"channel_id"`
	Token     string      `json:"token"`
}

type WebhookCreate

type WebhookCreate struct {
	Name   string `json:"name"`
	Avatar string `json:"avatar,omitempty"`
}

type WebpushSubscription

type WebpushSubscription struct {

	// The URL to send the notification to
	Endpoint string `json:"endpoint"`

	// P-256 Diffie-Hellman public key
	P256DH string `json:"p256dh"`

	// Auth secret; used to authenticate the origin of the notification
	Auth string `json:"auth"`
}

type WebsocketChannelTyping

type WebsocketChannelTyping struct {
	Type    WebsocketMessageType `json:"type"`
	Channel string               `json:"channel"`
}

type WebsocketMessageAuthenticate

type WebsocketMessageAuthenticate struct {
	Type  WebsocketMessageType `json:"type"`
	Token string               `json:"token"`
}

type WebsocketMessagePing

type WebsocketMessagePing struct {
	Type WebsocketMessageType `json:"type"`
	Data int64                `json:"data"`
}

type WebsocketMessageType

type WebsocketMessageType string
const (
	WebsocketKeepAlivePeriod = 60 * time.Second

	WebsocketMessageTypeAuthenticate WebsocketMessageType = "Authenticate"
	WebsocketMessageTypeHeartbeat    WebsocketMessageType = "Ping"
	WebsocketMessageTypeBeginTyping  WebsocketMessageType = "BeginTyping"
	WebsocketMessageTypeEndTyping    WebsocketMessageType = "EndTyping"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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