revolt

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: CC0-1.0, MIT Imports: 17 Imported by: 0

README

revolt.go

Revolt.go is a Go package for writing bots and self-bots in Revolt easily. This project is a mantained and re-worked version ben-forster's fork of 5elenay's library revoltgo.

Features

  • Multiple event listen
  • Easy to use
  • Supports self bots
  • Simple cache system

API Reference

Click here for api reference.

Notice

Please note that you will need the Go 1.20 to use revolt.

This package is still under development and while you can create a working bot, the library is not finished. Create an issue if you would like to contribute.

Ping Pong Example (Bot)

package main

import (
    "os"
    "os/signal"
    "syscall"

    "within.website/x/web/revolt"
)

func main() {
    // Init a new client.
    client := revolt.Client{
        Token: "bot token",
    }

    // Listen a on message event.
    client.OnMessage(func(m *revolt.Message) {
        if m.Content == "!ping" {
            sendMsg := &revolt.SendMessage{}
            sendMsg.SetContent("🏓 Pong!")

            m.Reply(true, sendMsg)
        }
    })

    // Start the client.
    client.Start()

    // Wait for close.
    sc := make(chan os.Signal, 1)

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

    // Destroy client.
    client.Destroy()
}

Ping Pong Example (Self-Bot)

package main

import (
    "os"
    "os/signal"
    "syscall"

    "within.website/x/web/revolt"
)

func main() {
    // Init a new client.
    client := revolt.Client{
        SelfBot: &revolt.SelfBot{
            Id:           "session id",
            SessionToken: "session token",
            UserId:       "user id",
        },
    }

    // Listen a on message event.
    client.OnMessage(func(m *revolt.Message) {
        if m.Content == "!ping" {
            sendMsg := &revolt.SendMessage{}
            sendMsg.SetContent("🏓 Pong!")

            m.Reply(true, sendMsg)
        }
    })

    // Start the client.
    client.Start()

    // Wait for close.
    sc := make(chan os.Signal, 1)

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

    // Destroy client.
    client.Destroy()
}

To-Do

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	ID          string `json:"_id"`
	Tag         string `json:"tag"`
	Size        int    `json:"size"`
	FileName    string `json:"filename"`
	Metadata    *AttachmentMetadata
	ContentType string `json:"content_type"`
}

Attachment struct.

type AttachmentMetadata

type AttachmentMetadata struct {
	Type   string `json:"type"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

Attachment metadata struct.

type Binary

type Binary struct {
	Data []byte
}

revolt binary struct.

func (Binary) Save

func (b Binary) Save(path string) error

Save data to the given path.

type Bot

type Bot struct {
	CreatedAt time.Time

	Id              string `json:"_id"`
	OwnerId         string `json:"owner"`
	Token           string `json:"token"`
	IsPublic        bool   `json:"public"`
	InteractionsUrl string `json:"interactionsURL"`
}

Bot struct.

func (*Bot) CalculateCreationDate

func (b *Bot) CalculateCreationDate() error

Calculate creation date and edit the struct.

type BotInformation

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

Bot information struct.

type Cache

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

Client cache struct.

func (*Cache) GetChannel

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

Get a channel from cache by Id. Will return an empty channel struct if not found.

func (*Cache) GetMember

func (c *Cache) GetMember(id string) *Member

Get a member from cache by Id. Will return an empty member struct if not found.

func (*Cache) GetServer

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

Get a server from cache by Id. Will return an empty server struct if not found.

func (*Cache) GetUser

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

Get an user from cache by Id. Will return an empty user struct if not found.

func (*Cache) RemoveChannel

func (c *Cache) RemoveChannel(id string) error

Remove a channel from cache by Id. Will not delete the channel, just deletes the channel from cache. Will change the entire channel cache order!

func (*Cache) RemoveMember

func (c *Cache) RemoveMember(id string) error

Remove a member from cache by Id. Will not delete the member, just deletes the member from cache. Will change the entire member cache order!

func (*Cache) RemoveServer

func (c *Cache) RemoveServer(id string) error

Remove a server from cache by Id. Will not delete the server, just deletes the server from cache. Will change the entire server cache order!

func (*Cache) RemoveUser

func (c *Cache) RemoveUser(id string) error

Remove an user from cache by Id. Will not delete the user, just deletes the user from cache. Will change the entire user cache order!

type Channel

type Channel struct {
	CreatedAt time.Time

	Id                 string      `json:"_id"`
	Nonce              string      `json:"nonce"`
	OwnerId            string      `json:"owner"`
	Name               string      `json:"name"`
	Active             bool        `json:"active"`
	Recipients         []string    `json:"recipients"`
	LastMessage        interface{} `json:"last_message"`
	Description        string      `json:"description"`
	Icon               *Attachment `json:"icon"`
	DefaultPermissions interface{} `json:"default_permissions"`
	RolePermissions    interface{} `json:"role_permissions"`
	Permissions        uint        `json:"permissions"`
}

Channel struct.

func (*Channel) CalculateCreationDate

func (c *Channel) CalculateCreationDate() error

Calculate creation date and edit the struct.

type Client

type Client struct {
	SelfBot  *SelfBot
	Token    string
	Socket   gowebsocket.Socket
	HTTP     *http.Client
	Cache    *Cache
	BaseURL  string
	WSURL    string
	Ticker   *time.Ticker
	Settings RevoltSettings
}

Client struct.

func New

func New(token string) (*Client, error)

New creates a new client with the default Revolt server details.

Use NewWithEndpoint to create a client with a custom endpoint.

func NewWithEndpoint

func NewWithEndpoint(token, baseURL, wsURL string) (*Client, error)

NewWithEndpoint creates a new client with a custom Revolt endpoint.

You can use this to test the library against an arbirtary Revolt server.

func (Client) AddFriend

func (c Client) AddFriend(ctx context.Context, username string) (*UserRelations, error)

Send friend request. / Accept friend request. User relations struct only will have status. id is not defined for this function.

func (*Client) AddGroupRecipient

func (c *Client) AddGroupRecipient(ctx context.Context, groupID, userID string) error

Add a new group recipient.

func (*Client) Auth

func (c *Client) Auth(ctx context.Context, friendlyName string) error

Auth client user.

func (*Client) BotDelete

func (c *Client) BotDelete(ctx context.Context, id string) error

func (*Client) BotEdit

func (c *Client) BotEdit(ctx context.Context, id string, eb *EditBot) error

func (*Client) ChannelCreateInvite

func (c *Client) ChannelCreateInvite(ctx context.Context, channelID string) (string, error)

Create a new invite. Returns a string (invite code) and error (nil if not exists).

func (*Client) ChannelDelete

func (c *Client) ChannelDelete(ctx context.Context, channelID string) error

Delete channel.

func (*Client) ChannelEdit

func (c *Client) ChannelEdit(ctx context.Context, channelID string, ec *EditChannel) error

Edit channel.

func (*Client) ChannelFetchMessage

func (c *Client) ChannelFetchMessage(ctx context.Context, channelID, id string) (*Message, error)

Fetch a message from channel by Id.

func (*Client) ChannelFetchMessages

func (c *Client) ChannelFetchMessages(ctx context.Context, channelID string, options url.Values) (*FetchedMessages, error)

Fetch messages from channel. Check: https://developers.revolt.chat/api/#tag/Messaging/paths/~1channels~1:channel~1messages/get for map parameters.

func (*Client) ChannelSendMessage

func (c *Client) ChannelSendMessage(ctx context.Context, channelID string, message *SendMessage) (*Message, error)

SendMessage sends a message to a channel.

func (*Client) ChannelSetPermissions

func (c *Client) ChannelSetPermissions(ctx context.Context, channelID, roleID string, permissions uint) error

Set channel permissions for a role. Leave role field empty if you want to edit default permissions

func (*Client) Connect

func (c *Client) Connect(ctx context.Context, handler Handler)

func (*Client) CreateBot

func (c *Client) CreateBot(ctx context.Context, name string) (*Bot, error)

Create a new bot.

func (*Client) CreateEmoji

func (c *Client) CreateEmoji(ctx context.Context, uploadID string, emoji CreateEmoji) (*Emoji, error)

CreateEmoji creates a new emoji.

func (*Client) CreateGroup

func (c *Client) CreateGroup(ctx context.Context, name, description string, users []string) (*Channel, error)

Create a new group. Users parameter is a list of users will be added.

func (*Client) CreateServer

func (c *Client) CreateServer(ctx context.Context, name, description string) (*Server, error)

Create a server.

func (*Client) CreateTextChannel

func (c *Client) CreateTextChannel(ctx context.Context, serverID, name, description string) (*Channel, error)

Create a new text-channel.

func (*Client) CreateVoiceChannel

func (c *Client) CreateVoiceChannel(ctx context.Context, serverID, name, description string) (*Channel, error)

Create a new voice-channel.

func (*Client) DeleteEmoji

func (c *Client) DeleteEmoji(ctx context.Context, id string) error

DeleteEmoji deletes an emoji.

func (*Client) DeleteGroupRecipient

func (c *Client) DeleteGroupRecipient(ctx context.Context, groupID, userID string) error

Delete a group recipient.

func (Client) Edit

func (c Client) Edit(ctx context.Context, eu *EditUser) error

Edit client user.

func (*Client) Emoji

func (c *Client) Emoji(ctx context.Context, id string) (*Emoji, error)

Emoji grabs a single emoji by URL.

func (*Client) FetchBot

func (c *Client) FetchBot(ctx context.Context, id string) (*Bot, error)

Fetch a bot.

func (*Client) FetchBots

func (c *Client) FetchBots(ctx context.Context) (*FetchedBots, error)

Fetch client bots.

func (*Client) FetchChannel

func (c *Client) FetchChannel(ctx context.Context, id string) (*Channel, error)

Fetch a channel by Id.

func (*Client) FetchDirectMessages

func (c *Client) FetchDirectMessages(ctx context.Context) ([]*Channel, error)

Fetch all of the DMs.

func (Client) FetchRelationships

func (c Client) FetchRelationships(ctx context.Context) ([]*UserRelations, error)

Fetch relationships.

func (*Client) FetchServer

func (c *Client) FetchServer(ctx context.Context, id string) (*Server, error)

Fetch a server by Id.

func (*Client) FetchUser

func (c *Client) FetchUser(ctx context.Context, id string) (*User, error)

Fetch an user by Id.

func (*Client) GroupFetchMembers

func (c *Client) GroupFetchMembers(ctx context.Context, groupID string) ([]*User, error)

Fetch all of the members from group.

func (*Client) MarkServerAsRead

func (c *Client) MarkServerAsRead(ctx context.Context, id string) error

Mark a server as read.

func (*Client) MessageDelete

func (c *Client) MessageDelete(ctx context.Context, channelID, messageID string) error

Delete the message.

func (*Client) MessageEdit

func (c *Client) MessageEdit(ctx context.Context, channelID, messageID, content string) error

Edit message content.

func (*Client) MessageReply

func (c *Client) MessageReply(ctx context.Context, channelID, messageID string, mention bool, sm *SendMessage) (*Message, error)

Reply to the message.

func (Client) RemoveFriend

func (c Client) RemoveFriend(ctx context.Context, username string) (*UserRelations, error)

Deny friend request. / Remove friend. User relations struct only will have status. id is not defined for this function.

func (Client) Request

func (c Client) Request(ctx context.Context, method, path string, data []byte) ([]byte, error)

Send http request

func (*Client) RequestWithPathAndContentType

func (c *Client) RequestWithPathAndContentType(ctx context.Context, method, path, contentType string, data []byte) ([]byte, error)

func (*Client) ResolveAttachment added in v1.6.0

func (c *Client) ResolveAttachment(att *Attachment) string

func (*Client) ServerBanMember

func (c *Client) ServerBanMember(ctx context.Context, serverID, id, reason string) error

Ban a member from server.

func (*Client) ServerCreateRole

func (c *Client) ServerCreateRole(ctx context.Context, serverID, name string) (string, error)

Create a new role for server. Returns string (role id) and error.

func (*Client) ServerDelete

func (c *Client) ServerDelete(ctx context.Context, serverID string) error

Delete / leave server. If the server not created by client, it will leave. Otherwise it will be deleted.

func (*Client) ServerDeleteRole

func (c *Client) ServerDeleteRole(ctx context.Context, serverID, id string) error

Delete a server role.

func (*Client) ServerEdit

func (c *Client) ServerEdit(ctx context.Context, serverID string, es *EditServer) error

Edit server.

func (*Client) ServerEditMember

func (c *Client) ServerEditMember(ctx context.Context, serverID, id string, em *EditMember) error

Edit a member.

func (*Client) ServerEditRole

func (c *Client) ServerEditRole(ctx context.Context, serverID, id string, er *EditRole) error

Edit a server role.

func (*Client) ServerFetchBans

func (c *Client) ServerFetchBans(ctx context.Context, serverID string) (*FetchedBans, error)

Fetch server bans.

func (*Client) ServerFetchInvites

func (c *Client) ServerFetchInvites(ctx context.Context, serverID string) error

Fetch server invite.

func (*Client) ServerFetchMember

func (c *Client) ServerFetchMember(ctx context.Context, serverID, id string) (*Member, error)

Fetch a member from Server.

func (*Client) ServerFetchMembers

func (c *Client) ServerFetchMembers(ctx context.Context, serverID string) (*FetchedMembers, error)

Fetch all of the members from Server.

func (*Client) ServerKickMember

func (c *Client) ServerKickMember(ctx context.Context, serverID, id string) error

Kick a member from server.

func (*Client) ServerSetRolePermissions

func (c *Client) ServerSetRolePermissions(ctx context.Context, serverID, roleID string, channelPermissions, serverPermissions uint) error

Set server permissions for a role. Leave role field empty if you want to edit default permissions

func (*Client) ServerTimeoutMember

func (c *Client) ServerTimeoutMember(ctx context.Context, serverID, id string) error

Timeout a member from server. Placeholder.

func (*Client) ServerUnbanMember

func (c *Client) ServerUnbanMember(ctx context.Context, serverID, id string) error

Unban a member from server.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, tag, fname string, data []byte) (string, error)

Upload a file to Revolt using a multi-part form.

func (*Client) UserBlock

func (c *Client) UserBlock(ctx context.Context, uid string) (*UserRelations, error)

Block user.

func (*Client) UserFetchDefaultAvatar

func (c *Client) UserFetchDefaultAvatar(ctx context.Context, uid string) (*Binary, error)

Fetch default user avatar.

func (*Client) UserFetchRelationship

func (c *Client) UserFetchRelationship(ctx context.Context, uid string) (*UserRelations, error)

Fetch user relationship.

func (*Client) UserOpenDirectMessage

func (c *Client) UserOpenDirectMessage(ctx context.Context, uid string) (*Channel, error)

Open a DM with the user.

func (*Client) UserUnblock

func (c *Client) UserUnblock(ctx context.Context, uid string) (*UserRelations, error)

Un-block user.

type CreateEmoji

type CreateEmoji struct {
	Name   string `json:"name"`
	NSFW   bool   `json:"nsfw"`
	Parent Parent `json:"parent"`
}

type EditBot

type EditBot struct {
	Name            string `json:"name,omitempty"`
	Public          bool   `json:"public,omitempty"`
	InteractionsUrl string `json:"interactionsURL,omitempty"`
	Remove          string `json:"remove,omitempty"`
}

Edit bot struct Please see https://developers.revolt.chat/api/#tag/Bots/paths/~1bots~1:bot/patch for more information.

func (*EditBot) RemoveInteractionsUrl

func (eb *EditBot) RemoveInteractionsUrl() *EditBot

Remove interaction url for struct.

func (*EditBot) SetInteractionsUrl

func (eb *EditBot) SetInteractionsUrl(url string) *EditBot

Set interaction url for struct.

func (*EditBot) SetName

func (eb *EditBot) SetName(name string) *EditBot

Set name for struct.

func (*EditBot) SetPublicValue

func (eb *EditBot) SetPublicValue(is_public bool) *EditBot

Set public value for struct.

type EditChannel

type EditChannel struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Icon        string `json:"icon,omitempty"`
	Remove      string `json:"remove,omitempty"`
}

Edit channel struct. Please see: https://developers.revolt.chat/api/#tag/Channel-Information/paths/~1channels~1:channel/patch for more information.

func (*EditChannel) RemoveItem

func (ec *EditChannel) RemoveItem(item string) *EditChannel

Set remove item.

func (*EditChannel) SetDescription

func (ec *EditChannel) SetDescription(desc string) *EditChannel

Set description for struct.

func (*EditChannel) SetIcon

func (ec *EditChannel) SetIcon(autumn_id string) *EditChannel

Set icon for struct.

func (*EditChannel) SetName

func (ec *EditChannel) SetName(name string) *EditChannel

Set name for struct.

type EditMember

type EditMember struct {
	Nickname string   `json:"nickname,omitempty"`
	Avatar   string   `json:"avatar,omitempty"`
	Roles    []string `json:"roles,omitempty"`
	Remove   string   `json:"remove,omitempty"`
}

Edit member struct. Please see https://developers.revolt.chat/api/#tag/Server-Members/paths/~1servers~1:server~1members~1:member/patch for more information.

func (*EditMember) AddRole

func (em *EditMember) AddRole(role_id string) *EditMember

Add role for struct.

func (*EditMember) RemoveItem

func (em *EditMember) RemoveItem(item string) *EditMember

Set remove item.

func (*EditMember) SetAvatar

func (em *EditMember) SetAvatar(autumn_id string) *EditMember

Set avatar for struct.

func (*EditMember) SetNickname

func (em *EditMember) SetNickname(nick string) *EditMember

Set nickname for struct.

type EditRole

type EditRole struct {
	Name   string `json:"name,omitempty"`
	Color  string `json:"colour,omitempty"`
	Hoist  bool   `json:"hoist,omitempty"`
	Rank   int    `json:"rank,omitempty"`
	Remove string `json:"remove,omitempty"`
}

Edit role struct.

func (*EditRole) IsHoist

func (er *EditRole) IsHoist(hoist bool) *EditRole

Set hoist boolean value for struct.

func (*EditRole) RemoveColour

func (er *EditRole) RemoveColour() *EditRole

Set role ranking for struct.

func (*EditRole) SetColor

func (er *EditRole) SetColor(color string) *EditRole

Set valid HTML color for struct.

func (*EditRole) SetName

func (er *EditRole) SetName(name string) *EditRole

Set name for struct.

func (*EditRole) SetRank

func (er *EditRole) SetRank(rank int) *EditRole

Set role ranking for struct.

type EditServer

type EditServer 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"`
	Remove         string                `json:"remove,omitempty"`
}

Edit server struct. Please see https://developers.revolt.chat/api/#tag/Server-Information/paths/~1servers~1:server/patch for more detail.

func (*EditServer) AddCategory

func (es *EditServer) AddCategory(category *ServerCategory) *EditServer

Add a new category for struct.

func (*EditServer) RemoveItem

func (es *EditServer) RemoveItem(item string) *EditServer

Set remove item.

func (*EditServer) SetBanner

func (es *EditServer) SetBanner(autumn_id string) *EditServer

Set banner for struct.

func (*EditServer) SetDescription

func (es *EditServer) SetDescription(desc string) *EditServer

Set description for struct.

func (*EditServer) SetIcon

func (es *EditServer) SetIcon(autumn_id string) *EditServer

Set icon for struct.

func (*EditServer) SetName

func (es *EditServer) SetName(name string) *EditServer

Set name for struct

func (*EditServer) SetSystemMessages

func (es *EditServer) SetSystemMessages(sm *ServerSystemMessages) *EditServer

Set system messages for struct.

type EditUser

type EditUser struct {
	Status struct {
		Text     string `json:"text,omitempty"`
		Presence string `json:"presence,omitempty"`
	} `json:"status,omitempty"`
	Profile struct {
		Content    string `json:"content,omitempty"`
		Background string `json:"background,omitempty"`
	} `json:"profile,omitempty"`
	Avatar string `json:"avatar,omitempty"`
	Remove string `json:"remove,omitempty"`
}

Edit client user struct. See https://developers.revolt.chat/api/#tag/User-Information/paths/~1users~1@me/patch for more information.

func (*EditUser) SetAvatar

func (eu *EditUser) SetAvatar(autumn_id string) *EditUser

Set avatar for struct.

func (*EditUser) SetProfile

func (eu *EditUser) SetProfile(content, background string) *EditUser

Set profile informations for struct.

func (*EditUser) SetRemove

func (eu *EditUser) SetRemove(item string) *EditUser

Set remove item for struct.

func (*EditUser) SetStatus

func (eu *EditUser) SetStatus(text, presence string) *EditUser

Set status for struct.

type Emoji

type Emoji struct {
	ID        string `json:"_id"`
	Name      string `json:"name"`
	Animated  bool   `json:"animated"`
	NSFW      bool   `json:"nsfw"`
	CreatorID string `json:"creator_id"`
	URL       string `json:"url"`
}

Emoji struct.

type Events

type Events struct {
}

type FetchedBans

type FetchedBans struct {
	Users []*User `json:"users"`
	Bans  []struct {
		Ids struct {
			UserId   string `json:"user"`
			ServerUd string `json:"server"`
		} `json:"_id"`
		Reason string `json:"reason"`
	} `json:"bans"`
}

Fetched bans struct.

type FetchedBots

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

Fetched bots struct.

type FetchedGroupMembers

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

Fetched group members struct.

type FetchedMembers

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

Fetched server members struct.

type FetchedMessages

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

Fetched messages struct.

type Group

type Group struct {
	CreatedAt time.Time

	Id          string   `json:"_id"`
	Nonce       string   `json:"nonce"`
	OwnerId     string   `json:"owner"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Users       []string `json:"users"`
}

Group channel struct.

func (*Group) CalculateCreationDate

func (c *Group) CalculateCreationDate() error

Calculate creation date and edit the struct.

type GroupSystemMessages

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

System messages struct.

type Handler

type Handler interface {
	UnknownEvent(ctx context.Context, kind string, data []byte) error
	Authenticated(context.Context) error
	Ready(context.Context) error

	MessageCreate(ctx context.Context, message *Message) error
	MessageAppend(ctx context.Context, channelID, messageID string, data *MessageAppend) error
	MessageDelete(ctx context.Context, channelID, messageID string) error
	MessageUpdate(ctx context.Context, channelID, messageID string, data *Message) error
	MessageReact(ctx context.Context, messageID, channelID, userID, emojiID string) error
	MessageUnreact(ctx context.Context, messageID, channelID, userID, emojiID string) error
	MessageRemoveReaction(ctx context.Context, messageID, channelID, emojiID string) error

	ChannelCreate(ctx context.Context, channel *Channel) error
	ChannelUpdate(ctx context.Context, channelID string, channel *Channel, clear []string) error
	ChannelDelete(ctx context.Context, channelID string) error
	ChannelAck(ctx context.Context, channelID, userID, messageID string) error
	ChannelStartTyping(ctx context.Context, channelID, userID string) error
	ChannelStopTyping(ctx context.Context, channelID, userID string) error

	ChannelGroupJoin(ctx context.Context, channelID, userID string) error
	ChannelGroupLeave(ctx context.Context, channelID, userID string) error

	ServerCreate(ctx context.Context, srv *Server) error
	ServerUpdate(ctx context.Context, serverID string, srv *Server, clear []string) error
	ServerDelete(ctx context.Context, serverID string) error
	ServerMemberUpdate(ctx context.Context, serverID, userID string, data *Member, clear []string) error
	ServerMemberJoin(ctx context.Context, serverID, userID string) error
	ServerMemberLeave(ctx context.Context, serverID, userID string) error
	ServerRoleUpdate(ctx context.Context, serverID, roleID string, role *Role, clear []string) error
	ServerRoleDelete(ctx context.Context, serverID, roleID string) error

	// Users
	UserUpdate(ctx context.Context, userID string, user *User, clear []string) error
	UserRelationship(ctx context.Context, userID string, user *User, status string) error
	UserPlatformWipe(ctx context.Context, userID string, flags string) error

	// Emoji
	EmojiCreate(ctx context.Context, emoji *Emoji) error
	EmojiDelete(ctx context.Context, emojiID string) error
}

type Interaction

type Interaction struct {
}

Interaction struct.

type Masquerade

type Masquerade struct {
	Name      string `json:"name"`
	AvatarURL string `json:"avatar"`
	Color     string `json:"colour,omitempty"`
}

type Member

type Member struct {
	Informations struct {
		ServerId string `json:"server"`
		UserId   string `json:"user"`
	} `json:"_id"`
	Nickname string      `json:"nickname"`
	Avatar   *Attachment `json:"avatar"`
	Roles    []string    `json:"roles"`
}

Server member struct.

type Message

type Message struct {
	CreatedAt time.Time

	ID          string          `json:"_id"`
	Nonce       string          `json:"nonce"`
	ChannelId   string          `json:"channel"`
	AuthorId    string          `json:"author"`
	Content     string          `json:"content,omitempty"`
	Edited      interface{}     `json:"edited"`
	Embeds      []*MessageEmbed `json:"embeds"`
	Attachments []*Attachment   `json:"attachments"`
	Mentions    []string        `json:"mentions"`
	Replies     []string        `json:"replies"`
	Masquerade  *Masquerade     `json:"masquerade"`
}

Message struct

func (*Message) CalculateCreationDate

func (c *Message) CalculateCreationDate() error

Calculate creation date and edit the struct.

type MessageAppend

type MessageAppend struct {
	Embeds []*MessageEmbed `json:"embeds"`
}

type MessageEdited

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

Message edited struct.

type MessageEmbed

type MessageEmbed struct {
	Type        string `json:"type"`
	Url         string `json:"url"`
	Special     *MessageSpecialEmbed
	Title       string                `json:"title"`
	Description string                `json:"description"`
	Image       *MessageEmbeddedImage `json:"image"`
	Video       *MessageEmbeddedVideo `json:"video"`
	IconUrl     string                `json:"icon_url"`
	Color       string                `json:"color"`
}

Message embed struct.

type MessageEmbeddedImage

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

Message embedded image struct

type MessageEmbeddedVideo

type MessageEmbeddedVideo struct {
	Url    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

Message embedded video struct

type MessageSpecialEmbed

type MessageSpecialEmbed struct {
	Type        string `json:"type"`
	Id          string `json:"id"`
	ContentType string `json:"content_type"`
}

Message special embed struct.

type NullHandler

type NullHandler struct{}

func (NullHandler) Authenticated

func (NullHandler) Authenticated(context.Context) error

func (NullHandler) ChannelAck

func (NullHandler) ChannelCreate

func (NullHandler) ChannelCreate(context.Context, *Channel) error

func (NullHandler) ChannelDelete

func (NullHandler) ChannelDelete(context.Context, string) error

func (NullHandler) ChannelGroupJoin

func (NullHandler) ChannelGroupJoin(context.Context, string, string) error

func (NullHandler) ChannelGroupLeave

func (NullHandler) ChannelGroupLeave(context.Context, string, string) error

func (NullHandler) ChannelStartTyping

func (NullHandler) ChannelStartTyping(context.Context, string, string) error

func (NullHandler) ChannelStopTyping

func (NullHandler) ChannelStopTyping(context.Context, string, string) error

func (NullHandler) ChannelUpdate

func (NullHandler) ChannelUpdate(context.Context, string, *Channel, []string) error

func (NullHandler) EmojiCreate

func (NullHandler) EmojiCreate(context.Context, *Emoji) error

func (NullHandler) EmojiDelete

func (NullHandler) EmojiDelete(context.Context, string) error

func (NullHandler) MessageAppend

func (NullHandler) MessageCreate

func (NullHandler) MessageCreate(context.Context, *Message) error

func (NullHandler) MessageDelete

func (NullHandler) MessageDelete(context.Context, string, string) error

func (NullHandler) MessageReact

func (NullHandler) MessageRemoveReaction

func (NullHandler) MessageRemoveReaction(context.Context, string, string, string) error

func (NullHandler) MessageUnreact

func (NullHandler) MessageUnreact(context.Context, string, string, string, string) error

func (NullHandler) MessageUpdate

func (NullHandler) MessageUpdate(context.Context, string, string, *Message) error

func (NullHandler) Ready

func (NullHandler) ServerChannelCreate

func (NullHandler) ServerChannelCreate(context.Context, string, *Channel) error

func (NullHandler) ServerChannelDelete

func (NullHandler) ServerChannelDelete(context.Context, string, string) error

func (NullHandler) ServerChannelUpdate

func (NullHandler) ServerChannelUpdate(context.Context, string, string, *Channel, []string) error

func (NullHandler) ServerCreate

func (NullHandler) ServerCreate(context.Context, *Server) error

func (NullHandler) ServerDelete

func (NullHandler) ServerDelete(context.Context, string) error

func (NullHandler) ServerMemberJoin

func (NullHandler) ServerMemberJoin(context.Context, string, string) error

func (NullHandler) ServerMemberLeave

func (NullHandler) ServerMemberLeave(context.Context, string, string) error

func (NullHandler) ServerMemberUpdate

func (NullHandler) ServerMemberUpdate(context.Context, string, string, *Member, []string) error

func (NullHandler) ServerRoleCreate

func (NullHandler) ServerRoleCreate(context.Context, string, *Role) error

func (NullHandler) ServerRoleDelete

func (NullHandler) ServerRoleDelete(context.Context, string, string) error

func (NullHandler) ServerRoleUpdate

func (NullHandler) ServerRoleUpdate(context.Context, string, string, *Role, []string) error

func (NullHandler) ServerUpdate

func (NullHandler) ServerUpdate(context.Context, string, *Server, []string) error

func (NullHandler) UnknownEvent

func (NullHandler) UnknownEvent(context.Context, string, []byte) error

func (NullHandler) UserPlatformWipe

func (NullHandler) UserPlatformWipe(context.Context, string, string) error

func (NullHandler) UserRelationship

func (NullHandler) UserRelationship(context.Context, string, *User, string) error

func (NullHandler) UserUpdate

func (NullHandler) UserUpdate(context.Context, string, *User, []string) error

type Parent

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

type Permissions

type Permissions struct {
	Bitvise     uint
	Mode        string // can ben CHANNEL, SERVER or USER
	Permissions map[string]uint
}

Permissions struct

func (*Permissions) Add

func (p *Permissions) Add(perms ...string) *Permissions

Add new permission(s).

func (Permissions) Calculate

func (p Permissions) Calculate(perms ...string) uint

Calculate perms and return unsigned int.

func (Permissions) Has

func (p Permissions) Has(perm string) bool

Calculate if bitvise has permission

func (*Permissions) InitChannel

func (p *Permissions) InitChannel() *Permissions

Init all of the perms for channel.

func (*Permissions) InitServer

func (p *Permissions) InitServer() *Permissions

Init all of the perms for server.

func (*Permissions) InitUser

func (p *Permissions) InitUser() *Permissions

Init all of the perms for user.

func (*Permissions) Remove

func (p *Permissions) Remove(perms ...string) *Permissions

Remove permission(s).

type Replies

type Replies struct {
	Id      string `json:"id"`
	Mention bool   `json:"mention"`
}

type RevoltAutumn

type RevoltAutumn struct {
	Enabled bool   `json:"enabled"`
	URL     string `json:"url"`
}

type RevoltBuild

type RevoltBuild struct {
	CommitSha       string `json:"commit_sha"`
	CommitTimestamp string `json:"commit_timestamp"`
	Semver          string `json:"semver"`
	OriginURL       string `json:"origin_url"`
	Timestamp       string `json:"timestamp"`
}

type RevoltCaptcha

type RevoltCaptcha struct {
	Enabled bool   `json:"enabled"`
	Key     string `json:"key"`
}

type RevoltFeatures

type RevoltFeatures struct {
	Captcha    RevoltCaptcha `json:"captcha"`
	Email      bool          `json:"email"`
	InviteOnly bool          `json:"invite_only"`
	Autumn     RevoltAutumn  `json:"autumn"`
	January    RevoltJanuary `json:"january"`
	Voso       RevoltVoso    `json:"voso"`
}

type RevoltJanuary

type RevoltJanuary struct {
	Enabled bool   `json:"enabled"`
	URL     string `json:"url"`
}

type RevoltSettings

type RevoltSettings struct {
	Revolt   string         `json:"revolt"`
	Features RevoltFeatures `json:"features"`
	Ws       string         `json:"ws"`
	App      string         `json:"app"`
	Vapid    string         `json:"vapid"`
	Build    RevoltBuild    `json:"build"`
}

type RevoltVoso

type RevoltVoso struct {
	Enabled bool   `json:"enabled"`
	URL     string `json:"url"`
	Ws      string `json:"ws"`
}

type Role

type Role struct {
	Name        string         `json:"name"`
	Permissions map[string]int `json:"permissions"`
	Color       string         `json:"colour"`
	Hoist       bool           `json:"hoist"`
	Rank        int            `json:"int"`
}

type SelfBot

type SelfBot struct {
	Email        string `json:"-"`
	Password     string `json:"-"`
	Id           string `json:"id"`
	UserId       string `json:"user_id"`
	SessionToken string `json:"token"`
}

Self bot struct.

type SendMessage

type SendMessage struct {
	Content     string          `json:"content"`
	Nonce       string          `json:"nonce,omitempty"`
	Attachments []string        `json:"attachments,omitempty"`
	Replies     []Replies       `json:"replies,omitempty"`
	Embeds      []SendableEmbed `json:"embeds,omitempty"`
	DeleteAfter uint            `json:"-"`
	Masquerade  *Masquerade     `json:"masquerade,omitempty"`
}

Similar to message, but created for send message function.

func (*SendMessage) AddAttachment

func (sms *SendMessage) AddAttachment(attachment string) *SendMessage

Add a new attachment.

func (*SendMessage) AddReply

func (sms *SendMessage) AddReply(id string, mention bool) *SendMessage

Add a new reply.

func (*SendMessage) CreateNonce

func (sms *SendMessage) CreateNonce() *SendMessage

Create a unique nonce.

func (*SendMessage) SetContent

func (sms *SendMessage) SetContent(content string) *SendMessage

Set content.

func (*SendMessage) SetContentf

func (sms *SendMessage) SetContentf(format string, values ...interface{}) *SendMessage

Set and format content.

func (*SendMessage) SetDeleteAfter

func (sms *SendMessage) SetDeleteAfter(second uint) *SendMessage

Set delete after option.

type SendableEmbed

type SendableEmbed struct {
	Type        string `json:"type"`
	IconUrl     string `json:"icon_url,omitempty"`
	Url         string `json:"url,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Media       string `json:"media,omitempty"`
	Color       string `json:"colour,omitempty"`
}

type Server

type Server struct {
	CreatedAt time.Time

	Id                 string                 `json:"_id"`
	Nonce              string                 `json:"nonce"`
	OwnerId            string                 `json:"owner"`
	Name               string                 `json:"name"`
	Description        string                 `json:"description"`
	ChannelIds         []string               `json:"channels"`
	Categories         []*ServerCategory      `json:"categories"`
	SystemMessages     *ServerSystemMessages  `json:"system_messages"`
	Roles              map[string]interface{} `json:"roles"`
	DefaultPermissions uint                   `json:"default_permissions"`
	Icon               *Attachment            `json:"icon"`
	Banner             *Attachment            `json:"banner"`
}

Server struct.

func (*Server) CalculateCreationDate

func (s *Server) CalculateCreationDate() error

Calculate creation date and edit the struct.

type ServerCategory

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

Server categories struct.

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"`
	UserTimeout string `json:"user_timeout,omitempty"`
}

System messages struct.

type User

type User struct {
	Client    *Client
	CreatedAt time.Time

	Id             string           `json:"_id"`
	Username       string           `json:"username"`
	Avatar         *Attachment      `json:"avatar"`
	Relations      []*UserRelations `json:"relations"`
	Badges         int              `json:"badges"`
	Status         *UserStatus      `json:"status"`
	Relationship   string           `json:"relationship"`
	IsOnline       bool             `json:"online"`
	Flags          int              `json:"flags"`
	BotInformation *BotInformation  `json:"bot"`
}

User struct.

func (*User) CalculateCreationDate

func (u *User) CalculateCreationDate() error

Calculate creation date and edit the struct.

func (User) FormatMention

func (u User) FormatMention() string

Create a mention format.

type UserRelations

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

User relations struct.

type UserStatus

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

User status struct.

type WSError

type WSError struct {
	Type   string `json:"type"`
	ErrMsg string `json:"error"`
}

func (WSError) Error

func (e WSError) Error() string

Jump to

Keyboard shortcuts

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