From 63521b8f90af65cad9ca7510be3c2b76307d8090 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Fri, 8 Jul 2022 17:43:56 -0400 Subject: Extended room disco info --- telegram/utils.go | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'telegram/utils.go') diff --git a/telegram/utils.go b/telegram/utils.go index 5244803..377b784 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -1039,7 +1039,7 @@ func (c *Client) GetChatDescription(chat *client.Chat) string { return fullInfo.Description } } else { - log.Warnf("Coudln't retrieve private chat info: %v", err.Error()) + log.Warnf("Couldn't retrieve private chat info: %v", err.Error()) } } else if chatType == client.TypeChatTypeBasicGroup { basicGroupType, _ := chat.Type.(*client.ChatTypeBasicGroup) @@ -1049,7 +1049,7 @@ func (c *Client) GetChatDescription(chat *client.Chat) string { if err == nil { return fullInfo.Description } else { - log.Warnf("Coudln't retrieve basic group info: %v", err.Error()) + log.Warnf("Couldn't retrieve basic group info: %v", err.Error()) } } else if chatType == client.TypeChatTypeSupergroup { supergroupType, _ := chat.Type.(*client.ChatTypeSupergroup) @@ -1059,12 +1059,41 @@ func (c *Client) GetChatDescription(chat *client.Chat) string { if err == nil { return fullInfo.Description } else { - log.Warnf("Coudln't retrieve supergroup info: %v", err.Error()) + log.Warnf("Couldn't retrieve supergroup info: %v", err.Error()) } } return "" } +// GetChatMemberCount obtains the member count depending on the chat type +func (c *Client) GetChatMemberCount(chat *client.Chat) int32 { + chatType := chat.Type.ChatTypeType() + if chatType == client.TypeChatTypePrivate { + return 2 + } else if chatType == client.TypeChatTypeBasicGroup { + basicGroupType, _ := chat.Type.(*client.ChatTypeBasicGroup) + basicGroup, err := c.client.GetBasicGroup(&client.GetBasicGroupRequest{ + BasicGroupId: basicGroupType.BasicGroupId, + }) + if err == nil { + return basicGroup.MemberCount + } else { + log.Warnf("Couldn't retrieve basic group: %v", err.Error()) + } + } else if chatType == client.TypeChatTypeSupergroup { + supergroupType, _ := chat.Type.(*client.ChatTypeSupergroup) + supergroup, err := c.client.GetSupergroup(&client.GetSupergroupRequest{ + SupergroupId: supergroupType.SupergroupId, + }) + if err == nil { + return supergroup.MemberCount + } else { + log.Warnf("Couldn't retrieve supergroup: %v", err.Error()) + } + } + return 0 +} + // GetGroupChats obtains all group chats func (c *Client) GetGroupChats() []*client.Chat { var groupChats []*client.Chat -- cgit v1.2.3