4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-04 20:37:44 +00:00

Update dependencies (#1951)

This commit is contained in:
Wim
2023-01-28 22:57:53 +01:00
committed by GitHub
parent eac2a8c8dc
commit 880586bac4
325 changed files with 151452 additions and 141118 deletions

View File

@ -10,10 +10,14 @@ type ComponentType uint
// MessageComponent types.
const (
ActionsRowComponent ComponentType = 1
ButtonComponent ComponentType = 2
SelectMenuComponent ComponentType = 3
TextInputComponent ComponentType = 4
ActionsRowComponent ComponentType = 1
ButtonComponent ComponentType = 2
SelectMenuComponent ComponentType = 3
TextInputComponent ComponentType = 4
UserSelectMenuComponent ComponentType = 5
RoleSelectMenuComponent ComponentType = 6
MentionableSelectMenuComponent ComponentType = 7
ChannelSelectMenuComponent ComponentType = 8
)
// MessageComponent is a base interface for all message components.
@ -41,7 +45,8 @@ func (umc *unmarshalableMessageComponent) UnmarshalJSON(src []byte) error {
umc.MessageComponent = &ActionsRow{}
case ButtonComponent:
umc.MessageComponent = &Button{}
case SelectMenuComponent:
case SelectMenuComponent, ChannelSelectMenuComponent, UserSelectMenuComponent,
RoleSelectMenuComponent, MentionableSelectMenuComponent:
umc.MessageComponent = &SelectMenu{}
case TextInputComponent:
umc.MessageComponent = &TextInput{}
@ -169,8 +174,23 @@ type SelectMenuOption struct {
Default bool `json:"default"`
}
// SelectMenuType represents select menu type.
type SelectMenuType ComponentType
// SelectMenu types.
const (
StringSelectMenu = SelectMenuType(SelectMenuComponent)
UserSelectMenu = SelectMenuType(UserSelectMenuComponent)
RoleSelectMenu = SelectMenuType(RoleSelectMenuComponent)
MentionableSelectMenu = SelectMenuType(MentionableSelectMenuComponent)
ChannelSelectMenu = SelectMenuType(ChannelSelectMenuComponent)
)
// SelectMenu represents select menu component.
type SelectMenu struct {
// Type of the select menu.
MenuType SelectMenuType `json:"type,omitempty"`
// CustomID is a developer-defined identifier for the select menu.
CustomID string `json:"custom_id,omitempty"`
// The text which will be shown in the menu if there's no default options or all options was deselected and component was closed.
Placeholder string `json:"placeholder"`
@ -179,25 +199,31 @@ type SelectMenu struct {
// This value determines the maximal amount of selected items in the menu.
// If MaxValues or MinValues are greater than one then the user can select multiple items in the component.
MaxValues int `json:"max_values,omitempty"`
Options []SelectMenuOption `json:"options"`
Options []SelectMenuOption `json:"options,omitempty"`
Disabled bool `json:"disabled"`
// NOTE: Can only be used in SelectMenu with Channel menu type.
ChannelTypes []ChannelType `json:"channel_types,omitempty"`
}
// Type is a method to get the type of a component.
func (SelectMenu) Type() ComponentType {
func (s SelectMenu) Type() ComponentType {
if s.MenuType != 0 {
return ComponentType(s.MenuType)
}
return SelectMenuComponent
}
// MarshalJSON is a method for marshaling SelectMenu to a JSON object.
func (m SelectMenu) MarshalJSON() ([]byte, error) {
func (s SelectMenu) MarshalJSON() ([]byte, error) {
type selectMenu SelectMenu
return Marshal(struct {
selectMenu
Type ComponentType `json:"type"`
}{
selectMenu: selectMenu(m),
Type: m.Type(),
selectMenu: selectMenu(s),
Type: s.Type(),
})
}

View File

@ -22,7 +22,7 @@ import (
)
// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
const VERSION = "0.26.1"
const VERSION = "0.27.0"
// New creates a new Discord session with provided token.
// If the token is for a bot, it must be prefixed with "Bot "

View File

@ -60,11 +60,12 @@ var (
return EndpointCDNBanners + uID + "/" + cID + ".gif"
}
EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" }
EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
EndpointUserGuildMember = func(uID, gID string) string { return EndpointUserGuild(uID, gID) + "/member" }
EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }
EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" }
EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
EndpointUserGuildMember = func(uID, gID string) string { return EndpointUserGuild(uID, gID) + "/member" }
EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
EndpointUserApplicationRoleConnection = func(aID string) string { return EndpointUsers + "@me/applications/" + aID + "/role-connection" }
EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }
EndpointGuild = func(gID string) string { return EndpointGuilds + gID }
EndpointGuildAutoModeration = func(gID string) string { return EndpointGuild(gID) + "/auto-moderation" }
@ -96,6 +97,7 @@ var (
EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" }
EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID }
EndpointGuildBanner = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".png" }
EndpointGuildBannerAnimated = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".gif" }
EndpointGuildStickers = func(gID string) string { return EndpointGuilds + gID + "/stickers" }
EndpointGuildSticker = func(gID, sID string) string { return EndpointGuilds + gID + "/stickers/" + sID }
EndpointStageInstance = func(cID string) string { return EndpointStageInstances + "/" + cID }
@ -197,8 +199,9 @@ var (
EndpointEmoji = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".png" }
EndpointEmojiAnimated = func(eID string) string { return EndpointCDN + "emojis/" + eID + ".gif" }
EndpointApplications = EndpointAPI + "applications"
EndpointApplication = func(aID string) string { return EndpointApplications + "/" + aID }
EndpointApplications = EndpointAPI + "applications"
EndpointApplication = func(aID string) string { return EndpointApplications + "/" + aID }
EndpointApplicationRoleConnectionMetadata = func(aID string) string { return EndpointApplication(aID) + "/role-connections/metadata" }
EndpointOAuth2 = EndpointAPI + "oauth2/"
EndpointOAuth2Applications = EndpointOAuth2 + "applications"

View File

@ -36,13 +36,13 @@ type Event struct {
// A Ready stores all data for the websocket READY event.
type Ready struct {
Version int `json:"v"`
SessionID string `json:"session_id"`
User *User `json:"user"`
Guilds []*Guild `json:"guilds"`
PrivateChannels []*Channel `json:"private_channels"`
// TODO: Application and Shard
Version int `json:"v"`
SessionID string `json:"session_id"`
User *User `json:"user"`
Shard *[2]int `json:"shard"`
Application *Application `json:"application"`
Guilds []*Guild `json:"guilds"`
PrivateChannels []*Channel `json:"private_channels"`
}
// ChannelCreate is the data for a ChannelCreate event.
@ -150,6 +150,7 @@ type GuildMemberAdd struct {
// GuildMemberUpdate is the data for a GuildMemberUpdate event.
type GuildMemberUpdate struct {
*Member
BeforeUpdate *Member `json:"-"`
}
// GuildMemberRemove is the data for a GuildMemberRemove event.

View File

@ -42,6 +42,7 @@ type ApplicationCommand struct {
DefaultPermission *bool `json:"default_permission,omitempty"`
DefaultMemberPermissions *int64 `json:"default_member_permissions,string,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
// NOTE: Chat commands only. Otherwise it mustn't be set.
@ -343,13 +344,22 @@ func (ApplicationCommandInteractionData) Type() InteractionType {
// MessageComponentInteractionData contains the data of message component interaction.
type MessageComponentInteractionData struct {
CustomID string `json:"custom_id"`
ComponentType ComponentType `json:"component_type"`
CustomID string `json:"custom_id"`
ComponentType ComponentType `json:"component_type"`
Resolved MessageComponentInteractionDataResolved `json:"resolved"`
// NOTE: Only filled when ComponentType is SelectMenuComponent (3). Otherwise is nil.
Values []string `json:"values"`
}
// MessageComponentInteractionDataResolved contains the resolved data of selected option.
type MessageComponentInteractionDataResolved struct {
Users map[string]*User `json:"users"`
Members map[string]*Member `json:"members"`
Roles map[string]*Role `json:"roles"`
Channels map[string]*Channel `json:"channels"`
}
// Type returns the type of interaction data.
func (MessageComponentInteractionData) Type() InteractionType {
return InteractionMessageComponent
@ -472,7 +482,7 @@ func (o ApplicationCommandInteractionDataOption) RoleValue(s *Session, gID strin
return &Role{ID: roleID}
}
r, err := s.State.Role(roleID, gID)
r, err := s.State.Role(gID, roleID)
if err != nil {
roles, err := s.GuildRoles(gID)
if err == nil {

View File

@ -249,6 +249,10 @@ type MessageEdit struct {
Embeds []*MessageEmbed `json:"embeds"`
AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
Flags MessageFlags `json:"flags,omitempty"`
// Files to append to the message
Files []*File `json:"-"`
// Overwrite existing attachments
Attachments *[]*MessageAttachment `json:"attachments,omitempty"`
ID string
Channel string
@ -385,8 +389,8 @@ type MessageEmbedAuthor struct {
// MessageEmbedField is a part of a MessageEmbed struct.
type MessageEmbedField struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Name string `json:"name"`
Value string `json:"value"`
Inline bool `json:"inline,omitempty"`
}

File diff suppressed because it is too large Load Diff

View File

@ -207,6 +207,15 @@ func (s *State) presenceAdd(guildID string, presence *Presence) error {
if presence.Status != "" {
guild.Presences[i].Status = presence.Status
}
if presence.ClientStatus.Desktop != "" {
guild.Presences[i].ClientStatus.Desktop = presence.ClientStatus.Desktop
}
if presence.ClientStatus.Mobile != "" {
guild.Presences[i].ClientStatus.Mobile = presence.ClientStatus.Mobile
}
if presence.ClientStatus.Web != "" {
guild.Presences[i].ClientStatus.Web = presence.ClientStatus.Web
}
//Update the optionally sent user information
//ID Is a mandatory field so you should not need to check if it is empty
@ -909,9 +918,11 @@ func (s *State) onReady(se *Session, r *Ready) (err error) {
// if state is disabled, store the bare essentials.
if !se.StateEnabled {
ready := Ready{
Version: r.Version,
SessionID: r.SessionID,
User: r.User,
Version: r.Version,
SessionID: r.SessionID,
User: r.User,
Shard: r.Shard,
Application: r.Application,
}
s.Ready = ready
@ -981,6 +992,13 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
}
case *GuildMemberUpdate:
if s.TrackMembers {
var old *Member
old, err = s.Member(t.GuildID, t.User.ID)
if err == nil {
oldCopy := *old
t.BeforeUpdate = &oldCopy
}
err = s.MemberAdd(t.Member)
}
case *GuildMemberRemove:
@ -1023,7 +1041,14 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
}
case *GuildEmojisUpdate:
if s.TrackEmojis {
err = s.EmojisAdd(t.GuildID, t.Emojis)
var guild *Guild
guild, err = s.Guild(t.GuildID)
if err != nil {
return err
}
s.Lock()
defer s.Unlock()
guild.Emojis = t.Emojis
}
case *ChannelCreate:
if s.TrackChannels {

View File

@ -17,7 +17,6 @@ import (
"math"
"net/http"
"regexp"
"strings"
"sync"
"time"
@ -156,6 +155,38 @@ type Application struct {
Flags int `json:"flags,omitempty"`
}
// ApplicationRoleConnectionMetadataType represents the type of application role connection metadata.
type ApplicationRoleConnectionMetadataType int
// Application role connection metadata types.
const (
ApplicationRoleConnectionMetadataIntegerLessThanOrEqual ApplicationRoleConnectionMetadataType = 1
ApplicationRoleConnectionMetadataIntegerGreaterThanOrEqual ApplicationRoleConnectionMetadataType = 2
ApplicationRoleConnectionMetadataIntegerEqual ApplicationRoleConnectionMetadataType = 3
ApplicationRoleConnectionMetadataIntegerNotEqual ApplicationRoleConnectionMetadataType = 4
ApplicationRoleConnectionMetadataDatetimeLessThanOrEqual ApplicationRoleConnectionMetadataType = 5
ApplicationRoleConnectionMetadataDatetimeGreaterThanOrEqual ApplicationRoleConnectionMetadataType = 6
ApplicationRoleConnectionMetadataBooleanEqual ApplicationRoleConnectionMetadataType = 7
ApplicationRoleConnectionMetadataBooleanNotEqual ApplicationRoleConnectionMetadataType = 8
)
// ApplicationRoleConnectionMetadata stores application role connection metadata.
type ApplicationRoleConnectionMetadata struct {
Type ApplicationRoleConnectionMetadataType `json:"type"`
Key string `json:"key"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations"`
Description string `json:"description"`
DescriptionLocalizations map[Locale]string `json:"description_localizations"`
}
// ApplicationRoleConnection represents the role connection that an application has attached to a user.
type ApplicationRoleConnection struct {
PlatformName string `json:"platform_name"`
PlatformUsername string `json:"platform_username"`
Metadata map[string]string `json:"metadata"`
}
// UserConnection is a Connection returned from the UserConnections endpoint
type UserConnection struct {
ID string `json:"id"`
@ -254,6 +285,42 @@ const (
ChannelTypeGuildPublicThread ChannelType = 11
ChannelTypeGuildPrivateThread ChannelType = 12
ChannelTypeGuildStageVoice ChannelType = 13
ChannelTypeGuildForum ChannelType = 15
)
// ChannelFlags represent flags of a channel/thread.
type ChannelFlags int
// Block containing known ChannelFlags values.
const (
// ChannelFlagPinned indicates whether the thread is pinned in the forum channel.
// NOTE: forum threads only.
ChannelFlagPinned ChannelFlags = 1 << 1
// ChannelFlagRequireTag indicates whether a tag is required to be specified when creating a thread.
// NOTE: forum channels only.
ChannelFlagRequireTag ChannelFlags = 1 << 4
)
// ForumSortOrderType represents sort order of a forum channel.
type ForumSortOrderType int
const (
// ForumSortOrderLatestActivity sorts posts by activity.
ForumSortOrderLatestActivity ForumSortOrderType = 0
// ForumSortOrderCreationDate sorts posts by creation time (from most recent to oldest).
ForumSortOrderCreationDate ForumSortOrderType = 1
)
// ForumLayout represents layout of a forum channel.
type ForumLayout int
const (
// ForumLayoutNotSet represents no default layout.
ForumLayoutNotSet ForumLayout = 0
// ForumLayoutListView displays forum posts as a list.
ForumLayoutListView ForumLayout = 1
// ForumLayoutGalleryView displays forum posts as a collection of tiles.
ForumLayoutGalleryView ForumLayout = 2
)
// A Channel holds all data related to an individual Discord channel.
@ -332,6 +399,30 @@ type Channel struct {
// All thread members. State channels only.
Members []*ThreadMember `json:"-"`
// Channel flags.
Flags ChannelFlags `json:"flags"`
// The set of tags that can be used in a forum channel.
AvailableTags []ForumTag `json:"available_tags"`
// The IDs of the set of tags that have been applied to a thread in a forum channel.
AppliedTags []string `json:"applied_tags"`
// Emoji to use as the default reaction to a forum post.
DefaultReactionEmoji ForumDefaultReaction `json:"default_reaction_emoji"`
// The initial RateLimitPerUser to set on newly created threads in a channel.
// This field is copied to the thread at creation time and does not live update.
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user"`
// The default sort order type used to order posts in forum channels.
// Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin.
DefaultSortOrder *ForumSortOrderType `json:"default_sort_order"`
// The default forum layout view used to display posts in forum channels.
// Defaults to ForumLayoutNotSet, which indicates a layout view has not been set by a channel admin.
DefaultForumLayout ForumLayout `json:"default_forum_layout"`
}
// Mention returns a string which mentions the channel
@ -346,15 +437,17 @@ func (c *Channel) IsThread() bool {
// A ChannelEdit holds Channel Field data for a channel edit.
type ChannelEdit struct {
Name string `json:"name,omitempty"`
Topic string `json:"topic,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
Position int `json:"position"`
Bitrate int `json:"bitrate,omitempty"`
UserLimit int `json:"user_limit,omitempty"`
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID string `json:"parent_id,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
Name string `json:"name,omitempty"`
Topic string `json:"topic,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
Position int `json:"position"`
Bitrate int `json:"bitrate,omitempty"`
UserLimit int `json:"user_limit,omitempty"`
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID string `json:"parent_id,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
Flags *ChannelFlags `json:"flags,omitempty"`
DefaultThreadRateLimitPerUser *int `json:"default_thread_rate_limit_per_user,omitempty"`
// NOTE: threads only
@ -362,6 +455,16 @@ type ChannelEdit struct {
AutoArchiveDuration int `json:"auto_archive_duration,omitempty"`
Locked *bool `json:"locked,omitempty"`
Invitable *bool `json:"invitable,omitempty"`
// NOTE: forum channels only
AvailableTags *[]ForumTag `json:"available_tags,omitempty"`
DefaultReactionEmoji *ForumDefaultReaction `json:"default_reaction_emoji,omitempty"`
DefaultSortOrder *ForumSortOrderType `json:"default_sort_order,omitempty"` // TODO: null
DefaultForumLayout *ForumLayout `json:"default_forum_layout,omitempty"`
// NOTE: forum threads only
AppliedTags *[]string `json:"applied_tags,omitempty"`
}
// A ChannelFollow holds data returned after following a news channel
@ -395,6 +498,9 @@ type ThreadStart struct {
Type ChannelType `json:"type,omitempty"`
Invitable bool `json:"invitable"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
// NOTE: forum threads only
AppliedTags []string `json:"applied_tags,omitempty"`
}
// ThreadMetadata contains a number of thread-specific channel fields that are not needed by other channel types.
@ -438,6 +544,24 @@ type AddedThreadMember struct {
Presence *Presence `json:"presence"`
}
// ForumDefaultReaction specifies emoji to use as the default reaction to a forum post.
// NOTE: Exactly one of EmojiID and EmojiName must be set.
type ForumDefaultReaction struct {
// The id of a guild's custom emoji.
EmojiID string `json:"emoji_id,omitempty"`
// The unicode character of the emoji.
EmojiName string `json:"emoji_name,omitempty"`
}
// ForumTag represents a tag that is able to be applied to a thread in a forum channel.
type ForumTag struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Moderated bool `json:"moderated"`
EmojiID string `json:"emoji_id,omitempty"`
EmojiName string `json:"emoji_name,omitempty"`
}
// Emoji struct holds data related to Emoji's
type Emoji struct {
ID string `json:"id"`
@ -452,7 +576,7 @@ type Emoji struct {
// EmojiRegex is the regex used to find and identify emojis in messages
var (
EmojiRegex = regexp.MustCompile(`<(a|):[A-z0-9_~]+:[0-9]{18}>`)
EmojiRegex = regexp.MustCompile(`<(a|):[A-z0-9_~]+:[0-9]{18,20}>`)
)
// MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
@ -792,16 +916,11 @@ type GuildPreview struct {
}
// IconURL returns a URL to the guild's icon.
func (g *GuildPreview) IconURL() string {
if g.Icon == "" {
return ""
}
if strings.HasPrefix(g.Icon, "a_") {
return EndpointGuildIconAnimated(g.ID, g.Icon)
}
return EndpointGuildIcon(g.ID, g.Icon)
//
// size: The size of the desired icon image as a power of two
// Image size can be any power of two between 16 and 4096.
func (g *GuildPreview) IconURL(size string) string {
return iconURL(g.Icon, EndpointGuildIcon(g.ID, g.Icon), EndpointGuildIconAnimated(g.ID, g.Icon), size)
}
// GuildScheduledEvent is a representation of a scheduled event in a guild. Only for retrieval of the data.
@ -917,13 +1036,13 @@ type GuildScheduledEventStatus int
const (
// GuildScheduledEventStatusScheduled represents the current event is in scheduled state
GuildScheduledEventStatusScheduled = 1
GuildScheduledEventStatusScheduled GuildScheduledEventStatus = 1
// GuildScheduledEventStatusActive represents the current event is in active state
GuildScheduledEventStatusActive = 2
GuildScheduledEventStatusActive GuildScheduledEventStatus = 2
// GuildScheduledEventStatusCompleted represents the current event is in completed state
GuildScheduledEventStatusCompleted = 3
GuildScheduledEventStatusCompleted GuildScheduledEventStatus = 3
// GuildScheduledEventStatusCanceled represents the current event is in canceled state
GuildScheduledEventStatusCanceled = 4
GuildScheduledEventStatusCanceled GuildScheduledEventStatus = 4
)
// GuildScheduledEventEntityType is the type of entity associated with a guild scheduled event.
@ -932,11 +1051,11 @@ type GuildScheduledEventEntityType int
const (
// GuildScheduledEventEntityTypeStageInstance represents a stage channel
GuildScheduledEventEntityTypeStageInstance = 1
GuildScheduledEventEntityTypeStageInstance GuildScheduledEventEntityType = 1
// GuildScheduledEventEntityTypeVoice represents a voice channel
GuildScheduledEventEntityTypeVoice = 2
GuildScheduledEventEntityTypeVoice GuildScheduledEventEntityType = 2
// GuildScheduledEventEntityTypeExternal represents an external event
GuildScheduledEventEntityTypeExternal = 3
GuildScheduledEventEntityTypeExternal GuildScheduledEventEntityType = 3
)
// GuildScheduledEventUser is a user subscribed to a scheduled event.
@ -1007,29 +1126,26 @@ type SystemChannelFlag int
// Block containing known SystemChannelFlag values
const (
SystemChannelFlagsSuppressJoin SystemChannelFlag = 1 << 0
SystemChannelFlagsSuppressPremium SystemChannelFlag = 1 << 1
SystemChannelFlagsSuppressJoinNotifications SystemChannelFlag = 1 << 0
SystemChannelFlagsSuppressPremium SystemChannelFlag = 1 << 1
SystemChannelFlagsSuppressGuildReminderNotifications SystemChannelFlag = 1 << 2
SystemChannelFlagsSuppressJoinNotificationReplies SystemChannelFlag = 1 << 3
)
// IconURL returns a URL to the guild's icon.
func (g *Guild) IconURL() string {
if g.Icon == "" {
return ""
}
if strings.HasPrefix(g.Icon, "a_") {
return EndpointGuildIconAnimated(g.ID, g.Icon)
}
return EndpointGuildIcon(g.ID, g.Icon)
//
// size: The size of the desired icon image as a power of two
// Image size can be any power of two between 16 and 4096.
func (g *Guild) IconURL(size string) string {
return iconURL(g.Icon, EndpointGuildIcon(g.ID, g.Icon), EndpointGuildIconAnimated(g.ID, g.Icon), size)
}
// BannerURL returns a URL to the guild's banner.
func (g *Guild) BannerURL() string {
if g.Banner == "" {
return ""
}
return EndpointGuildBanner(g.ID, g.Banner)
//
// size: The size of the desired banner image as a power of two
// Image size can be any power of two between 16 and 4096.
func (g *Guild) BannerURL(size string) string {
return bannerURL(g.Banner, EndpointGuildBanner(g.ID, g.Banner), EndpointGuildBannerAnimated(g.ID, g.Banner), size)
}
// A UserGuild holds a brief version of a Guild
@ -1076,12 +1192,22 @@ type GuildParams struct {
Region string `json:"region,omitempty"`
VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
ExplicitContentFilter int `json:"explicit_content_filter,omitempty"`
AfkChannelID string `json:"afk_channel_id,omitempty"`
AfkTimeout int `json:"afk_timeout,omitempty"`
Icon string `json:"icon,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
Splash string `json:"splash,omitempty"`
DiscoverySplash string `json:"discovery_splash,omitempty"`
Banner string `json:"banner,omitempty"`
SystemChannelID string `json:"system_channel_id,omitempty"`
SystemChannelFlags SystemChannelFlag `json:"system_channel_flags,omitempty"`
RulesChannelID string `json:"rules_channel_id,omitempty"`
PublicUpdatesChannelID string `json:"public_updates_channel_id,omitempty"`
PreferredLocale Locale `json:"preferred_locale,omitempty"`
Features []GuildFeature `json:"features,omitempty"`
Description string `json:"description,omitempty"`
PremiumProgressBarEnabled *bool `json:"premium_progress_bar_enabled,omitempty"`
}
// A Role stores information about Discord guild member roles.
@ -1167,10 +1293,11 @@ type VoiceState struct {
// A Presence stores the online, offline, or idle and game status of Guild members.
type Presence struct {
User *User `json:"user"`
Status Status `json:"status"`
Activities []*Activity `json:"activities"`
Since *int `json:"since"`
User *User `json:"user"`
Status Status `json:"status"`
Activities []*Activity `json:"activities"`
Since *int `json:"since"`
ClientStatus ClientStatus `json:"client_status"`
}
// A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
@ -1249,9 +1376,10 @@ func (m *Member) Mention() string {
}
// AvatarURL returns the URL of the member's avatar
// size: The size of the user's avatar as a power of two
// if size is an empty string, no size parameter will
// be added to the URL.
//
// size: The size of the user's avatar as a power of two
// if size is an empty string, no size parameter will
// be added to the URL.
func (m *Member) AvatarURL(size string) string {
if m.Avatar == "" {
return m.User.AvatarURL(size)
@ -1262,6 +1390,13 @@ func (m *Member) AvatarURL(size string) string {
}
// ClientStatus stores the online, offline, idle, or dnd status of each device of a Guild member.
type ClientStatus struct {
Desktop Status `json:"desktop"`
Mobile Status `json:"mobile"`
Web Status `json:"web"`
}
// Status type definition
type Status string
@ -1371,9 +1506,21 @@ type AutoModerationTriggerMetadata struct {
// Substrings which will be searched for in content.
// NOTE: should be only used with keyword trigger type.
KeywordFilter []string `json:"keyword_filter,omitempty"`
// Regular expression patterns which will be matched against content (maximum of 10).
// NOTE: should be only used with keyword trigger type.
RegexPatterns []string `json:"regex_patterns,omitempty"`
// Internally pre-defined wordsets which will be searched for in content.
// NOTE: should be only used with keyword preset trigger type.
Presets []AutoModerationKeywordPreset `json:"presets,omitempty"`
// Substrings which should not trigger the rule.
// NOTE: should be only used with keyword or keyword preset trigger type.
AllowList *[]string `json:"allow_list,omitempty"`
// Total number of unique role and user mentions allowed per message.
// NOTE: should be only used with mention spam trigger type.
MentionTotalLimit int `json:"mention_total_limit,omitempty"`
}
// AutoModerationActionType represents an action which will execute whenever a rule is triggered.
@ -2074,6 +2221,7 @@ const (
ErrCodeUnknownGuildWelcomeScreen = 10069
ErrCodeUnknownGuildScheduledEvent = 10070
ErrCodeUnknownGuildScheduledEventUser = 10071
ErrUnknownTag = 10087
ErrCodeBotsCannotUseEndpoint = 20001
ErrCodeOnlyBotsCanUseEndpoint = 20002
@ -2087,28 +2235,30 @@ const (
ErrCodeStageTopicContainsNotAllowedWordsForPublicStages = 20031
ErrCodeGuildPremiumSubscriptionLevelTooLow = 20035
ErrCodeMaximumGuildsReached = 30001
ErrCodeMaximumPinsReached = 30003
ErrCodeMaximumNumberOfRecipientsReached = 30004
ErrCodeMaximumGuildRolesReached = 30005
ErrCodeMaximumNumberOfWebhooksReached = 30007
ErrCodeMaximumNumberOfEmojisReached = 30008
ErrCodeTooManyReactions = 30010
ErrCodeMaximumNumberOfGuildChannelsReached = 30013
ErrCodeMaximumNumberOfAttachmentsInAMessageReached = 30015
ErrCodeMaximumNumberOfInvitesReached = 30016
ErrCodeMaximumNumberOfAnimatedEmojisReached = 30018
ErrCodeMaximumNumberOfServerMembersReached = 30019
ErrCodeMaximumNumberOfGuildDiscoverySubcategoriesReached = 30030
ErrCodeGuildAlreadyHasATemplate = 30031
ErrCodeMaximumNumberOfThreadParticipantsReached = 30033
ErrCodeMaximumNumberOfBansForNonGuildMembersHaveBeenExceeded = 30035
ErrCodeMaximumNumberOfBansFetchesHasBeenReached = 30037
ErrCodeMaximumNumberOfUncompletedGuildScheduledEventsReached = 30038
ErrCodeMaximumNumberOfStickersReached = 30039
ErrCodeMaximumNumberOfPruneRequestsHasBeenReached = 30040
ErrCodeMaximumNumberOfGuildWidgetSettingsUpdatesHasBeenReached = 30042
ErrCodeMaximumNumberOfEditsToMessagesOlderThanOneHourReached = 30046
ErrCodeMaximumGuildsReached = 30001
ErrCodeMaximumPinsReached = 30003
ErrCodeMaximumNumberOfRecipientsReached = 30004
ErrCodeMaximumGuildRolesReached = 30005
ErrCodeMaximumNumberOfWebhooksReached = 30007
ErrCodeMaximumNumberOfEmojisReached = 30008
ErrCodeTooManyReactions = 30010
ErrCodeMaximumNumberOfGuildChannelsReached = 30013
ErrCodeMaximumNumberOfAttachmentsInAMessageReached = 30015
ErrCodeMaximumNumberOfInvitesReached = 30016
ErrCodeMaximumNumberOfAnimatedEmojisReached = 30018
ErrCodeMaximumNumberOfServerMembersReached = 30019
ErrCodeMaximumNumberOfGuildDiscoverySubcategoriesReached = 30030
ErrCodeGuildAlreadyHasATemplate = 30031
ErrCodeMaximumNumberOfThreadParticipantsReached = 30033
ErrCodeMaximumNumberOfBansForNonGuildMembersHaveBeenExceeded = 30035
ErrCodeMaximumNumberOfBansFetchesHasBeenReached = 30037
ErrCodeMaximumNumberOfUncompletedGuildScheduledEventsReached = 30038
ErrCodeMaximumNumberOfStickersReached = 30039
ErrCodeMaximumNumberOfPruneRequestsHasBeenReached = 30040
ErrCodeMaximumNumberOfGuildWidgetSettingsUpdatesHasBeenReached = 30042
ErrCodeMaximumNumberOfEditsToMessagesOlderThanOneHourReached = 30046
ErrCodeMaximumNumberOfPinnedThreadsInForumChannelHasBeenReached = 30047
ErrCodeMaximumNumberOfTagsInForumChannelHasBeenReached = 30048
ErrCodeUnauthorized = 40001
ErrCodeActionRequiredVerifiedAccount = 40002
@ -2121,6 +2271,7 @@ const (
ErrCodeMessageAlreadyCrossposted = 40033
ErrCodeAnApplicationWithThatNameAlreadyExists = 40041
ErrCodeInteractionHasAlreadyBeenAcknowledged = 40060
ErrCodeTagNamesMustBeUnique = 40061
ErrCodeMissingAccess = 50001
ErrCodeInvalidAccountType = 50002

View File

@ -51,7 +51,7 @@ func MultipartBodyWithJSON(data interface{}, files []*File) (requestContentType
for i, file := range files {
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file%d"; filename="%s"`, i, quoteEscaper.Replace(file.Name)))
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="files[%d]"; filename="%s"`, i, quoteEscaper.Replace(file.Name)))
contentType := file.ContentType
if contentType == "" {
contentType = "application/octet-stream"
@ -107,3 +107,19 @@ func bannerURL(bannerHash, staticBannerURL, animatedBannerURL, size string) stri
}
return URL
}
func iconURL(iconHash, staticIconURL, animatedIconURL, size string) string {
var URL string
if iconHash == "" {
return ""
} else if strings.HasPrefix(iconHash, "a_") {
URL = animatedIconURL
} else {
URL = staticIconURL
}
if size != "" {
return URL + "?size=" + size
}
return URL
}

View File

@ -360,6 +360,25 @@ func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{}
v.wsConn = nil
v.Unlock()
// Wait for VOICE_SERVER_UPDATE.
// When the bot is moved by the user to another voice channel,
// VOICE_SERVER_UPDATE is received after the code 4014.
for i := 0; i < 5; i++ { // TODO: temp, wait for VoiceServerUpdate.
<-time.After(1 * time.Second)
v.RLock()
reconnected := v.wsConn != nil
v.RUnlock()
if !reconnected {
continue
}
v.log(LogInformational, "successfully reconnected after 4014 manual disconnection")
return
}
// When VOICE_SERVER_UPDATE is not received, disconnect as usual.
v.log(LogInformational, "disconnect due to 4014 manual disconnection")
v.session.Lock()
delete(v.session.VoiceConnections, v.GuildID)
v.session.Unlock()
@ -835,7 +854,7 @@ func (v *VoiceConnection) opusReceiver(udpConn *net.UDPConn, close <-chan struct
if opus, ok := secretbox.Open(nil, recvbuf[12:rlen], &nonce, &v.op4.SecretKey); ok {
p.Opus = opus
} else {
return
continue
}
// extension bit set, and not a RTCP packet

View File

@ -320,7 +320,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
}
}
// UpdateStatusData ia provided to UpdateStatusComplex()
// UpdateStatusData is provided to UpdateStatusComplex()
type UpdateStatusData struct {
IdleSince *int `json:"since"`
Activities []*Activity `json:"activities"`
@ -361,6 +361,14 @@ func (s *Session) UpdateGameStatus(idle int, name string) (err error) {
return s.UpdateStatusComplex(*newUpdateStatusData(idle, ActivityTypeGame, name, ""))
}
// UpdateWatchStatus is used to update the user's watch status.
// If idle>0 then set status to idle.
// If name!="" then set movie/stream.
// if otherwise, set status to active, and no activity.
func (s *Session) UpdateWatchStatus(idle int, name string) (err error) {
return s.UpdateStatusComplex(*newUpdateStatusData(idle, ActivityTypeWatching, name, ""))
}
// UpdateStreamingStatus is used to update the user's streaming status.
// If idle>0 then set status to idle.
// If name!="" then set game.