Updates API (#785)

* Update to API

Updates the golang stuct to current api documentation and adds new util

* Revert of change.

* Update message.go

* Update structs.go

* Yikes this my hand hurts.

* Consistency

* Update message.go
This commit is contained in:
TroyDota 2020-06-29 00:53:46 +02:00 committed by GitHub
parent 9c46cf4ec7
commit 9ce4a230c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 293 additions and 89 deletions

View file

@ -16,6 +16,7 @@ import (
)
// MessageType is the type of Message
// https://discord.com/developers/docs/resources/channel#message-object-message-types
type MessageType int
// Block contains the valid known MessageType values
@ -33,6 +34,8 @@ const (
MessageTypeUserPremiumGuildSubscriptionTierTwo
MessageTypeUserPremiumGuildSubscriptionTierThree
MessageTypeChannelFollowAdd
MessageTypeGuildDiscoveryDisqualified
MessageTypeGuildDiscoveryRequalified
)
// A Message stores all data related to a specific Discord message.
@ -117,9 +120,22 @@ type Message struct {
// The flags of the message, which describe extra features of a message.
// This is a combination of bit masks; the presence of a certain permission can
// be checked by performing a bitwise AND between this int and the flag.
Flags int `json:"flags"`
Flags MessageFlags `json:"flags"`
}
// MessageFlags is the flags of "message" (see MessageFlags* consts)
// https://discord.com/developers/docs/resources/channel#message-object-message-flags
type MessageFlags int
// Valid MessageFlags values
const (
MessageFlagsCrossPosted MessageFlags = 1 << iota
MessageFlagsIsCrossPosted
MessageFlagsSupressEmbeds
MessageFlagsSourceMessageDeleted
MessageFlagsUrgent
)
// File stores info about files you e.g. send in messages.
type File struct {
Name string
@ -245,10 +261,9 @@ type MessageEmbedThumbnail struct {
// MessageEmbedVideo is a part of a MessageEmbed struct.
type MessageEmbedVideo struct {
URL string `json:"url,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
URL string `json:"url,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
}
// MessageEmbedProvider is a part of a MessageEmbed struct.
@ -275,7 +290,7 @@ type MessageEmbedField struct {
// An MessageEmbed stores data for message embeds.
type MessageEmbed struct {
URL string `json:"url,omitempty"`
Type string `json:"type,omitempty"`
Type EmbedType `json:"type,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
@ -289,6 +304,20 @@ type MessageEmbed struct {
Fields []*MessageEmbedField `json:"fields,omitempty"`
}
// EmbedType is the type of embed
// https://discord.com/developers/docs/resources/channel#embed-object-embed-types
type EmbedType string
// Block of valid EmbedTypes
const (
EmbedTypeRich EmbedType = "rich"
EmbedTypeImage EmbedType = "image"
EmbedTypeVideo EmbedType = "video"
EmbedTypeGifv EmbedType = "gifv"
EmbedTypeArticle EmbedType = "article"
EmbedTypeLink EmbedType = "link"
)
// MessageReactions holds a reactions object for a message.
type MessageReactions struct {
Count int `json:"count"`

View file

@ -143,13 +143,24 @@ type Integration struct {
Enabled bool `json:"enabled"`
Syncing bool `json:"syncing"`
RoleID string `json:"role_id"`
ExpireBehavior int `json:"expire_behavior"`
EnableEmoticons bool `json:"enable_emoticons"`
ExpireBehavior ExpireBehavior `json:"expire_behavior"`
ExpireGracePeriod int `json:"expire_grace_period"`
User *User `json:"user"`
Account IntegrationAccount `json:"account"`
SyncedAt Timestamp `json:"synced_at"`
}
//ExpireBehavior of Integration
// https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
type ExpireBehavior int
// Block of valid ExpireBehaviors
const (
ExpireBehaviorRemoveRole ExpireBehavior = iota
ExpireBehaviorKick
)
// IntegrationAccount is integration account information
// sent by the UserConnections endpoint
type IntegrationAccount struct {
@ -180,23 +191,34 @@ type ICEServer struct {
// A Invite stores all data related to a specific Discord Guild or Channel invite.
type Invite struct {
Guild *Guild `json:"guild"`
Channel *Channel `json:"channel"`
Inviter *User `json:"inviter"`
Code string `json:"code"`
CreatedAt Timestamp `json:"created_at"`
MaxAge int `json:"max_age"`
Uses int `json:"uses"`
MaxUses int `json:"max_uses"`
Revoked bool `json:"revoked"`
Temporary bool `json:"temporary"`
Unique bool `json:"unique"`
Guild *Guild `json:"guild"`
Channel *Channel `json:"channel"`
Inviter *User `json:"inviter"`
Code string `json:"code"`
CreatedAt Timestamp `json:"created_at"`
MaxAge int `json:"max_age"`
Uses int `json:"uses"`
MaxUses int `json:"max_uses"`
Revoked bool `json:"revoked"`
Temporary bool `json:"temporary"`
Unique bool `json:"unique"`
TargetUser *User `json:"target_user"`
TargetUserType TargetUserType `json:"target_user_type"`
// will only be filled when using InviteWithCounts
ApproximatePresenceCount int `json:"approximate_presence_count"`
ApproximateMemberCount int `json:"approximate_member_count"`
}
// TargetUserType is the type of the target user
// https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
type TargetUserType int
// Block contains known TargetUserType values
const (
TargetUserTypeStream TargetUserType = iota
)
// ChannelType is the type of a Channel
type ChannelType int
@ -268,6 +290,12 @@ type Channel struct {
// Amount of seconds a user has to wait before sending another message (0-21600)
// bots, as well as users with the permission manage_messages or manage_channel, are unaffected
RateLimitPerUser int `json:"rate_limit_per_user"`
// ID of the DM creator Zeroed if guild channel
OwnerID string `json:"owner_id"`
// ApplicationID of the DM creator Zeroed if guild channel or not a bot user
ApplicationID string `json:"application_id"`
}
// Mention returns a string which mentions the channel
@ -301,6 +329,7 @@ type Emoji struct {
ID string `json:"id"`
Name string `json:"name"`
Roles []string `json:"roles"`
User *User `json:"user"`
Managed bool `json:"managed"`
RequireColons bool `json:"require_colons"`
Animated bool `json:"animated"`
@ -398,11 +427,17 @@ type Guild struct {
// The user ID of the owner of the guild.
OwnerID string `json:"owner_id"`
// If we are the owner of the guild
Owner bool `json:"owner"`
// The time at which the current user joined the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
JoinedAt Timestamp `json:"joined_at"`
// The hash of the guild's discovery splash.
DiscoverySplash string `json:"discovery_splash"`
// The hash of the guild's splash.
Splash string `json:"splash"`
@ -426,8 +461,7 @@ type Guild struct {
Large bool `json:"large"`
// The default message notification setting for the guild.
// 0 == all messages, 1 == mentions only.
DefaultMessageNotifications int `json:"default_message_notifications"`
DefaultMessageNotifications MessageNotifications `json:"default_message_notifications"`
// A list of roles in the guild.
Roles []*Role `json:"roles"`
@ -445,6 +479,12 @@ type Guild struct {
// update events, and thus is only present in state-cached guilds.
Presences []*Presence `json:"presences"`
// The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned)
MaxPresences int `json:"max_presences"`
// The maximum number of members for the guild
MaxMembers int `json:"max_members"`
// A list of channels in the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
@ -469,6 +509,9 @@ type Guild struct {
// Required MFA level for the guild
MfaLevel MfaLevel `json:"mfa_level"`
// The application id of the guild if bot created.
ApplicationID string `json:"application_id"`
// Whether or not the Server Widget is enabled
WidgetEnabled bool `json:"widget_enabled"`
@ -478,6 +521,12 @@ type Guild struct {
// The Channel ID to which system messages are sent (eg join and leave messages)
SystemChannelID string `json:"system_channel_id"`
// The System channel flags
SystemChannelFlags SystemChannelFlag `json:"system_channel_flags"`
// The ID of the rules channel ID, used for rules.
RulesChannelID string `json:"rules_channel_id"`
// the vanity url code for the guild
VanityURLCode string `json:"vanity_url_code"`
@ -492,8 +541,46 @@ type Guild struct {
// The total number of users currently boosting this server
PremiumSubscriptionCount int `json:"premium_subscription_count"`
// The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US"
PreferredLocale string `json:"preferred_locale"`
// The id of the channel where admins and moderators of guilds with the "PUBLIC" feature receive notices from Discord
PublicUpdatesChannelID string `json:"public_updates_channel_id"`
// The maximum amount of users in a video channel
MaxVideoChannelUsers int `json:"max_video_channel_users"`
// Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
ApproximateMemberCount int `json:"approximate_member_count"`
// Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
ApproximatePresenceCount int `json:"approximate_presence_count"`
// Permissions of our user
Permissions int `json:"permissions"`
}
// MessageNotifications is the notification level for a guild
// https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level
type MessageNotifications int
// Block containing known MessageNotifications values
const (
MessageNotificationsAllMessages MessageNotifications = iota
MessageNotificationsOnlyMentions
)
// SystemChannelFlag is the type of flags in the system channel (see SystemChannelFlag* consts)
// https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags
type SystemChannelFlag int
// Block containing known SystemChannelFlag values
const (
SystemChannelFlagsSuppressJoin SystemChannelFlag = 1 << iota
SystemChannelFlagsSuppressPremium
)
// IconURL returns a URL to the guild's icon.
func (g *Guild) IconURL() string {
if g.Icon == "" {
@ -775,79 +862,157 @@ type GuildEmbed struct {
}
// A GuildAuditLog stores data for a guild audit log.
// https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
type GuildAuditLog struct {
Webhooks []struct {
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id"`
ID string `json:"id"`
Avatar string `json:"avatar"`
Name string `json:"name"`
} `json:"webhooks,omitempty"`
Users []struct {
Username string `json:"username"`
Discriminator string `json:"discriminator"`
Bot bool `json:"bot"`
ID string `json:"id"`
Avatar string `json:"avatar"`
} `json:"users,omitempty"`
AuditLogEntries []struct {
TargetID string `json:"target_id"`
Changes []struct {
NewValue interface{} `json:"new_value"`
OldValue interface{} `json:"old_value"`
Key string `json:"key"`
} `json:"changes,omitempty"`
UserID string `json:"user_id"`
ID string `json:"id"`
ActionType int `json:"action_type"`
Options struct {
DeleteMembersDay string `json:"delete_member_days"`
MembersRemoved string `json:"members_removed"`
ChannelID string `json:"channel_id"`
Count string `json:"count"`
ID string `json:"id"`
Type string `json:"type"`
RoleName string `json:"role_name"`
} `json:"options,omitempty"`
Reason string `json:"reason"`
} `json:"audit_log_entries"`
Webhooks []*Webhook `json:"webhooks,omitempty"`
Users []*User `json:"users,omitempty"`
AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
Integrations []*Integration `json:"integrations"`
}
// AuditLogEntry for a GuildAuditLog
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-entry-structure
type AuditLogEntry struct {
TargetID string `json:"target_id"`
Changes []*AuditLogChange `json:"changes"`
UserID string `json:"user_id"`
ID string `json:"id"`
ActionType *AuditLogAction `json:"action_type"`
Options *AuditLogOptions `json:"options"`
Reason string `json:"reason"`
}
// AuditLogChange for an AuditLogEntry
type AuditLogChange struct {
NewValue interface{} `json:"new_value"`
OldValue interface{} `json:"old_value"`
Key *AuditLogChangeKey `json:"key"`
}
// AuditLogChangeKey value for AuditLogChange
// https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
type AuditLogChangeKey string
// Block of valid AuditLogChangeKey
const (
AuditLogChangeKeyName AuditLogChangeKey = "name"
AuditLogChangeKeyIconHash AuditLogChangeKey = "icon_hash"
AuditLogChangeKeySplashHash AuditLogChangeKey = "splash_hash"
AuditLogChangeKeyOwnerID AuditLogChangeKey = "owner_id"
AuditLogChangeKeyRegion AuditLogChangeKey = "region"
AuditLogChangeKeyAfkChannelID AuditLogChangeKey = "afk_channel_id"
AuditLogChangeKeyAfkTimeout AuditLogChangeKey = "afk_timeout"
AuditLogChangeKeyMfaLevel AuditLogChangeKey = "mfa_level"
AuditLogChangeKeyVerificationLevel AuditLogChangeKey = "verification_level"
AuditLogChangeKeyExplicitContentFilter AuditLogChangeKey = "explicit_content_filter"
AuditLogChangeKeyDefaultMessageNotification AuditLogChangeKey = "default_message_notifications"
AuditLogChangeKeyVanityURLCode AuditLogChangeKey = "vanity_url_code"
AuditLogChangeKeyRoleAdd AuditLogChangeKey = "$add"
AuditLogChangeKeyRoleRemove AuditLogChangeKey = "$remove"
AuditLogChangeKeyPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
AuditLogChangeKeyWidgetEnabled AuditLogChangeKey = "widget_enabled"
AuditLogChangeKeyWidgetChannelID AuditLogChangeKey = "widget_channel_id"
AuditLogChangeKeySystemChannelID AuditLogChangeKey = "system_channel_id"
AuditLogChangeKeyPosition AuditLogChangeKey = "position"
AuditLogChangeKeyTopic AuditLogChangeKey = "topic"
AuditLogChangeKeyBitrate AuditLogChangeKey = "bitrate"
AuditLogChangeKeyPermissionOverwrite AuditLogChangeKey = "permission_overwrites"
AuditLogChangeKeyNSFW AuditLogChangeKey = "nsfw"
AuditLogChangeKeyApplicationID AuditLogChangeKey = "application_id"
AuditLogChangeKeyRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
AuditLogChangeKeyPermissions AuditLogChangeKey = "permissions"
AuditLogChangeKeyColor AuditLogChangeKey = "color"
AuditLogChangeKeyHoist AuditLogChangeKey = "hoist"
AuditLogChangeKeyMentionable AuditLogChangeKey = "mentionable"
AuditLogChangeKeyAllow AuditLogChangeKey = "allow"
AuditLogChangeKeyDeny AuditLogChangeKey = "deny"
AuditLogChangeKeyCode AuditLogChangeKey = "code"
AuditLogChangeKeyChannelID AuditLogChangeKey = "channel_id"
AuditLogChangeKeyInviterID AuditLogChangeKey = "inviter_id"
AuditLogChangeKeyMaxUses AuditLogChangeKey = "max_uses"
AuditLogChangeKeyUses AuditLogChangeKey = "uses"
AuditLogChangeKeyMaxAge AuditLogChangeKey = "max_age"
AuditLogChangeKeyTempoary AuditLogChangeKey = "temporary"
AuditLogChangeKeyDeaf AuditLogChangeKey = "deaf"
AuditLogChangeKeyMute AuditLogChangeKey = "mute"
AuditLogChangeKeyNick AuditLogChangeKey = "nick"
AuditLogChangeKeyAvatarHash AuditLogChangeKey = "avatar_hash"
AuditLogChangeKeyID AuditLogChangeKey = "id"
AuditLogChangeKeyType AuditLogChangeKey = "type"
AuditLogChangeKeyEnableEmoticons AuditLogChangeKey = "enable_emoticons"
AuditLogChangeKeyExpireBehavior AuditLogChangeKey = "expire_behavior"
AuditLogChangeKeyExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
)
// AuditLogOptions optional data for the AuditLog
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
type AuditLogOptions struct {
DeleteMemberDays string `json:"delete_member_days"`
MembersRemoved string `json:"members_removed"`
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
Count string `json:"count"`
ID string `json:"id"`
Type *AuditLogOptionsType `json:"type"`
RoleName string `json:"role_name"`
}
// AuditLogOptionsType of the AuditLogOption
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
type AuditLogOptionsType string
// Valid Types for AuditLogOptionsType
const (
AuditLogOptionsTypeMember AuditLogOptionsType = "member"
AuditLogOptionsTypeRole AuditLogOptionsType = "role"
)
// AuditLogAction is the Action of the AuditLog (see AuditLogAction* consts)
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
type AuditLogAction int
// Block contains Discord Audit Log Action Types
const (
AuditLogActionGuildUpdate = 1
AuditLogActionGuildUpdate AuditLogAction = 1
AuditLogActionChannelCreate = 10
AuditLogActionChannelUpdate = 11
AuditLogActionChannelDelete = 12
AuditLogActionChannelOverwriteCreate = 13
AuditLogActionChannelOverwriteUpdate = 14
AuditLogActionChannelOverwriteDelete = 15
AuditLogActionChannelCreate AuditLogAction = 10
AuditLogActionChannelUpdate AuditLogAction = 11
AuditLogActionChannelDelete AuditLogAction = 12
AuditLogActionChannelOverwriteCreate AuditLogAction = 13
AuditLogActionChannelOverwriteUpdate AuditLogAction = 14
AuditLogActionChannelOverwriteDelete AuditLogAction = 15
AuditLogActionMemberKick = 20
AuditLogActionMemberPrune = 21
AuditLogActionMemberBanAdd = 22
AuditLogActionMemberBanRemove = 23
AuditLogActionMemberUpdate = 24
AuditLogActionMemberRoleUpdate = 25
AuditLogActionMemberKick AuditLogAction = 20
AuditLogActionMemberPrune AuditLogAction = 21
AuditLogActionMemberBanAdd AuditLogAction = 22
AuditLogActionMemberBanRemove AuditLogAction = 23
AuditLogActionMemberUpdate AuditLogAction = 24
AuditLogActionMemberRoleUpdate AuditLogAction = 25
AuditLogActionRoleCreate = 30
AuditLogActionRoleUpdate = 31
AuditLogActionRoleDelete = 32
AuditLogActionRoleCreate AuditLogAction = 30
AuditLogActionRoleUpdate AuditLogAction = 31
AuditLogActionRoleDelete AuditLogAction = 32
AuditLogActionInviteCreate = 40
AuditLogActionInviteUpdate = 41
AuditLogActionInviteDelete = 42
AuditLogActionInviteCreate AuditLogAction = 40
AuditLogActionInviteUpdate AuditLogAction = 41
AuditLogActionInviteDelete AuditLogAction = 42
AuditLogActionWebhookCreate = 50
AuditLogActionWebhookUpdate = 51
AuditLogActionWebhookDelete = 52
AuditLogActionWebhookCreate AuditLogAction = 50
AuditLogActionWebhookUpdate AuditLogAction = 51
AuditLogActionWebhookDelete AuditLogAction = 52
AuditLogActionEmojiCreate = 60
AuditLogActionEmojiUpdate = 61
AuditLogActionEmojiDelete = 62
AuditLogActionEmojiCreate AuditLogAction = 60
AuditLogActionEmojiUpdate AuditLogAction = 61
AuditLogActionEmojiDelete AuditLogAction = 62
AuditLogActionMessageDelete = 72
AuditLogActionMessageDelete AuditLogAction = 72
AuditLogActionMessageBulkDelete AuditLogAction = 73
AuditLogActionMessagePin AuditLogAction = 74
AuditLogActionMessageUnpin AuditLogAction = 75
AuditLogActionIntegrationCreate AuditLogAction = 80
AuditLogActionIntegrationUpdate AuditLogAction = 81
AuditLogActionIntegrationDelete AuditLogAction = 82
)
// A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
@ -884,15 +1049,26 @@ type APIErrorMessage struct {
// Webhook stores the data for a webhook.
type Webhook struct {
ID string `json:"id"`
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
User *User `json:"user"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Token string `json:"token"`
ID string `json:"id"`
Type WebhookType `json:"type"`
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
User *User `json:"user"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Token string `json:"token"`
}
// WebhookType is the type of Webhook (see WebhookType* consts) in the Webhook struct
// https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types
type WebhookType int
// Valid WebhookType values
const (
WebhookTypeIncoming WebhookType = iota
WebhookTypeChannelFollower
)
// WebhookParams is a struct for webhook params, used in the WebhookExecute command.
type WebhookParams struct {
Content string `json:"content,omitempty"`
@ -940,7 +1116,6 @@ type Activity struct {
type ActivityType int
// Valid ActivityType values
// https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
const (
ActivityTypeGame GameType = iota
ActivityTypeStreaming