add String() method to User (#350)

* add String() method to User

* put User def in it's own file

* remove usage of t.Run for support w/ older Go versions
This commit is contained in:
Ammar Bandukwala 2017-04-07 17:19:48 +02:00 committed by Chris Rhodes
parent 253456549c
commit 52ad9e2feb
3 changed files with 39 additions and 13 deletions

View file

@ -337,19 +337,6 @@ type Member struct {
Roles []string `json:"roles"`
}
// A User stores all data for an individual Discord user.
type User struct {
ID string `json:"id"`
Email string `json:"email"`
Username string `json:"username"`
Avatar string `json:"avatar"`
Discriminator string `json:"discriminator"`
Token string `json:"token"`
Verified bool `json:"verified"`
MFAEnabled bool `json:"mfa_enabled"`
Bot bool `json:"bot"`
}
// A Settings stores data for a specific users Discord client settings.
type Settings struct {
RenderEmbeds bool `json:"render_embeds"`

23
user.go Normal file
View file

@ -0,0 +1,23 @@
package discordgo
import (
"fmt"
)
// A User stores all data for an individual Discord user.
type User struct {
ID string `json:"id"`
Email string `json:"email"`
Username string `json:"username"`
Avatar string `json:"avatar"`
Discriminator string `json:"discriminator"`
Token string `json:"token"`
Verified bool `json:"verified"`
MFAEnabled bool `json:"mfa_enabled"`
Bot bool `json:"bot"`
}
//String returns a unique identifier of the form username#discriminator
func (u *User) String() string {
return fmt.Sprintf("%s#%s", u.Username, u.Discriminator)
}

16
user_test.go Normal file
View file

@ -0,0 +1,16 @@
package discordgo
import "testing"
func TestUser(t *testing.T) {
t.Parallel()
user := &User{
Username: "bob",
Discriminator: "8192",
}
if user.String() != "bob#8192" {
t.Errorf("user.String() == %v", user.String())
}
}