forked from pothtonswer/discordmuffin
feat(member): add helper function for display name (#1426)
This commit is contained in:
parent
d2fd4c5587
commit
13748a3431
2 changed files with 45 additions and 0 deletions
|
@ -1398,6 +1398,15 @@ func (m *Member) AvatarURL(size string) string {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DisplayName returns the member's guild nickname if they have one,
|
||||||
|
// otherwise it returns their discord display name.
|
||||||
|
func (m *Member) DisplayName() string {
|
||||||
|
if m.Nick != "" {
|
||||||
|
return m.Nick
|
||||||
|
}
|
||||||
|
return m.User.GlobalName
|
||||||
|
}
|
||||||
|
|
||||||
// ClientStatus stores the online, offline, idle, or dnd status of each device of a Guild member.
|
// ClientStatus stores the online, offline, idle, or dnd status of each device of a Guild member.
|
||||||
type ClientStatus struct {
|
type ClientStatus struct {
|
||||||
Desktop Status `json:"desktop"`
|
Desktop Status `json:"desktop"`
|
||||||
|
|
36
structs_test.go
Normal file
36
structs_test.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// Discordgo - Discord bindings for Go
|
||||||
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
|
|
||||||
|
// Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package discordgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMember_DisplayName(t *testing.T) {
|
||||||
|
user := &User{
|
||||||
|
GlobalName: "Global",
|
||||||
|
}
|
||||||
|
t.Run("no server nickname set", func(t *testing.T) {
|
||||||
|
m := &Member{
|
||||||
|
Nick: "",
|
||||||
|
User: user,
|
||||||
|
}
|
||||||
|
if dn := m.DisplayName(); dn != user.GlobalName {
|
||||||
|
t.Errorf("Member.DisplayName() = %v, want %v", dn, user.GlobalName)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("server nickname set", func(t *testing.T) {
|
||||||
|
m := &Member{
|
||||||
|
Nick: "Server",
|
||||||
|
User: user,
|
||||||
|
}
|
||||||
|
if dn := m.DisplayName(); dn != m.Nick {
|
||||||
|
t.Errorf("Member.DisplayName() = %v, want %v", dn, m.Nick)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue