Discord: add Mention method to mentionable Snowflakes

This commit is contained in:
mavolin 2020-09-24 20:43:20 +02:00 committed by diamondburned
parent 64ab8c4f30
commit 647efb8030
4 changed files with 7 additions and 4 deletions

View File

@ -57,7 +57,7 @@ type Channel struct {
// Mention returns a mention of the channel. // Mention returns a mention of the channel.
func (ch Channel) Mention() string { func (ch Channel) Mention() string {
return "<#" + ch.ID.String() + ">" return ch.ID.Mention()
} }
// IconURL returns the URL to the channel icon in the PNG format. // IconURL returns the URL to the channel icon in the PNG format.

View File

@ -307,7 +307,7 @@ type Role struct {
// Mention returns the mention of the Role. // Mention returns the mention of the Role.
func (r Role) Mention() string { func (r Role) Mention() string {
return "<@&" + r.ID.String() + ">" return r.ID.Mention()
} }
// https://discord.com/developers/docs/topics/gateway#presence-update // https://discord.com/developers/docs/topics/gateway#presence-update
@ -375,7 +375,7 @@ type Member struct {
// Mention returns the mention of the role. // Mention returns the mention of the role.
func (m Member) Mention() string { func (m Member) Mention() string {
return "<@!" + m.User.ID.String() + ">" return m.User.Mention()
} }
// https://discord.com/developers/docs/resources/guild#ban-object // https://discord.com/developers/docs/resources/guild#ban-object

View File

@ -149,6 +149,7 @@ func (s ChannelID) Time() time.Time { return Snowflake(s).Time() }
func (s ChannelID) Worker() uint8 { return Snowflake(s).Worker() } func (s ChannelID) Worker() uint8 { return Snowflake(s).Worker() }
func (s ChannelID) PID() uint8 { return Snowflake(s).PID() } func (s ChannelID) PID() uint8 { return Snowflake(s).PID() }
func (s ChannelID) Increment() uint16 { return Snowflake(s).Increment() } func (s ChannelID) Increment() uint16 { return Snowflake(s).Increment() }
func (s ChannelID) Mention() string { return "<#" + s.String() + ">" }
type EmojiID Snowflake type EmojiID Snowflake
@ -219,6 +220,7 @@ func (s RoleID) Time() time.Time { return Snowflake(s).Time() }
func (s RoleID) Worker() uint8 { return Snowflake(s).Worker() } func (s RoleID) Worker() uint8 { return Snowflake(s).Worker() }
func (s RoleID) PID() uint8 { return Snowflake(s).PID() } func (s RoleID) PID() uint8 { return Snowflake(s).PID() }
func (s RoleID) Increment() uint16 { return Snowflake(s).Increment() } func (s RoleID) Increment() uint16 { return Snowflake(s).Increment() }
func (s RoleID) Mention() string { return "<@&" + s.String() + ">" }
type UserID Snowflake type UserID Snowflake
@ -233,6 +235,7 @@ func (s UserID) Time() time.Time { return Snowflake(s).Time() }
func (s UserID) Worker() uint8 { return Snowflake(s).Worker() } func (s UserID) Worker() uint8 { return Snowflake(s).Worker() }
func (s UserID) PID() uint8 { return Snowflake(s).PID() } func (s UserID) PID() uint8 { return Snowflake(s).PID() }
func (s UserID) Increment() uint16 { return Snowflake(s).Increment() } func (s UserID) Increment() uint16 { return Snowflake(s).Increment() }
func (s UserID) Mention() string { return "<@" + s.String() + ">" }
type WebhookID Snowflake type WebhookID Snowflake

View File

@ -27,7 +27,7 @@ type User struct {
} }
func (u User) Mention() string { func (u User) Mention() string {
return "<@" + u.ID.String() + ">" return u.ID.Mention()
} }
// AvatarURL returns the URL of the Avatar Image. It automatically detects a // AvatarURL returns the URL of the Avatar Image. It automatically detects a