1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-03-24 10:59:18 +00:00

Discord: Add missing guild widget methods (#168)

* Discord: cleanup comments

* Discord: differentiate between GuildWidget and GuildWidgetSettings

* Discord: rename GuildImageURL and GuildImage to GuildWidgetURL and GuildWidget

* Discord: add missing guild widget endpoints
This commit is contained in:
Maximilian von Lindern 2020-11-21 18:40:54 +01:00 committed by GitHub
parent 59d2ac8959
commit 1d58ea57fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 20 deletions

View file

@ -431,11 +431,13 @@ func (c *Client) SyncIntegration(guildID discord.GuildID, integrationID discord.
)
}
// GuildWidget returns the guild widget object.
// GuildWidgetSettings returns the guild widget object.
//
// Requires the MANAGE_GUILD permission.
func (c *Client) GuildWidget(guildID discord.GuildID) (*discord.GuildWidget, error) {
var ge *discord.GuildWidget
func (c *Client) GuildWidgetSettings(
guildID discord.GuildID) (*discord.GuildWidgetSettings, error) {
var ge *discord.GuildWidgetSettings
return ge, c.RequestJSON(&ge, "GET", EndpointGuilds+guildID.String()+"/widget")
}
@ -454,9 +456,9 @@ type ModifyGuildWidgetData struct {
//
// Requires the MANAGE_GUILD permission.
func (c *Client) ModifyGuildWidget(
guildID discord.GuildID, data ModifyGuildWidgetData) (*discord.GuildWidget, error) {
guildID discord.GuildID, data ModifyGuildWidgetData) (*discord.GuildWidgetSettings, error) {
var w *discord.GuildWidget
var w *discord.GuildWidgetSettings
return w, c.RequestJSON(
&w, "PATCH",
EndpointGuilds+guildID.String()+"/widget",
@ -464,6 +466,14 @@ func (c *Client) ModifyGuildWidget(
)
}
// GuildWidget returns the widget for the guild.
func (c *Client) GuildWidget(guildID discord.GuildID) (*discord.GuildWidget, error) {
var w *discord.GuildWidget
return w, c.RequestJSON(
&w, "GET",
EndpointGuilds+guildID.String()+"/widget.json")
}
// GuildVanityURL returns *Invite for guilds that have that feature enabled,
// but only Code and Uses are filled. Code will be "" if a vanity url for the
// guild is not set.
@ -475,48 +485,48 @@ func (c *Client) GuildVanityURL(guildID discord.GuildID) (*discord.Invite, error
}
// https://discord.com/developers/docs/resources/guild#get-guild-widget-image-widget-style-options
type GuildImageStyle string
type GuildWidgetImageStyle string
const (
// GuildShield is a shield style widget with Discord icon and guild members
// online count.
//
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=shield
GuildShield GuildImageStyle = "shield"
GuildShield GuildWidgetImageStyle = "shield"
// GuildBanner1 is a large image with guild icon, name and online count.
// "POWERED BY DISCORD" as the footer of the widget.
//
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner1
GuildBanner1 GuildImageStyle = "banner1"
GuildBanner1 GuildWidgetImageStyle = "banner1"
// GuildBanner2 is a smaller widget style with guild icon, name and online
// count. Split on the right with Discord logo.
//
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner2
GuildBanner2 GuildImageStyle = "banner2"
GuildBanner2 GuildWidgetImageStyle = "banner2"
// GuildBanner3 is a large image with guild icon, name and online count. In
// the footer, Discord logo on the left and "Chat Now" on the right.
//
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner3
GuildBanner3 GuildImageStyle = "banner3"
GuildBanner3 GuildWidgetImageStyle = "banner3"
// GuildBanner4 is a large Discord logo at the top of the widget.
// Guild icon, name and online count in the middle portion of the widget
// and a "JOIN MY SERVER" button at the bottom.
//
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner4
GuildBanner4 GuildImageStyle = "banner4"
GuildBanner4 GuildWidgetImageStyle = "banner4"
)
// GuildImageURL returns a link to the PNG image widget for the guild.
// GuildWidgetImageURL returns a link to the PNG image widget for the guild.
//
// Requires no permissions or authentication.
func (c *Client) GuildImageURL(guildID discord.GuildID, img GuildImageStyle) string {
func (c *Client) GuildWidgetImageURL(guildID discord.GuildID, img GuildWidgetImageStyle) string {
return EndpointGuilds + guildID.String() + "/widget.png?style=" + string(img)
}
// GuildImage returns a PNG image widget for the guild. Requires no permissions
// GuildWidgetImage returns a PNG image widget for the guild. Requires no permissions
// or authentication.
func (c *Client) GuildImage(guildID discord.GuildID, img GuildImageStyle) (io.ReadCloser, error) {
r, err := c.Request("GET", c.GuildImageURL(guildID, img))
func (c *Client) GuildWidgetImage(guildID discord.GuildID, img GuildWidgetImageStyle) (io.ReadCloser, error) {
r, err := c.Request("GET", c.GuildWidgetImageURL(guildID, img))
if err != nil {
return nil, err
}

View file

@ -10,7 +10,7 @@ type Channel struct {
// ID is the id of this channel.
ID ChannelID `json:"id,string"`
// Type is the type of channel.
Type ChannelType `json:"type"`
Type ChannelType `json:"type,omitempty"`
// GuildID is the id of the guild.
GuildID GuildID `json:"guild_id,string,omitempty"`
@ -24,7 +24,7 @@ type Channel struct {
// Topic is the channel topic (0-1024 characters).
Topic string `json:"topic,omitempty"`
// NSFW specifies whether the channel is nsfw.
NSFW bool `json:"nsfw"`
NSFW bool `json:"nsfw,omitempty"`
// LastMessageID is the id of the last message sent in this channel (may
// not point to an existing or valid message).

View file

@ -105,7 +105,8 @@ type Guild struct {
// MaxVideoChannelUsers is the maximum amount of users in a video channel.
MaxVideoChannelUsers uint64 `json:"max_video_channel_users,omitempty"`
// ApproximateMembers is the approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
// ApproximateMembers is the approximate number of members in this guild,
// returned by the GuildWithCount method.
ApproximateMembers uint64 `json:"approximate_member_count,omitempty"`
// ApproximatePresences is the approximate number of non-offline members in
// this guild, returned by the GuildWithCount method.
@ -408,8 +409,22 @@ type Integration struct {
SyncedAt Timestamp `json:"synced_at"`
}
// https://discord.com/developers/docs/resources/guild#guild-widget-object
// https://discord.com/developers/docs/resources/guild#get-guild-widget-example-get-guild-widget
type GuildWidget struct {
// ID is the ID of the guild.
ID GuildID `json:"id"`
// Name is the name of the guild.
Name string `json:"name"`
// InviteURl is the url of an instant invite to the guild.
InviteURL string `json:"instant_invite"`
Channels []Channel `json:"channels"`
Members []User `json:"members"`
// Presence count is the amount of presences in the guild
PresenceCount int `json:"presence_count"`
}
// https://discord.com/developers/docs/resources/guild#guild-widget-object
type GuildWidgetSettings struct {
// Enabled specifies whether the widget is enabled.
Enabled bool `json:"enabled"`
// ChannelID is the widget channel id.