@@ -16,6 +16,7 @@ import (
16
16
"fmt"
17
17
"math"
18
18
"net/http"
19
+ "regexp"
19
20
"strings"
20
21
"sync"
21
22
"time"
@@ -353,6 +354,11 @@ type Emoji struct {
353
354
Available bool `json:"available"`
354
355
}
355
356
357
+ // EmojiRegex is the regex used to find and identify emojis in messages
358
+ var (
359
+ EmojiRegex = regexp .MustCompile (`<(a|):[A-z0-9_~]+:[0-9]{18}>` )
360
+ )
361
+
356
362
// MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
357
363
func (e * Emoji ) MessageFormat () string {
358
364
if e .ID != "" && e .Name != "" {
@@ -1114,9 +1120,74 @@ type GatewayStatusUpdate struct {
1114
1120
// Activity defines the Activity sent with GatewayStatusUpdate
1115
1121
// https://discord.com/developers/docs/topics/gateway#activity-object
1116
1122
type Activity struct {
1117
- Name string `json:"name"`
1118
- Type ActivityType `json:"type"`
1119
- URL string `json:"url,omitempty"`
1123
+ Name string `json:"name"`
1124
+ Type ActivityType `json:"type"`
1125
+ URL string `json:"url,omitempty"`
1126
+ CreatedAt time.Time `json:"created_at"`
1127
+ ApplicationID string `json:"application_id,omitempty"`
1128
+ State string `json:"state,omitempty"`
1129
+ Details string `json:"details,omitempty"`
1130
+ Timestamps TimeStamps `json:"timestamps,omitempty"`
1131
+ Emoji Emoji `json:"emoji,omitempty"`
1132
+ Party Party `json:"party,omitempty"`
1133
+ Assets Assets `json:"assets,omitempty"`
1134
+ Secrets Secrets `json:"secrets,omitempty"`
1135
+ Instance bool `json:"instance,omitempty"`
1136
+ Flags int `json:"flags,omitempty"`
1137
+ }
1138
+
1139
+ // UnmarshalJSON is a custom unmarshaljson to make CreatedAt a time.Time instead of an int
1140
+ func (activity * Activity ) UnmarshalJSON (b []byte ) error {
1141
+ temp := struct {
1142
+ Name string `json:"name"`
1143
+ Type ActivityType `json:"type"`
1144
+ URL string `json:"url,omitempty"`
1145
+ CreatedAt int64 `json:"created_at"`
1146
+ ApplicationID string `json:"application_id,omitempty"`
1147
+ State string `json:"state,omitempty"`
1148
+ Details string `json:"details,omitempty"`
1149
+ Timestamps TimeStamps `json:"timestamps,omitempty"`
1150
+ Emoji Emoji `json:"emoji,omitempty"`
1151
+ Party Party `json:"party,omitempty"`
1152
+ Assets Assets `json:"assets,omitempty"`
1153
+ Secrets Secrets `json:"secrets,omitempty"`
1154
+ Instance bool `json:"instance,omitempty"`
1155
+ Flags int `json:"flags,omitempty"`
1156
+ }{}
1157
+ err := json .Unmarshal (b , & temp )
1158
+ if err != nil {
1159
+ return err
1160
+ }
1161
+ activity .CreatedAt = time .Unix (0 , temp .CreatedAt * 1000000 )
1162
+ activity .ApplicationID = temp .ApplicationID
1163
+ activity .Assets = temp .Assets
1164
+ activity .Details = temp .Details
1165
+ activity .Emoji = temp .Emoji
1166
+ activity .Flags = temp .Flags
1167
+ activity .Instance = temp .Instance
1168
+ activity .Name = temp .Name
1169
+ activity .Party = temp .Party
1170
+ activity .Secrets = temp .Secrets
1171
+ activity .State = temp .State
1172
+ activity .Timestamps = temp .Timestamps
1173
+ activity .Type = temp .Type
1174
+ activity .URL = temp .URL
1175
+ return nil
1176
+ }
1177
+
1178
+ // Party defines the Party field in the Activity struct
1179
+ // https://discord.com/developers/docs/topics/gateway#activity-object
1180
+ type Party struct {
1181
+ ID string `json:"id,omitempty"`
1182
+ Size []int `json:"size,omitempty"`
1183
+ }
1184
+
1185
+ // Secrets defines the Secrets field for the Activity struct
1186
+ // https://discord.com/developers/docs/topics/gateway#activity-object
1187
+ type Secrets struct {
1188
+ Join string `json:"join,omitempty"`
1189
+ Spectate string `json:"spectate,omitempty"`
1190
+ Match string `json:"match,omitempty"`
1120
1191
}
1121
1192
1122
1193
// ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
0 commit comments