1
0
telegram/utils_chat.go

82 lines
2.0 KiB
Go
Raw Normal View History

2017-10-17 11:08:09 +00:00
package telegram
2018-08-15 13:26:07 +00:00
import (
"fmt"
"strings"
)
2018-04-19 13:02:15 +00:00
// IsPrivate checks that the current chat is a private chat with single user.
2018-08-15 11:05:58 +00:00
func (c *Chat) IsPrivate() bool {
2018-08-15 13:26:07 +00:00
return c != nil && strings.EqualFold(c.Type, ChatPrivate)
2017-10-17 11:08:09 +00:00
}
2018-04-19 13:02:15 +00:00
// IsGroup checks that the current chat is a group.
2018-08-15 11:05:58 +00:00
func (c *Chat) IsGroup() bool {
2018-08-15 13:26:07 +00:00
return c != nil && strings.EqualFold(c.Type, ChatGroup)
2017-10-17 11:08:09 +00:00
}
2018-04-19 13:02:15 +00:00
// IsSuperGroup checks that the current chat is a supergroup.
2018-08-15 11:05:58 +00:00
func (c *Chat) IsSuperGroup() bool {
2018-08-15 13:26:07 +00:00
return c != nil && strings.EqualFold(c.Type, ChatSuperGroup)
2017-10-17 11:08:09 +00:00
}
2018-04-19 13:02:15 +00:00
// IsChannel checks that the current chat is a channel.
2018-08-15 11:05:58 +00:00
func (c *Chat) IsChannel() bool {
2018-08-15 13:26:07 +00:00
return c != nil && strings.EqualFold(c.Type, ChatChannel)
2017-10-17 11:08:09 +00:00
}
2018-04-19 13:02:15 +00:00
// HasPinnedMessage checks that the current chat has a pinned message.
2018-08-15 11:05:58 +00:00
func (c *Chat) HasPinnedMessage() bool {
return c != nil && c.PinnedMessage != nil
}
2018-04-19 13:02:15 +00:00
// HasStickerSet checks that the current chat has a sticker set.
2018-08-15 11:05:58 +00:00
func (c *Chat) HasStickerSet() bool {
2018-08-15 13:26:07 +00:00
return c != nil && !strings.EqualFold(c.StickerSetName, "")
}
2018-04-19 13:02:15 +00:00
// StickerSet return StickerSet structure if StickerSetName is available.
2018-08-15 11:05:58 +00:00
func (c *Chat) StickerSet(bot *Bot) *StickerSet {
if !c.HasStickerSet() || bot == nil {
return nil
}
2018-08-15 11:05:58 +00:00
set, err := bot.GetStickerSet(c.StickerSetName)
if err != nil {
return nil
}
return set
}
2018-04-19 13:02:15 +00:00
// FullName returns the full name of chat or FirstName if LastName is not available.
2018-08-15 11:05:58 +00:00
func (c *Chat) FullName() string {
if c == nil {
return ""
}
2018-08-15 13:26:07 +00:00
if c.HasLastName() {
2018-08-15 11:05:58 +00:00
return fmt.Sprintln(c.FirstName, c.LastName)
}
2018-08-15 11:05:58 +00:00
return c.FirstName
}
2018-08-15 13:26:07 +00:00
// HaveLastName checks what the current user has a LastName.
func (c *Chat) HasLastName() bool {
return c != nil && !strings.EqualFold(c.LastName, "")
}
// HaveUsername checks what the current user has a username.
func (c *Chat) HasUsername() bool {
return c != nil && !strings.EqualFold(c.Username, "")
}
func (c *Chat) HasDescription() bool {
return c != nil && !strings.EqualFold(c.Description, "")
}
func (c *Chat) HasInviteLink() bool {
return c != nil && !strings.EqualFold(c.InviteLink, "")
}