Merge branch 'master' into 44-data-structs
This commit is contained in:
commit
ae14c8fb73
13
api/emoji.go
13
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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue