Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
fwzookeeper/vendor/gitlab.com/toby3d/telegram/utils_user.go

50 lines
1.0 KiB
Go

package telegram
import (
"golang.org/x/text/language"
"golang.org/x/text/message"
)
// Language parse LanguageCode of current user and returns language.Tag.
func (u *User) Language() language.Tag {
if u == nil {
return language.Und
}
tag, err := language.Parse(u.LanguageCode)
if err != nil {
return language.Und
}
return tag
}
// NewPrinter create simple message.Printer with User.Language() by default.
func (u *User) NewPrinter() *message.Printer {
return message.NewPrinter(u.Language())
}
// FullName returns the full name of user or FirstName if LastName is not
// available.
func (u *User) FullName() string {
if u == nil {
return ""
}
if u.HasLastName() {
return u.FirstName + " " + u.LastName
}
return u.FirstName
}
// HaveLastName checks what the current user has a LastName.
func (u *User) HasLastName() bool {
return u != nil && u.LastName != ""
}
// HaveUsername checks what the current user has a username.
func (u *User) HasUsername() bool {
return u != nil && u.Username != ""
}