Documentation
¶
Index ¶
- Constants
- Variables
- type ArrayCache
- func (c *ArrayCache) GetChannel(id string) *Channel
- func (c *ArrayCache) GetServer(id string) *Server
- func (c *ArrayCache) GetUser(id string) *User
- func (c *ArrayCache) ListServers() []*Server
- func (c *ArrayCache) PutChannel(channel *Channel)
- func (c *ArrayCache) PutServer(s *Server)
- func (c *ArrayCache) PutUser(u *User)
- type Cache
- type Category
- type Channel
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) OnChannelCreate(h HandlerChannelCreate)
- func (c *Client) OnChannelDelete(h HandlerChannelDelete)
- func (c *Client) OnChannelUpdate(h HandlerChannelUpdate)
- func (c *Client) OnMessage(h HandlerMessage)
- func (c *Client) OnMessageUpdate(h HandlerMessageUpdate)
- func (c *Client) OnReady(h HandlerReady)
- func (c *Client) OnServerCreate(h HandlerServerCreate)
- func (c *Client) OnServerUpdate(h HandlerServerUpdate)
- func (c *Client) SendMessage(channel, content string) (*Message, error)
- func (c *Client) SetCache(cache Cache)
- func (c *Client) UnregisterHandlers()
- type Embed
- type HandlerChannelCreate
- type HandlerChannelDelete
- type HandlerChannelUpdate
- type HandlerMessage
- type HandlerMessageUpdate
- type HandlerReady
- type HandlerServerCreate
- type HandlerServerUpdate
- type Masquerade
- type Member
- type Message
- type MessageUpdate
- type Permissions
- type Ready
- type Reply
- type Role
- type Server
- type ServerCreate
- type UpdatedChannel
- type UpdatedMessage
- type User
Constants ¶
const ( RevoltAPI = "https://api.revolt.chat" RevoltWebsocket = "wss://ws.revolt.chat" )
const ( RouteUsersMe = "/users/@me" RouteUsers = "/users/{0}" RouteServerMembers = "/servers/{0}/members" RouteChannelMessages = "/channels/{0}/messages" RouteChannel = "/channels/{0}" )
Variables ¶
var ( ErrRateLimit = errors.New("429: rate limit reached") 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") )
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 ¶
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 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 (*Channel) SendMessage ¶
SendMessage will send message in the channel
func (*Channel) SendMessagef ¶
SendMessagef will format the message being sent to the channel
type Client ¶
type Client struct {
User *User
// contains filtered or unexported fields
}
Client maintains state for your logged in session
func (*Client) Connect ¶
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 (*Client) SetCache ¶
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 HandlerChannelCreate ¶
type HandlerChannelDelete ¶
type HandlerChannelUpdate ¶
type HandlerMessage ¶
type HandlerMessageUpdate ¶
type HandlerMessageUpdate func(c *Client, m *UpdatedMessage)
type HandlerReady ¶
type HandlerServerCreate ¶
type HandlerServerUpdate ¶
type Masquerade ¶
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 ¶
Reply will send a message within the same channel with that message as the reply.
type MessageUpdate ¶
type Permissions ¶
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"`
}
type ServerCreate ¶
type UpdatedChannel ¶
type UpdatedMessage ¶
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"`
}
