gorevolt

package module
v0.0.0-...-34cef66 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2022 License: GPL-3.0 Imports: 15 Imported by: 0

README

GoRevolt (Revolt.chat API Library)

GoRevolt is a revolt.chat API library allowing you to write fast and large scale bots in Go. Optimized for high performance and stability. Discord.js devs will right at home with this Revolt.chat library.

Revolt.chat image

Under Active Development

Please come back after a stable release.

Road Map

  1. Implement all end points for Delta.
  2. Implement all event handlers for Bonfire.
  3. Fast customisable caching layer.
  4. Fast data rich API for building bots.
  5. Reply filter (await user response in channel, no prefix required).

Robust & Stable

Written with concurrency in mind. Built in unit tests ensure the library is operating as expected.

API tests require these environment variables to be set.

gorevolt_test_token=
gorevolt_test_channel=
# User should be the ID of the bot user and the username should be "GoRevolt"
gorevolt_test_user=

Non interactive tests environment variables

gorevolt_test_interactive=true

Interactive websockets tests

go test -v ./...

Run the unit tests your self by using the command above.

Events

List of currently implemented events. More to come soon.

  • OnReady
  • OnMessage
  • OnMessageUpdate
  • OnMessageAppend
  • OnMessageDelete
  • OnChannelCreate
  • OnChannelUpdate
  • OnChannelDelete
  • OnChannelGroupJoin
  • OnChannelGroupLeave
  • OnChannelStartTyping
  • OnChannelStopTyping
  • OnChannelAck
  • OnServerCreate
  • OnServerUpdate
  • OnServerDelete
  • OnServerMemberUpdate
  • OnServerMemberJoin
  • OnServerMemberLeave
  • OnServerRoleUpdate
  • OnServerRoleDelete
  • OnUserUpdate
  • OnUserRelationship
  • OnUserRelationship
  • OnEmojiCreate
  • OnEmojiDelete

Documentation

Index

Constants

View Source
const (
	RevoltAPI       = "https://api.revolt.chat"
	RevoltWebsocket = "wss://ws.revolt.chat"
)
View Source
const (
	RouteUsersMe         = "/users/@me"
	RouteUsers           = "/users/{0}"
	RouteServerMembers   = "/servers/{0}/members"
	RouteChannelMessages = "/channels/{0}/messages"
	RouteChannel         = "/channels/{0}"
)

Variables

View Source
var (
	ErrRateLimit    = errors.New("429: rate limit reached")
	ErrUnauthorised = errors.New("unauthorised request")
	ErrForbidden    = errors.New("access denied you do not have permission to perform that action")
	ErrUnknown      = errors.New("unknown error occurred")
	ErrNotFound     = errors.New("resource not found")
)
View Source
var (
	ErrAuthenticationFailed = errors.New("authentication failed")
)

Functions

This section is empty.

Types

type ArrayCache

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

ArrayCache uses a array to store users, servers etc.

Results in a reduced memory footprint but slower performance.

func (*ArrayCache) GetChannel

func (c *ArrayCache) GetChannel(id string) *Channel

func (*ArrayCache) GetServer

func (c *ArrayCache) GetServer(id string) *Server

func (*ArrayCache) GetUser

func (c *ArrayCache) GetUser(id string) *User

func (*ArrayCache) ListServers

func (c *ArrayCache) ListServers() []*Server

func (*ArrayCache) PutChannel

func (c *ArrayCache) PutChannel(channel *Channel)

func (*ArrayCache) PutServer

func (c *ArrayCache) PutServer(s *Server)

func (*ArrayCache) PutUser

func (c *ArrayCache) PutUser(u *User)

type Cache

type Cache interface {
	GetUser(id string) *User
	PutUser(user *User)
	GetServer(id string) *Server
	ListServers() []*Server
	PutServer(server *Server)
	GetChannel(id string) *Channel
	PutChannel(channel *Channel)
}

func NewArrayCache

func NewArrayCache(usersHint, serversHint int) Cache

NewArrayCache creates a new cache layer using minimal memory.

user and server hint is used to preallocate memory to boost performance. It is better to be over generous than conservative.

type Category

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

type Channel

type Channel struct {
	ID                 string                 `json:"_id"`
	ChannelType        string                 `json:"channel_type"`
	ServerID           string                 `json:"server"`
	Name               string                 `json:"name"`
	Description        string                 `json:"description"`
	NFSW               bool                   `json:"nsfw"`
	DefaultPermissions Permissions            `json:"default_permissions"`
	RolePermissions    map[string]Permissions `json:"role_permissions"`
	LastMessageID      string                 `json:"last_message_id"`
}

func GetChannel

func GetChannel(c *Client, id string) (*Channel, error)

func (*Channel) SendMessage

func (channel *Channel) SendMessage(c *Client, content string) (*Message, error)

SendMessage will send message in the channel

func (*Channel) SendMessagef

func (channel *Channel) SendMessagef(c *Client, format string, a ...interface{}) (*Message, error)

SendMessagef will format the message being sent to the channel

func (*Channel) Server

func (channel *Channel) Server(c *Client) *Server

Server will provide the server object which the channel belongs to. If the server could not be found the result will be nil

type Client

type Client struct {
	User *User
	// contains filtered or unexported fields
}

Client maintains state for your logged in session

func New

func New(token string) *Client

New creates a new client but does not authenticate yet

func (*Client) Close

func (c *Client) Close() error

Close will disconnect you from Revolt

func (*Client) Connect

func (c *Client) Connect() error

Connect will establish a connection to the websocket server and authenticate your credentials

func (*Client) OnChannelCreate

func (c *Client) OnChannelCreate(h HandlerChannelCreate)

OnChannelCreate registers a channel create event handler

func (*Client) OnChannelDelete

func (c *Client) OnChannelDelete(h HandlerChannelDelete)

OnChannelDelete registers a channel delete event handler

func (*Client) OnChannelUpdate

func (c *Client) OnChannelUpdate(h HandlerChannelUpdate)

OnChannelUpdate registers a channel update event handler

func (*Client) OnMessage

func (c *Client) OnMessage(h HandlerMessage)

OnMessage registers a onMessage event handler

func (*Client) OnMessageUpdate

func (c *Client) OnMessageUpdate(h HandlerMessageUpdate)

OnMessage registers a onMessageUpdate event handler

func (*Client) OnReady

func (c *Client) OnReady(h HandlerReady)

OnReady registers a ready event handler

func (*Client) OnServerCreate

func (c *Client) OnServerCreate(h HandlerServerCreate)

OnServerCreate registers a server create event handler

func (*Client) OnServerUpdate

func (c *Client) OnServerUpdate(h HandlerServerUpdate)

OnServerCreate registers a server update event handler

func (*Client) SendMessage

func (c *Client) SendMessage(channel, content string) (*Message, error)

func (*Client) SetCache

func (c *Client) SetCache(cache Cache)

SetCache allows you to use custom caching layers. Solutions such as hash maps, Redis or even disk caches are possible.

func (*Client) UnregisterHandlers

func (c *Client) UnregisterHandlers()

UnregisterHandlers will reset all handlers and require new ones to be set.

type Embed

type Embed struct {
	IconURL     string `json:"icon_url"`
	URL         string `json:"url"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Media       string `json:"media"`
	Colour      string `json:"colour"`
}

type HandlerChannelCreate

type HandlerChannelCreate func(c *Client, channel *Channel)

type HandlerChannelDelete

type HandlerChannelDelete func(c *Client, channel *Channel)

type HandlerChannelUpdate

type HandlerChannelUpdate func(c *Client, old *Channel, new *Channel)

type HandlerMessage

type HandlerMessage func(c *Client, m *Message)

type HandlerMessageUpdate

type HandlerMessageUpdate func(c *Client, m *UpdatedMessage)

type HandlerReady

type HandlerReady func(c *Client, startup time.Duration)

type HandlerServerCreate

type HandlerServerCreate func(c *Client, server *Server)

type HandlerServerUpdate

type HandlerServerUpdate func(c *Client, old, new *Server)

type Masquerade

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

type Member

type Member struct {
	ID struct {
		Server string `json:"server"`
		User   string `json:"user"`
	} `json:"_id"`
	Nickname string `json:"nickname"`
	// TODO: add avatar to member
	Roles []string `json:"roles"`
}

type Message

type Message struct {
	ID        string   `json:"_id"`
	AuthorID  string   `json:"author_id"`
	ChannelID string   `json:"channel_id"`
	ServerID  string   `json:"server_id"`
	Channel   *Channel `json:"channel"`
	Author    *User    `json:"author"`
	Content   string   `json:"content"`
	// contains filtered or unexported fields
}

func (*Message) Reply

func (m *Message) Reply(content string) (*Message, error)

Reply will send a message within the same channel with that message as the reply.

func (*Message) Replyf

func (m *Message) Replyf(format string, a ...interface{}) (*Message, error)

Replyf is much like Message.Reply() however you can format your strings just like fmt.Printf()

func (*Message) Server

func (m *Message) Server() *Server

type MessageUpdate

type MessageUpdate struct {
	ID      string                 `json:"id"`
	Channel string                 `json:"channel"`
	Data    map[string]interface{} `json:"data"`
}

type Permissions

type Permissions struct {
	A int `json:"a"`
	D int `json:"d"`
}

type Ready

type Ready struct {
	Users    []*User    `json:"users"`
	Servers  []*Server  `json:"servers"`
	Channels []*Channel `json:"channels"`
}

type Reply

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

type Role

type Role struct {
	Name        string      `json:"name"`
	Permissions Permissions `json:"permissions"`
	Rank        int         `json:"rank"`
}

type Server

type Server struct {
	// TODO: add icon & banner
	ID                 string          `json:"_id"`
	OwnerID            string          `json:"owner"`
	Name               string          `json:"name"`
	Description        string          `json:"description"`
	ChannelIDs         []string        `json:"channels"`
	Categories         []Category      `json:"categories"`
	Roles              map[string]Role `json:"roles"`
	DefaultPermissions int64           `json:"default_permissions"`
}

func (*Server) Channels

func (s *Server) Channels(c *Client) (channels []*Channel)

Channels returns the channels which belong to this server

type ServerCreate

type ServerCreate struct {
	ID       string    `json:"_id"`
	Server   Server    `json:"server"`
	Channels []Channel `json:"channels"`
}

type UpdatedChannel

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

type UpdatedMessage

type UpdatedMessage struct {
	ID        string    `json:"id"`
	ChannelID string    `json:"channel_id"`
	ServerID  string    `json:"server_id"`
	Channel   *Channel  `json:"channel"`
	Content   string    `json:"content"`
	Edited    time.Time `json:"edited"`
	Changes   []string  `json:"changes"`
}

type User

type User struct {
	ID       string `json:"_id"`
	Username string `json:"username"`
	Profile  struct {
		Content string `json:"content"`
	} `json:"profile"`
	Bot *struct {
		OwnerID string `json:"owner"`
	} `json:"bot"`
	Relationship string  `json:"relationship"`
	Online       bool    `json:"online"`
	Privileged   bool    `json:"privileged"`
	Flags        []int32 `json:"flags"`
}

func GetUser

func GetUser(c *Client, id string) (*User, error)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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