diff --git a/api/emoji.go b/api/emoji.go index ec2102a..6cf4a10 100644 --- a/api/emoji.go +++ b/api/emoji.go @@ -5,14 +5,13 @@ import ( "github.com/diamondburned/arikawa/utils/httputil" ) -// EmojiAPI is a special format that the API wants. -type EmojiAPI = string - -func FormatEmojiAPI(id discord.Snowflake, name string) string { - if id == 0 { - return name - } +// Emoji is the API format of a regular Emoji, both Unicode or custom. +type Emoji = string +// NewCustomEmoji creates a new Emoji using a custom guild emoji as +// base. +// Unicode emojis should be directly passed to the function using Emoji. +func NewCustomEmoji(id discord.Snowflake, name string) Emoji { return name + ":" + id.String() } diff --git a/api/guild.go b/api/guild.go index a8189a9..8e01f8d 100644 --- a/api/guild.go +++ b/api/guild.go @@ -157,8 +157,8 @@ func (c *Client) GuildsRange(before, after discord.Snowflake, limit uint) ([]dis } var param struct { - Before discord.Snowflake `schema:"before"` - After discord.Snowflake `schema:"after"` + Before discord.Snowflake `schema:"before,omitempty"` + After discord.Snowflake `schema:"after,omitempty"` Limit uint `schema:"limit"` } @@ -251,6 +251,7 @@ func (c *Client) ModifyGuild(id discord.Snowflake, data ModifyGuildData) (*disco EndpointGuilds+id.String(), httputil.WithJSONBody(data), ) + } // DeleteGuild deletes a guild permanently. The User must be owner. @@ -321,6 +322,9 @@ func (c *Client) AttachIntegration(guildID, ID discord.Snowflake `json:"id"` } + param.Type = integrationType + param.ID = integrationID + return c.FastRequest( "POST", EndpointGuilds+guildID.String()+"/integrations", diff --git a/api/message_reaction.go b/api/message_reaction.go index c51e4b9..6a05e1c 100644 --- a/api/message_reaction.go +++ b/api/message_reaction.go @@ -1,10 +1,13 @@ package api import ( + "net/url" + "github.com/diamondburned/arikawa/discord" "github.com/diamondburned/arikawa/utils/httputil" ) + // React creates a reaction for the message. // // This endpoint requires the READ_MESSAGE_HISTORY permission to be present on @@ -14,10 +17,11 @@ import ( func (c *Client) React(channelID, messageID discord.Snowflake, emoji EmojiAPI) error { var msgURL = EndpointChannels + channelID.String() + "/messages/" + messageID.String() + - "/reactions/" + emoji + "/@me" + "/reactions/" + url.PathEscape(emoji) + "/@me" return c.FastRequest("PUT", msgURL) } + // Unreact removes a reaction the current user has made for the message. func (c *Client) Unreact(chID, msgID discord.Snowflake, emoji EmojiAPI) error { return c.DeleteUserReaction(chID, msgID, 0, emoji) @@ -62,7 +66,7 @@ func (c *Client) Reactions( // ReactionsBefore gets all reactions before the passed user ID. func (c *Client) ReactionsBefore( channelID, messageID, before discord.Snowflake, - limit uint, emoji EmojiAPI) ([]discord.User, error) { + limit uint, emoji Emoji) ([]discord.User, error) { return c.ReactionsRange(channelID, messageID, before, 0, limit, emoji) } @@ -70,7 +74,7 @@ func (c *Client) ReactionsBefore( // Refer to ReactionsRange. func (c *Client) ReactionsAfter( channelID, messageID, after discord.Snowflake, - limit uint, emoji EmojiAPI) ([]discord.User, error) { + limit uint, emoji Emoji) ([]discord.User, error) { return c.ReactionsRange(channelID, messageID, 0, after, limit, emoji) } @@ -79,7 +83,7 @@ func (c *Client) ReactionsAfter( // optional. A maximum limit of only 100 reactions could be returned. func (c *Client) ReactionsRange( channelID, messageID, before, after discord.Snowflake, - limit uint, emoji EmojiAPI) ([]discord.User, error) { + limit uint, emoji Emoji) ([]discord.User, error) { switch { case limit == 0: @@ -103,7 +107,7 @@ func (c *Client) ReactionsRange( return users, c.RequestJSON( &users, "GET", EndpointChannels+channelID.String()+ "/messages/"+messageID.String()+ - "/reactions/"+emoji, + "/reactions/"+url.PathEscape(emoji), httputil.WithSchema(c, param), ) } @@ -120,9 +124,9 @@ func (c *Client) DeleteUserReaction( user = userID.String() } - return c.FastRequest("DELETE", EndpointChannels+channelID.String()+ - "/messages/"+messageID.String()+ - "/reactions/"+emoji+"/"+user) + return c.FastRequest("DELETE", EndpointChannels+chID.String()+ + "/messages/"+msgID.String()+ + "/reactions/"+url.PathEscape(emoji)+"/"+user) } // DeleteReactions deletes all the reactions for a given emoji on a message. @@ -133,9 +137,11 @@ func (c *Client) DeleteUserReaction( func (c *Client) DeleteReactions( channelId, messageID discord.Snowflake, emoji EmojiAPI) error { - return c.FastRequest("DELETE", EndpointChannels+channelId.String()+ - "/messages/"+messageID.String()+ - "/reactions/"+emoji) + return c.FastRequest( + "DELETE", + EndpointChannels+channelId.String()+"/messages/"+messageID.String()+ + "/reactions/"+url.PathEscape(emoji), + ) } // DeleteAllReactions deletes all reactions on a message. diff --git a/api/webhook.go b/api/webhook.go index 22a7dda..69abefd 100644 --- a/api/webhook.go +++ b/api/webhook.go @@ -98,7 +98,8 @@ func (c *Client) ModifyWebhookWithToken( return w, c.RequestJSON( &w, "PATCH", EndpointWebhooks+webhookID.String()+"/"+token, - httputil.WithJSONBody(data)) + httputil.WithJSONBody(data), + ) } // DeleteWebhook deletes a webhook permanently. diff --git a/state/state_events.go b/state/state_events.go index b7e434d..739d3bd 100644 --- a/state/state_events.go +++ b/state/state_events.go @@ -238,6 +238,8 @@ func (s *State) onEvent(iface interface{}) { } } + case *gateway.SessionsReplaceEvent: + case *gateway.UserGuildSettingsUpdateEvent: for i, ugs := range s.Ready.UserGuildSettings { if ugs.GuildID == ev.GuildID { diff --git a/utils/heart/heart.go b/utils/heart/heart.go index 96acedc..2c19a2e 100644 --- a/utils/heart/heart.go +++ b/utils/heart/heart.go @@ -125,14 +125,11 @@ func (p *Pacemaker) start() error { p.Echo() for { - Debug("Pacemaker loop restarted.") if err := p.Pace(); err != nil { return err } - Debug("Paced.") - // Paced, save: p.SentBeat.Set(time.Now()) @@ -142,11 +139,9 @@ func (p *Pacemaker) start() error { select { case <-p.stop.Recv(): - Debug("Received stop signal.") return nil case <-tick.C: - Debug("Ticked. Restarting.") } } } diff --git a/utils/wsutil/heart.go b/utils/wsutil/heart.go index 197289d..dfb549f 100644 --- a/utils/wsutil/heart.go +++ b/utils/wsutil/heart.go @@ -84,11 +84,13 @@ func (p *PacemakerLoop) startLoop() error { for { select { case err := <-p.pacedeath: - // return nil if err == nil + WSDebug("Pacedeath returned with error:", err) return errors.Wrap(err, "Pacemaker died, reconnecting") case ev, ok := <-p.events: if !ok { + WSDebug("Events channel closed, stopping pacemaker.") + defer WSDebug("Pacemaker stopped automatically.") // Events channel is closed. Kill the pacemaker manually and // die. p.pacemaker.Stop()