guildrone

package module
v0.0.0-...-bcad012 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2022 License: BSD-3-Clause Imports: 15 Imported by: 0

README

GuilDrone

This is a Guilded chat library based on discordgo by bwmarrin.

This is basically bwmarrin's code, so please leave all thanks to him.

Getting Started

Installing

This assumes you already have a working Go environment, if not please see this page first.

go get will always pull the latest tagged release from the master branch.

go get github.com/FlameInTheDark/guildrone
Usage

Import the package into your project.

import "github.com/FlameInTheDark/guildrone"

Construct a new Guilded client which can be used to access the variety of Guilded API functions and to set callback functions for Guilded events.

guilded, err := guildrone.New("authentication token")

See Documentation and Examples below for more detailed information.

Documentation

Index

Constants

View Source
const (

	// LogError level is used for critical errors that could lead to data loss
	// or panic that would not be returned to a calling function.
	LogError int = iota

	// LogWarning level is used for very abnormal events and errors that are
	// also returned to a calling function.
	LogWarning

	// LogInformational level is used for normal non-error activity
	LogInformational

	// LogDebug level is for very detailed non-error activity.  This is
	// very spammy and will impact performance.
	LogDebug
)
View Source
const FailedHeartbeatAcks time.Duration = 5 * time.Millisecond

FailedHeartbeatAcks is the Number of heartbeat intervals to wait until forcing a connection restart.

View Source
const VERSION = "0.1.0"

VERSION of Guildrone, follows Semantic Versioning. (http://semver.org/)

Variables

View Source
var (
	APIVersion = "1"

	EndpointGuildedWebsocket = "wss://api.guilded.gg/v1/websocket"

	EndpointGuilded  = "https://www.guilded.gg/"
	EndpointAPI      = EndpointGuilded + "api/v" + APIVersion + "/"
	EndpointChannels = EndpointAPI + "channels/"
	EndpointServers  = EndpointAPI + "servers/"
	EndpointGroups   = EndpointAPI + "groups/"

	EndpointChannel              = func(cID string) string { return EndpointChannels + cID }
	EndpointServer               = func(sID string) string { return EndpointServers + sID }
	EndpointChannelMessages      = func(cID string) string { return EndpointChannels + cID + "/messages" }
	EndpointChannelMessage       = func(cID, mID string) string { return EndpointChannels + cID + "/messages/" + mID }
	EndpointServerMembers        = func(sID string) string { return EndpointServers + sID + "/members" }
	EndpointServerMember         = func(sID, uID string) string { return EndpointServers + sID + "/members/" + uID }
	EndpointServerMemberNickname = func(sID, uID string) string { return EndpointServers + sID + "/members/" + uID + "/nickname" }
	EndpointServerBans           = func(sID string) string { return EndpointServers + sID + "/bans" }
	EndpointServerBansMember     = func(sID, uID string) string { return EndpointServers + sID + "/bans/" + uID }
	EndpointChannelTopics        = func(cID string) string { return EndpointChannels + cID + "/topics" }
	EndpointChannelItems         = func(cID string) string { return EndpointChannels + cID + "/items" }
	EndpointChannelItem          = func(cID, iID string) string { return EndpointChannels + cID + "/items/" + iID }
	EndpointChannelItemComplete  = func(cID, iID string) string { return EndpointChannels + cID + "/items/" + iID + "/complete" }
	EndpointChannelDocs          = func(cID string) string { return EndpointChannels + cID + "/docs" }
	EndpointChannelDoc           = func(cID, dID string) string { return EndpointChannels + cID + "/docs/" + dID }
	EndpointChannelEvents        = func(cID string) string { return EndpointChannels + cID + "/events" }
	EndpointChannelEvent         = func(cID, eID string) string { return EndpointChannels + cID + "/events/" + eID }
	EndpointChannelReaction      = func(cID, coID, eID string) string {
		return EndpointChannels + cID + "/content/" + coID + "/emotes/" + eID
	}
	EndpointServerXPMember         = func(sID, uID string) string { return EndpointServers + sID + "/members/" + uID + "/xp" }
	EndpointServerXPRoles          = func(sID, rID string) string { return EndpointServers + sID + "/roles/" + rID + "/xp" }
	EndpointServerMemberSocialLink = func(sID, uID, linkType string) string {
		return EndpointServers + sID + "/members/" + uID + "/social-links/" + linkType
	}
	EndpointGroupMember       = func(gID, uID string) string { return EndpointGroups + gID + "/members/" + uID }
	EndpointServerMemberRoles = func(sID, uID string) string { return EndpointServers + sID + "/members/" + uID + "/roles" }
	EndpointServerMemberRole  = func(sID, uID, rID string) string { return EndpointServers + sID + "/members/" + uID + "/roles/" + rID }
	EndpointServerWeebhooks   = func(sID string) string { return EndpointServers + sID + "/webhooks" }
	EndpointServerWeebhook    = func(sID, wID string) string { return EndpointServers + sID + "/webhooks/" + wID }
)
View Source
var (
	ErrJSONUnmarshal           = errors.New("json unmarshal")
	ErrStatusOffline           = errors.New("You can't set your Status to offline")
	ErrVerificationLevelBounds = errors.New("VerificationLevel out of bounds, should be between 0 and 3")
	ErrPruneDaysBounds         = errors.New("the number of days should be more than or equal to 1")
	ErrGuildNoIcon             = errors.New("guild does not have an icon set")
	ErrGuildNoSplash           = errors.New("guild does not have a splash set")
	ErrUnauthorized            = errors.New("HTTP request was unauthorized. This could be because the provided token was not a bot token")
)

All error constants

View Source
var (
	// Marshal defines function used to encode JSON payloads
	Marshal func(v interface{}) ([]byte, error) = json.Marshal
	// Unmarshal defines function used to decode JSON payloads
	Unmarshal func(src []byte, v interface{}) error = json.Unmarshal
)
View Source
var ErrWSAlreadyOpen = errors.New("web socket already opened")

ErrWSAlreadyOpen is thrown when you attempt to open a websocket that already is open.

View Source
var ErrWSNotFound = errors.New("no websocket connection exists")

ErrWSNotFound is thrown when you attempt to use a websocket that doesn't exist

View Source
var Logger func(msgL, caller int, format string, a ...interface{})

Logger can be used to replace the standard logging for guildrone

Functions

This section is empty.

Types

type APIErrorMessage

type APIErrorMessage struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

An APIErrorMessage is an api error message returned from Guilded

type BotUser

type BotUser struct {
	ID        string    `json:"id"`
	BotID     string    `json:"botId"`
	Name      string    `json:"name"`
	CreatedAt Timestamp `json:"createdAt"`
	CreatedBy string    `json:"createdBy"`
}

type CalendarEvent

type CalendarEvent struct {
	ID          string    `json:"id"`
	ServerId    string    `json:"serverId"`
	ChannelId   string    `json:"channelId"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	Location    string    `json:"location"`
	URL         string    `json:"url"`
	Color       int       `json:"color"`
	StartsAt    Timestamp `json:"startsAt"`
	// Duration in minutes
	Duration     int          `json:"duration"`
	IsPrivate    bool         `json:"isPrivate"`
	Mentions     *Mentions    `json:"mentions"`
	CreatedAt    Timestamp    `json:"createdAt"`
	CreatedBy    string       `json:"createdBy"`
	Cancellation Cancellation `json:"cancellation"`
}

type CalendarEventCreated

type CalendarEventCreated struct {
	ServerID      string        `json:"serverId"`
	CalendarEvent CalendarEvent `json:"calendarEvent"`
}

type CalendarEventDeleted

type CalendarEventDeleted struct {
	ServerID      string        `json:"serverId"`
	CalendarEvent CalendarEvent `json:"calendarEvent"`
}

type CalendarEventUpdated

type CalendarEventUpdated struct {
	ServerID      string        `json:"serverId"`
	CalendarEvent CalendarEvent `json:"calendarEvent"`
}

type Cancellation

type Cancellation struct {
	Description string `json:"description"`
	CreatedBy   string `json:"createdBy"`
}

type ChannelCreate

type ChannelCreate struct {
	Name       string            `json:"name"`
	Topic      string            `json:"topic,omitempty"`
	IsPublic   bool              `json:"isPublic,omitempty"`
	Type       ServerChannelType `json:"type"`
	ServerID   string            `json:"serverId,omitempty"`
	GroupID    string            `json:"groupId,omitempty"`
	CategoryID string            `json:"categoryId,omitempty"`
}

type ChannelDoc

type ChannelDoc struct {
	Title   string `json:"title"`
	Content string `json:"content"`
}

type ChannelEvent

type ChannelEvent struct {
	Name        string     `json:"name"`
	Description string     `json:"description,omitempty"`
	Location    string     `json:"location,omitempty"`
	StartsAt    *Timestamp `json:"startsAt,omitempty"`
	URL         string     `json:"url,omitempty"`
	Color       int        `json:"color,omitempty"`
	Duration    int        `json:"duration,omitempty"`
	IsPrivate   bool       `json:"isPrivate,omitempty"`
}

type ChannelEventsRequest

type ChannelEventsRequest struct {
	Before *Timestamp `json:"before,omitempty"`
	After  *Timestamp `json:"after,omitempty"`
	Limit  int        `json:"limit,omitempty"`
}

type ChannelForumTopicCreate

type ChannelForumTopicCreate struct {
	Title   string `json:"title"`
	Content string `json:"content"`
}

type ChannelListItem

type ChannelListItem struct {
	Message string               `json:"message"`
	Note    *ChannelListItemNote `json:"note,omitempty"`
}

type ChannelListItemNote

type ChannelListItemNote struct {
	Content string `json:"content"`
}

type ChannelMessageReactionCreated

type ChannelMessageReactionCreated struct {
	ServerID string   `json:"serverId"`
	Reaction Reaction `json:"reaction"`
}

type ChannelMessageReactionDeleted

type ChannelMessageReactionDeleted struct {
	ServerID string   `json:"serverId"`
	Reaction Reaction `json:"reaction"`
}

type ChannelUpdate

type ChannelUpdate struct {
	Name     string `json:"name,omitempty"`
	Topic    string `json:"topic,omitempty"`
	IsPublic bool   `json:"isPublic,omitempty"`
}

type ChatEmbed

type ChatEmbed struct {
	Title       string              `json:"title,omitempty"`
	Description string              `json:"description,omitempty"`
	URL         string              `json:"url,omitempty"`
	Color       int                 `json:"color"`
	Footer      ChatEmbedFooter     `json:"footer"`
	Timestamp   *Timestamp          `json:"timestamp,omitempty"`
	Thumbnail   *ChatEmbedThumbnail `json:"thumbnail,omitempty"`
	Image       *ChatEmbedImage     `json:"image,omitempty"`
	Author      *ChatEmbedAuthor    `json:"author,omitempty"`
	Fields      []ChatEmbedField    `json:"fields,omitempty"`
}

type ChatEmbedAuthor

type ChatEmbedAuthor struct {
	Name    string `json:"name,omitempty"`
	URL     string `json:"url,omitempty"`
	IconUrl string `json:"icon_url,omitempty"`
}

type ChatEmbedField

type ChatEmbedField struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

type ChatEmbedFooter

type ChatEmbedFooter struct {
	Text    string `json:"text,omitempty"`
	IconUrl string `json:"icon_url,omitempty"`
}

type ChatEmbedImage

type ChatEmbedImage struct {
	URL string `json:"url,omitempty"`
}

type ChatEmbedThumbnail

type ChatEmbedThumbnail struct {
	URL string `json:"url,omitempty"`
}

type ChatMessage

type ChatMessage struct {
	// The ID of the message
	ID string `json:"id"`

	// Type of the message
	Type MessageType `json:"type"`

	// The ID of the server the message was sent in
	ServerID string `json:"serverId"`

	// The ID of the channel the message was sent in
	ChannelID string `json:"channelId"`

	// Content of the message
	Content string `json:"content"`

	// Embedded content
	Embeds []ChatEmbed `json:"embeds"`

	// Message ids that were replied to
	ReplyMessageIds []string `json:"replyMessageIds"`

	// If set, this message will only be seen by those mentioned or replied to
	IsPrivate          bool       `json:"isPrivate"`
	IsSilent           bool       `json:"isSilent"`
	Mentions           *Mentions  `json:"mentions,omitempty"`
	CreatedAt          string     `json:"createdAt"`
	CreatedBy          string     `json:"createdBy"`
	CreatedByWebhookId string     `json:"createdByWebhookId"`
	UpdatedAt          *Timestamp `json:"updatedAt,omitempty"`
}

ChatMessage stores the data of a chat message

type ChatMessageCreated

type ChatMessageCreated struct {
	ServerID string      `json:"serverId"`
	Message  ChatMessage `json:"message"`
}

Is the data for the ChatMessageCreated event

type ChatMessageDeleted

type ChatMessageDeleted struct {
	ServerID string      `json:"serverId"`
	Message  ChatMessage `json:"message"`
}

type ChatMessageUpdated

type ChatMessageUpdated struct {
	ServerID string      `json:"serverId"`
	Message  ChatMessage `json:"message"`
}

type Connect

type Connect struct{}

Connect is the data for a Connect event. This is a synthetic event and is not dispatched by Guilded.

type Disconnect

type Disconnect struct{}

Disconnect is the data for a Disconnect event. This is a synthetic event and is not dispatched by Guilded.

type Doc

type Doc struct {
	ID        int        `json:"id"`
	ServerId  string     `json:"serverId"`
	ChannelId string     `json:"channelId"`
	Title     string     `json:"title"`
	Content   string     `json:"content"`
	Mentions  *Mentions  `json:"mentions"`
	CreatedAt Timestamp  `json:"createdAt"`
	CreatedBy string     `json:"createdBy"`
	UpdatedAt *Timestamp `json:"updatedAt"`
	UpdatedBy string     `json:"updatedBy"`
}

type DocCreated

type DocCreated struct {
	ServerID string `json:"serverId"`
	Doc      Doc    `json:"doc"`
}

type DocDeleted

type DocDeleted struct {
	ServerID string `json:"serverId"`
	Doc      Doc    `json:"doc"`
}

type DocUpdated

type DocUpdated struct {
	ServerID string `json:"serverId"`
	Doc      Doc    `json:"doc"`
}

type Emote

type Emote struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	URL  string `json:"url"`
}

type Event

type Event struct {
	Operation int             `json:"op"`
	MessageID string          `json:"s"`
	Type      string          `json:"t"`
	RawData   json.RawMessage `json:"d"`
	// Struct contains one of the other types in this file.
	Struct interface{} `json:"-"`
}

Event provides a basic initial struct for all websocket events.

type EventHandler

type EventHandler interface {
	// Type returns the type of event this handler belongs to.
	Type() string

	// Handle is called whenever an event of Type() happens.
	// It is the receiver's responsibility to type assert that the interface
	// is the expected struct.
	Handle(*Session, interface{})
}

EventHandler is an interface for Guilded events.

type EventInterfaceProvider

type EventInterfaceProvider interface {
	// Type is the type of event this handler belongs to.
	Type() string

	// New returns a new instance of the struct this event handler handles.
	// This is called once per event.
	// The struct is provided to all handlers of the same Type().
	New() interface{}
}

EventInterfaceProvider is an interface for providing empty interfaces for Guilded events.

type ForumTopic

type ForumTopic struct {
	ID                 int        `json:"id"`
	ServerID           string     `json:"serverId"`
	ChannelID          string     `json:"channelId"`
	Title              string     `json:"title,omitempty"`
	Content            string     `json:"content,omitempty"`
	CreatedAt          Timestamp  `json:"createdAt"`
	CreatedBy          string     `json:"createdBy"`
	CreatedByWebhookId string     `json:"createdByWebhookId,omitempty"`
	UpdatedAt          *Timestamp `json:"updatedAt,omitempty"`
}

type ListItem

type ListItem struct {
	ID                 string        `json:"id"`
	ServerID           string        `json:"serverId"`
	ChannelID          string        `json:"channelId"`
	Message            string        `json:"message"`
	Mentions           *Mentions     `json:"mentions"`
	CreatedAt          Timestamp     `json:"createdAt"`
	CreatedBy          string        `json:"createdBy"`
	CreatedByWebhookId string        `json:"createdByWebhookId"`
	UpdatedAt          *Timestamp    `json:"updatedAt"`
	UpdatedBy          string        `json:"updatedBy"`
	ParentListItemId   string        `json:"parentListItemId"`
	CompletedAt        string        `json:"completedAt"`
	CompletedBy        string        `json:"completedBy"`
	Note               *ListItemNote `json:"note"`
}

type ListItemCompleted

type ListItemCompleted struct {
	ServerID string   `json:"serverId"`
	ListItem ListItem `json:"listItem"`
}

type ListItemCreated

type ListItemCreated struct {
	ServerID string   `json:"serverId"`
	ListItem ListItem `json:"listItem"`
}

type ListItemDeleted

type ListItemDeleted struct {
	ServerID string   `json:"serverId"`
	ListItem ListItem `json:"listItem"`
}

type ListItemNote

type ListItemNote struct {
	CreatedAt Timestamp  `json:"createdAt"`
	CreatedBy string     `json:"createdBy"`
	UpdatedAt *Timestamp `json:"updatedAt"`
	UpdatedBy string     `json:"updatedBy"`
	Mentions  *Mentions  `json:"mentions"`
	Content   string     `json:"content"`
}

type ListItemUpdated

type ListItemUpdated struct {
	ServerID string   `json:"serverId"`
	ListItem ListItem `json:"listItem"`
}

type MemberRole

type MemberRole struct {
	UserID  string `json:"userId"`
	RoleIDs []int  `json:"roleId"`
}

type MentionChannel

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

type MentionRole

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

type MentionUser

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

type Mentions

type Mentions struct {
	Users    []MentionUser    `json:"users,omitempty"`
	Channels []MentionChannel `json:"channels,omitempty"`
	Roles    []MentionRole    `json:"roles,omitempty"`
	Everyone bool             `json:"everyone,omitempty"`
	Here     bool             `json:"here,omitempty"`
}

type MessageCreate

type MessageCreate struct {
	IsPrivate       bool        `json:"isPrivate,omitempty"`
	IsSilent        bool        `json:"isSilent,omitempty"`
	ReplyMessageIds []string    `json:"replyMessageIds,omitempty"`
	Content         string      `json:"content,omitempty"`
	Embeds          []ChatEmbed `json:"embeds,omitempty"`
}

type MessageType

type MessageType string
const (
	MessageTypeDefault MessageType = "default"
	MessageTypeSystem  MessageType = "system"
)

type MessageUpdate

type MessageUpdate struct {
	Content string      `json:"content,omitempty"`
	Embeds  []ChatEmbed `json:"embeds,omitempty"`
}

type MessagesRequest

type MessagesRequest struct {
	Before         *time.Time `json:"before,omitempty"`
	After          *time.Time `json:"after,omitempty"`
	Limit          int        `json:"limit,omitempty"`
	IncludePrivate bool       `json:"includePrivate,omitempty"`
}

type RESTError

type RESTError struct {
	Request      *http.Request
	Response     *http.Response
	ResponseBody []byte

	Message *APIErrorMessage // Message may be nil.
}

RESTError stores error information about a request with a bad response code. Message is not always present, there are cases where api calls can fail without returning a json message.

func (RESTError) Error

func (r RESTError) Error() string

Error returns a Rest API Error with its status code and body.

type RateLimit

type RateLimit struct {
	RetryAfter time.Duration
	URL        string
}

RateLimit is the data for a RateLimit event. This is a synthetic event and is not dispatched by Guilded.

type RateLimitError

type RateLimitError struct {
	*RateLimit
}

RateLimitError is returned when a request exceeds a rate limit and ShouldRetryOnRateLimit is false. The request may be manually retried after waiting the duration specified by RetryAfter.

func (RateLimitError) Error

func (e RateLimitError) Error() string

Error returns a rate limit error with rate limited endpoint and retry time.

type Reaction

type Reaction struct {
	ChannelID string `json:"channelId"`
	MessageID string `json:"messageId"`
	CreatedBy string `json:"createdBy"`
	Emote     Emote  `json:"emote"`
}

type Ready

type Ready struct {
	LastMessageID       string  `json:"lastMessageId"`
	HeartbeatIntervalMS int     `json:"heartbeatIntervalMs"`
	User                BotUser `json:"user"`
}

type Server

type Server struct {
	ID               string      `json:"id"`
	OwnerID          string      `json:"ownerId"`
	Type             *ServerType `json:"type,omitempty"`
	Name             string      `json:"name"`
	URL              string      `json:"url,omitempty"`
	About            string      `json:"about,omitempty"`
	Avatar           string      `json:"avatar,omitempty"`
	Banner           string      `json:"banner,omitempty"`
	Timezone         string      `json:"timezone,omitempty"`
	IsVerified       bool        `json:"isVerified,omitempty"`
	DefaultChannleID string      `json:"defaultChannelId,omitempty"`
	CreatedAt        Timestamp   `json:"createdAt"`
}

type ServerChannel

type ServerChannel struct {
	ID         string            `json:"id"`
	Type       ServerChannelType `json:"type"`
	Name       string            `json:"name"`
	Topic      string            `json:"topic"`
	CreatedAt  Timestamp         `json:"createdAt"`
	CreatedBy  string            `json:"createdBy"`
	UpdatedAt  *Timestamp        `json:"updatedAt"`
	ServerId   string            `json:"serverId"`
	ParentId   string            `json:"parentId"`
	CategoryId int               `json:"categoryId"`
	GroupId    string            `json:"groupId"`
	IsPublic   bool              `json:"isPublic"`
	ArchivedBy string            `json:"archivedBy"`
	ArchivedAt string            `json:"archivedAt"`
}

type ServerChannelType

type ServerChannelType string

ServerChannelType is a sting that represents the type of a server channel. ("announcements", "chat", "calendar", "forums", "media", "docs", "voice", "list", "scheduling", or "stream")

const (
	ServerChannelTypeAnnouncements ServerChannelType = "announcements"
	ServerChannelTypeChat          ServerChannelType = "chat"
	ServerChannelTypeCalendar      ServerChannelType = "calendar"
	ServerChannelTypeForums        ServerChannelType = "forums"
	ServerChannelTypeMedia         ServerChannelType = "media"
	ServerChannelTypeDocs          ServerChannelType = "docs"
	ServerChannelTypeVoice         ServerChannelType = "voice"
	ServerChannelTypeList          ServerChannelType = "list"
	ServerChannelTypeScheduling    ServerChannelType = "scheduling"
	ServerChannelTypeStream        ServerChannelType = "stream"
)

type ServerMember

type ServerMember struct {
	User     User   `json:"user"`
	RoleIds  []int  `json:"roleIds"`
	Nickname string `json:"nickname"`
	JoinedAt string `json:"joinedAt"`
	IsOwner  bool   `json:"isOwner"`
}

type ServerMemberBan

type ServerMemberBan struct {
	UserSummary UserSummary `json:"user"`
	Reason      string      `json:"reason"`
	CreatedBy   string      `json:"createdBy"`
	CreatedAt   Timestamp   `json:"createdAt"`
}

type ServerMemberBanCreate

type ServerMemberBanCreate struct {
	Reason string `json:"reason"`
}

type ServerMemberNicknameUpdate

type ServerMemberNicknameUpdate struct {
	Nickname string `json:"nickname"`
}
type ServerSocialLink struct {
	Handle    string `json:"handle,omitempty"`
	ServiceID string `json:"serviceId,omitempty"`
	Type      string `json:"type"`
}

type ServerType

type ServerType string
const (
	ServerTypeTeam         ServerType = "team"
	ServerTypeOrganization ServerType = "organization"
	ServerTypeCommunity    ServerType = "community"
	ServerTypeClan         ServerType = "clan"
	ServerTypeGuild        ServerType = "guild"
	ServerTypeFriends      ServerType = "friends"
	ServerTypeStreaming    ServerType = "streaming"
	ServerTypeOther        ServerType = "other"
)

type ServerXPUpdate

type ServerXPUpdate struct {
	Amount int `json:"amount"`
}

type Session

type Session struct {
	sync.RWMutex

	// Authentication token for this session
	Token string

	// Logging
	Debug    bool
	LogLevel int

	// REST API Client
	Client    *http.Client
	UserAgent string

	// Max number of REST API retries
	MaxRestRetries int

	// Should the session reconnect the websocket on errors.
	ShouldReconnectOnError bool

	// Should the session retry requests when rate limited.
	ShouldRetryOnRateLimit bool

	// Whether or not to call event handlers synchronously.
	// e.g false = launch event handlers in their own goroutines.
	SyncEvents bool

	// Whether the Data Websocket is ready
	DataReady bool // NOTE: Maye be deprecated soon

	// Stores the last HeartbeatAck that was received (in UTC)
	LastHeartbeatAck time.Time

	// Stores the last Heartbeat sent (in UTC)
	LastHeartbeatSent time.Time
	// contains filtered or unexported fields
}

func New

func New(token string) (s *Session, err error)

New creates a new Guilded session with provided token

func (*Session) AddHandler

func (s *Session) AddHandler(handler interface{}) func()

AddHandler allows you to add an event handler that will be fired anytime the Guilded WSAPI event that matches the function fires. The first parameter is a *Session, and the second parameter is a pointer to a struct corresponding to the event for which you want to listen.

eg:

Session.AddHandler(func(s *guildrone.Session, m *guildrone.MessageCreated) {
})

or:

Session.AddHandler(func(s *guildrone.Session, m *guildrone.PresenceUpdate) {
})

List of events can be found at this page, with corresponding names in the library for each event: https://www.guilded.gg/docs/api/websockets There are also synthetic events fired by the library internally which are available for handling, like Connect, Disconnect, and RateLimit. events.go contains all of the Guilded WSAPI and synthetic events that can be handled.

The return value of this method is a function, that when called will remove the event handler.

func (*Session) AddHandlerOnce

func (s *Session) AddHandlerOnce(handler interface{}) func()

AddHandlerOnce allows you to add an event handler that will be fired the next time the Guilded WSAPI event that matches the function fires. See AddHandler for more details.

func (*Session) ChannelContentReactionAdd

func (s *Session) ChannelContentReactionAdd(channelID, contentID string, emoteID int) error

ChannelContentReactionAdd adds a reaction to a content in a channel. channelID : The ID of a Channel. contentID : The ID of a Content. emoteID : The ID of an Emote.

func (*Session) ChannelContentReactionDelete

func (s *Session) ChannelContentReactionDelete(channelID, contentID string, emoteID int) error

ChannelContentReactionDelete deletes a reaction to a content in a channel. channelID : The ID of a Channel. contentID : The ID of a Content. emoteID : The ID of an Emote.

func (*Session) ChannelCreate

func (s *Session) ChannelCreate(data *ChannelCreate) (*ServerChannel, error)

ChannelCreate creates a channel in a server. data : The channel struct to send.

func (*Session) ChannelDelete

func (s *Session) ChannelDelete(channelID string) error

ChannelDelete deletes a channel. channelID : The ID of a Channel.

func (*Session) ChannelDoc

func (s *Session) ChannelDoc(channelID string, docID int) (*Doc, error)

ChannelDoc returns a doc in a channel. channelID : The ID of a Channel. docID : The ID of a Doc.

func (*Session) ChannelDocCreate

func (s *Session) ChannelDocCreate(channelID string, data *ChannelDoc) (*Doc, error)

ChannelDocCreate creates a doc in a channel. channelID : The ID of a Channel. data : The data for the doc.

func (*Session) ChannelDocDelete

func (s *Session) ChannelDocDelete(channelID string, docID int) error

ChannelDocDelete deletes a doc in a channel. channelID : The ID of a Channel. docID : The ID of a Doc.

func (*Session) ChannelDocUpdate

func (s *Session) ChannelDocUpdate(channelID string, docID int, data *ChannelDoc) (*Doc, error)

ChannelDocUpdate updates a doc in a channel. channelID : The ID of a Channel. docID : The ID of a Doc. data : The data for the doc.

func (*Session) ChannelDocs

func (s *Session) ChannelDocs(channelID string) ([]*Doc, error)

ChannelDocs returns an array of docs in a channel. channelID : The ID of a Channel.

func (*Session) ChannelEvent

func (s *Session) ChannelEvent(channelID string, eventID int) (*CalendarEvent, error)

ChannelEvent returns a calendar event in a channel. channelID : The ID of a Channel. eventID : The ID of an CalendarEvent.

func (*Session) ChannelEventCreate

func (s *Session) ChannelEventCreate(channelID string, data *ChannelEvent) (*CalendarEvent, error)

ChannelEventCreate creates a calendar event in a channel. channelID : The ID of a Channel. data : The data for the event.

func (*Session) ChannelEventDelete

func (s *Session) ChannelEventDelete(channelID string, eventID int) error

ChannelEventDelete deletes a calendar event in a channel. channelID : The ID of a Channel. eventID : The ID of an CalendarEvent.

func (*Session) ChannelEventUpdate

func (s *Session) ChannelEventUpdate(channelID string, eventID int, data *ChannelEvent) (*CalendarEvent, error)

ChannelEventUpdate updates a calendar event in a channel. channelID : The ID of a Channel. eventID : The ID of an CalendarEvent. data : The data for the event.

func (*Session) ChannelEvents

func (s *Session) ChannelEvents(channelID string, data *ChannelEventsRequest) ([]*CalendarEvent, error)

ChannelEvents returns an array of calendar events in a channel. channelID : The ID of a Channel. data : The data for the event.

func (*Session) ChannelForumTopicCreate

func (s *Session) ChannelForumTopicCreate(channelID, title, content string) (*ForumTopic, error)

ChannelForumTopicCreate creates a topic in a channel. channelID : The ID of a Channel. title : The title of the topic. content : The content of the topic.

func (*Session) ChannelGet

func (s *Session) ChannelGet(channelID string) (*ServerChannel, error)

ChannelGet returns a channel. channelID : The ID of a Channel.

func (*Session) ChannelListItem

func (s *Session) ChannelListItem(channelID, itemID string) (*ListItem, error)

ChannelListItem returns a list item in a channel. channelID : The ID of a Channel. itemID : The ID of a ListItem.

func (*Session) ChannelListItemComplete

func (s *Session) ChannelListItemComplete(channelID, itemID string) error

ChannelListItemComplete completes a list item in a channel. channelID : The ID of a Channel. itemID : The ID of a ListItem.

func (*Session) ChannelListItemCreate

func (s *Session) ChannelListItemCreate(channelID string, data *ChannelListItem) (*ListItem, error)

ChannelListItem creates a list item in a channel. channelID : The ID of a Channel. data : The data for the list item.

func (*Session) ChannelListItemDelete

func (s *Session) ChannelListItemDelete(channelID, itemID string) error

ChannelListItemDelete deletes a list item in a channel. channelID : The ID of a Channel. itemID : The ID of a ListItem.

func (*Session) ChannelListItemUncomplete

func (s *Session) ChannelListItemUncomplete(channelID, itemID string) error

ChannelListItemUncomplete uncompletes a list item in a channel. channelID : The ID of a Channel. itemID : The ID of a ListItem.

func (*Session) ChannelListItemUpdate

func (s *Session) ChannelListItemUpdate(channelID, itemID string, data *ChannelListItem) (*ListItem, error)

ChannelListItemUpdate updates a list item in a channel. channelID : The ID of a Channel. itemID : The ID of a ListItem. data : The data for the list item.

func (*Session) ChannelListItems

func (s *Session) ChannelListItems(channelID string) ([]*ListItem, error)

ChannelListItems returns an array of list items in a channel without notes content. channelID : The ID of a Channel.

func (*Session) ChannelMessage

func (s *Session) ChannelMessage(channelID string, messageID string) (*ChatMessage, error)

ChannelMessage returns a message from a channel. channelID : The ID of a Channel. messageID : The ID of a Message.

func (*Session) ChannelMessageCreate

func (s *Session) ChannelMessageCreate(channelID string, content string) (*ChatMessage, error)

ChannelMessageCreate sends a message to the given channel. channelID : The ID of a Channel. content : The message to send.

func (*Session) ChannelMessageCreateComplex

func (s *Session) ChannelMessageCreateComplex(channelID string, data *MessageCreate) (st *ChatMessage, err error)

ChannelMessageCreateComplex sends a message to the given channel. channelID : The ID of a Channel. data : The message struct to send.

func (*Session) ChannelMessageDelete

func (s *Session) ChannelMessageDelete(channelID, messageID string) error

ChannelMessageDelete deletes a message in a channel. channelID : The ID of a Channel. messageID : The ID of a Message.

func (*Session) ChannelMessageUpdate

func (s *Session) ChannelMessageUpdate(channelID, messageID string, data *MessageUpdate) (*ChatMessage, error)

ChannelMessageUpdate updates a message in a channel. channelID : The ID of a Channel. messageID : The ID of a Message. data : The message struct to send.

func (*Session) ChannelMessages

func (s *Session) ChannelMessages(channelID string, limit int, beforeTime, afterTime *time.Time, includePrivate bool) ([]*ChatMessage, error)

ChannelMessages returns an array of messages from a channel. channelID : The ID of a Channel. limit : The number of messages to return. beforeTime : The time before which messages are to be returned. afterTime : The time after which messages are to be returned. includePrivate : Whether to include private messages.

func (*Session) ChannelUpdate

func (s *Session) ChannelUpdate(channelID string, data *ChannelUpdate) (*ServerChannel, error)

ChannelUpdate updates a channel. channelID : The ID of a Channel. data : The channel struct to send.

func (*Session) Close

func (s *Session) Close() error

Close closes a websocket and stops all listening/heartbeat goroutines.

func (*Session) CloseWithCode

func (s *Session) CloseWithCode(closeCode int) (err error)

CloseWithCode closes a websocket using the provided closeCode and stops all listening/heartbeat goroutines.

func (*Session) GroupMemberAdd

func (s *Session) GroupMemberAdd(groupID, userID string) error

GroupMemberAdd adds a member to a group. groupID : The ID of a Group. memberID : The ID of a Member.

func (*Session) GroupMemberRemove

func (s *Session) GroupMemberRemove(groupID, userID string) error

GroupMemberRemove removes a member from a group. groupID : The ID of a Group. memberID : The ID of a Member.

func (*Session) Open

func (s *Session) Open() error

Open creates a websocket connection to Guilded. See: https://www.guilded.gg/docs/api/connecting

func (*Session) Request

func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error)

Request is the same as RequestWithBucketID but the bucket id is the same as the urlStr

func (*Session) RequestCall

func (s *Session) RequestCall(method, urlStr, contentType string, b []byte, sequence int) (response []byte, err error)

RequestCall makes a request using a bucket that's already been locked

func (*Session) ServerGet

func (s *Session) ServerGet(serverID string) (*Server, error)

func (*Session) ServerMemberBan

func (s *Session) ServerMemberBan(serverID, userID string) (*ServerMemberBan, error)

ServerMemberBan returns a ban on a member of a server. serverID : The ID of a Server. userID : The ID of a User.

func (*Session) ServerMemberBanCreate

func (s *Session) ServerMemberBanCreate(serverID, userID, reason string) (*ServerMemberBan, error)

ServerMemberBanCreate creates a ban on a member of a server. serverID : The ID of a Server. userID : The ID of a User. reason : The reason for the ban.

func (*Session) ServerMemberBanDelete

func (s *Session) ServerMemberBanDelete(serverID, userID string) error

ServerMemberBanDelete deletes a ban on a member of a server. serverID : The ID of a Server. userID : The ID of a User.

func (*Session) ServerMemberBans

func (s *Session) ServerMemberBans(serverID string) ([]*ServerMemberBan, error)

ServerMemberBans returns an array of bans on a member of a server. serverID : The ID of a Server.

func (*Session) ServerMemberGet

func (s *Session) ServerMemberGet(serverID, userID string) (*ServerMember, error)

ServerMemberGet returns a member of the server. serverID : The ID of a Server. userID : The ID of a User.

func (*Session) ServerMemberKick

func (s *Session) ServerMemberKick(serverID, userID string) error

ServerMemberKick kicks a member from a server. serverID : The ID of a Server. userID : The ID of a User.

func (*Session) ServerMemberNicknameDelete

func (s *Session) ServerMemberNicknameDelete(serverID, userID string) error

ServerMemberNicknameDelete deletes a member's nickname in a server. serverID : The ID of a Server. userID : The ID of a User.

func (*Session) ServerMemberNicknameUpdate

func (s *Session) ServerMemberNicknameUpdate(serverID, userID string, nickname string) (string, error)

ServerMemberNicknameUpdate updates a member's nickname in a server. serverID : The ID of a Server. userID : The ID of a User. nickname : The nickname to set.

func (*Session) ServerMemberRoleAdd

func (s *Session) ServerMemberRoleAdd(serverID, memberID string, roleID int) error

ServerMemberRoleAdd adds a role to a member of a server. serverID : The ID of a Server. memberID : The ID of a Member. roleID : The ID of a Role.

func (*Session) ServerMemberRoleRemove

func (s *Session) ServerMemberRoleRemove(serverID, memberID string, roleID int) error

ServerMemberRoleRemove removes a role from a member of a server. serverID : The ID of a Server. memberID : The ID of a Member. roleID : The ID of a Role.

func (*Session) ServerMemberRoles

func (s *Session) ServerMemberRoles(serverID, memberID string) ([]int, error)

ServerMemberRoles returns a list of roles of a member of a server. serverID : The ID of a Server. memberID : The ID of a Member.

func (s *Session) ServerMemberSocialLink(serverID, memberID, linkType string) (*ServerSocialLink, error)

ServerMemberSocialLink returns a social link of a member of a server. serverID : The ID of a Server. memberID : The ID of a Member. linkType : The type of the social-link.

func (*Session) ServerMemberXPAward

func (s *Session) ServerMemberXPAward(serverID, memberID string, amount int) (int, error)

ServerMemberXPAward awards XP to a member of a server. serverID : The ID of a Server. memberID : The ID of a Member. amount : The amount of XP to award.

func (*Session) ServerMembers

func (s *Session) ServerMembers(serverID string) ([]*ServerMember, error)

ServerMembers returns an array of members of a server. serverID : The ID of a Server.

func (*Session) ServerRoleXPAward

func (s *Session) ServerRoleXPAward(serverID, roleID string, amount int) (int, error)

ServerRoleXPAward awards XP to a role of a server. serverID : The ID of a Server. roleID : The ID of a Role. amount : The amount of XP to award.

func (*Session) ServerWebhook

func (s *Session) ServerWebhook(serverID, webhookID string) (*Webhook, error)

ServerWebhook returns a webhook in a server. serverID : The ID of a Server. webhookID : The ID of a Webhook.

func (*Session) ServerWebhookCreate

func (s *Session) ServerWebhookCreate(serverID string, data *WebhookCreate) (*Webhook, error)

ServerWebhookCreate creates a webhook in a server. serverID : The ID of a Server. data : The data for the webhook.

func (*Session) ServerWebhookDelete

func (s *Session) ServerWebhookDelete(serverID, webhookID string) error

func (*Session) ServerWebhookUpdate

func (s *Session) ServerWebhookUpdate(serverID, webhookID string, data *WebhookUpdate) (*Webhook, error)

ServerWebhookUpdate updates a webhook in a server. serverID : The ID of a Server. webhookID : The ID of a Webhook. data : The data for the webhook.

func (*Session) ServerWebhooks

func (s *Session) ServerWebhooks(serverID string) ([]*Webhook, error)

ServerWebhooks returns a list of webhooks in a server. serverID : The ID of a Server.

type TeamChannelCreated

type TeamChannelCreated struct {
	ServerID string        `json:"serverId"`
	Channel  ServerChannel `json:"channel"`
}

type TeamChannelUpdated

type TeamChannelUpdated struct {
	ServerID string        `json:"serverId"`
	Channel  ServerChannel `json:"channel"`
}

type TeamMemberBanned

type TeamMemberBanned struct {
	ServerID        string          `json:"serverId"`
	ServerMemberBan ServerMemberBan `json:"serverMemberBan"`
}

type TeamMemberJoined

type TeamMemberJoined struct {
	ServerID string       `json:"serverId"`
	Member   ServerMember `json:"member"`
}

type TeamMemberRemoved

type TeamMemberRemoved struct {
	ServerID string `json:"serverId"`
	UserID   string `json:"userId"`
	IsKick   bool   `json:"isKick"`
	IsBan    bool   `json:"isBan"`
}

type TeamMemberUnbanned

type TeamMemberUnbanned struct {
	ServerID        string          `json:"serverId"`
	ServerMemberBan ServerMemberBan `json:"serverMemberBan"`
}

type TeamMemberUpdated

type TeamMemberUpdated struct {
	ServerID string   `json:"serverId"`
	UserInfo UserInfo `json:"userInfo"`
}

type TeamRolesUpdated

type TeamRolesUpdated struct {
	ServerID      string       `json:"serverId"`
	MemberRoleIds []MemberRole `json:"memberRoleIds"`
}

type TeamWebhookCreated

type TeamWebhookCreated struct {
	ServerID string  `json:"serverId"`
	Webhook  Webhook `json:"webhook"`
}

type TeamWebhookUpdated

type TeamWebhookUpdated struct {
	ServerID string  `json:"serverId"`
	Webhook  Webhook `json:"webhook"`
}

type Timestamp

type Timestamp struct {
	RawTime string    `json:"rawTime"`
	Time    time.Time `json:"time"`
}

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

type User

type User struct {
	// The ID of the user
	ID string `json:"id"`

	// The type of the user
	// Can be "bot" or "user"
	Type string `json:"type"`

	// The name of the user
	Name string `json:"name"`

	// The avatar url of the user
	Avatar string `json:"avatar"`

	// The banner url of the user
	Banner string `json:"banner"`

	// The timestamp of when the user was created
	CreatedAt Timestamp `json:"createdAt"`
}

User stores the data of a user.

func (*User) Mention

func (u *User) Mention() string

Mention returns a string that can be used to mention the user.

type UserInfo

type UserInfo struct {
	ID       string `json:"id"`
	Nickname string `json:"nickname"`
}

type UserSummary

type UserSummary struct {
	ID     string `json:"id"`
	Type   string `json:"type"`
	Name   string `json:"name"`
	Avatar string `json:"avatar"`
}

type UserType

type UserType string
const (
	UserTypeUser UserType = "user"
	UserTypeBot  UserType = "bot"
)

type Webhook

type Webhook struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	ServerId  string     `json:"serverId"`
	ChannelId string     `json:"channelId"`
	CreatedAt Timestamp  `json:"createdAt"`
	CreatedBy string     `json:"createdBy"`
	DeletedAt *Timestamp `json:"deletedAt"`
	Token     string     `json:"token"`
}

type WebhookCreate

type WebhookCreate struct {
	Name      string `json:"name"`
	ChannelID string `json:"channelId"`
}

type WebhookUpdate

type WebhookUpdate struct {
	Name      string `json:"name"`
	ChannelID string `json:"channelId"`
}

Directories

Path Synopsis
examples
pingpong command
tools

Jump to

Keyboard shortcuts

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