|
@@ -16,6 +16,7 @@ import (
|
|
|
"fmt"
|
|
|
"math"
|
|
|
"net/http"
|
|
|
+ "regexp"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
@@ -353,6 +354,11 @@ type Emoji struct {
|
|
|
Available bool `json:"available"`
|
|
|
}
|
|
|
|
|
|
+// EmojiRegex is the regex used to find and identify emojis in messages
|
|
|
+var (
|
|
|
+ EmojiRegex = regexp.MustCompile(`<(a|):[A-z0-9_~]+:[0-9]{18}>`)
|
|
|
+)
|
|
|
+
|
|
|
// MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
|
|
|
func (e *Emoji) MessageFormat() string {
|
|
|
if e.ID != "" && e.Name != "" {
|
|
@@ -1114,9 +1120,74 @@ type GatewayStatusUpdate struct {
|
|
|
// Activity defines the Activity sent with GatewayStatusUpdate
|
|
|
// https://discord.com/developers/docs/topics/gateway#activity-object
|
|
|
type Activity struct {
|
|
|
- Name string `json:"name"`
|
|
|
- Type ActivityType `json:"type"`
|
|
|
- URL string `json:"url,omitempty"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Type ActivityType `json:"type"`
|
|
|
+ URL string `json:"url,omitempty"`
|
|
|
+ CreatedAt time.Time `json:"created_at"`
|
|
|
+ ApplicationID string `json:"application_id,omitempty"`
|
|
|
+ State string `json:"state,omitempty"`
|
|
|
+ Details string `json:"details,omitempty"`
|
|
|
+ Timestamps TimeStamps `json:"timestamps,omitempty"`
|
|
|
+ Emoji Emoji `json:"emoji,omitempty"`
|
|
|
+ Party Party `json:"party,omitempty"`
|
|
|
+ Assets Assets `json:"assets,omitempty"`
|
|
|
+ Secrets Secrets `json:"secrets,omitempty"`
|
|
|
+ Instance bool `json:"instance,omitempty"`
|
|
|
+ Flags int `json:"flags,omitempty"`
|
|
|
+}
|
|
|
+
|
|
|
+// UnmarshalJSON is a custom unmarshaljson to make CreatedAt a time.Time instead of an int
|
|
|
+func (activity *Activity) UnmarshalJSON(b []byte) error {
|
|
|
+ temp := struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ Type ActivityType `json:"type"`
|
|
|
+ URL string `json:"url,omitempty"`
|
|
|
+ CreatedAt int64 `json:"created_at"`
|
|
|
+ ApplicationID string `json:"application_id,omitempty"`
|
|
|
+ State string `json:"state,omitempty"`
|
|
|
+ Details string `json:"details,omitempty"`
|
|
|
+ Timestamps TimeStamps `json:"timestamps,omitempty"`
|
|
|
+ Emoji Emoji `json:"emoji,omitempty"`
|
|
|
+ Party Party `json:"party,omitempty"`
|
|
|
+ Assets Assets `json:"assets,omitempty"`
|
|
|
+ Secrets Secrets `json:"secrets,omitempty"`
|
|
|
+ Instance bool `json:"instance,omitempty"`
|
|
|
+ Flags int `json:"flags,omitempty"`
|
|
|
+ }{}
|
|
|
+ err := json.Unmarshal(b, &temp)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ activity.CreatedAt = time.Unix(0, temp.CreatedAt*1000000)
|
|
|
+ activity.ApplicationID = temp.ApplicationID
|
|
|
+ activity.Assets = temp.Assets
|
|
|
+ activity.Details = temp.Details
|
|
|
+ activity.Emoji = temp.Emoji
|
|
|
+ activity.Flags = temp.Flags
|
|
|
+ activity.Instance = temp.Instance
|
|
|
+ activity.Name = temp.Name
|
|
|
+ activity.Party = temp.Party
|
|
|
+ activity.Secrets = temp.Secrets
|
|
|
+ activity.State = temp.State
|
|
|
+ activity.Timestamps = temp.Timestamps
|
|
|
+ activity.Type = temp.Type
|
|
|
+ activity.URL = temp.URL
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+// Party defines the Party field in the Activity struct
|
|
|
+// https://discord.com/developers/docs/topics/gateway#activity-object
|
|
|
+type Party struct {
|
|
|
+ ID string `json:"id,omitempty"`
|
|
|
+ Size []int `json:"size,omitempty"`
|
|
|
+}
|
|
|
+
|
|
|
+// Secrets defines the Secrets field for the Activity struct
|
|
|
+// https://discord.com/developers/docs/topics/gateway#activity-object
|
|
|
+type Secrets struct {
|
|
|
+ Join string `json:"join,omitempty"`
|
|
|
+ Spectate string `json:"spectate,omitempty"`
|
|
|
+ Match string `json:"match,omitempty"`
|
|
|
}
|
|
|
|
|
|
// ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
|