mirror of
https://github.com/BEARlogin/max-telegram-bridge-bot.git
synced 2026-04-28 03:39:46 +00:00
When a group owner/admin enables "Remain anonymous", their messages are sent from @GroupAnonymousBot with msg.SenderChat pointing to the group itself. GetChatMember was then checking the bot's status (not admin) and rejecting valid owners with "only for admins". New helper isTgAnonymousAdmin(msg) returns true when SenderChat.ID equals Chat.ID; in that case we skip the GetChatMember check and treat the user as admin. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package main
|
|
|
|
import maxschemes "github.com/max-messenger/max-bot-api-client-go/schemes"
|
|
|
|
// isTgGroup returns true if the TG chat type indicates a group.
|
|
func isTgGroup(chatType string) bool {
|
|
return chatType == "group" || chatType == "supergroup"
|
|
}
|
|
|
|
// isTgChannel returns true if the TG chat type is a channel.
|
|
func isTgChannel(chatType string) bool {
|
|
return chatType == "channel"
|
|
}
|
|
|
|
// isTgAdmin returns true if the TG ChatMember status indicates admin rights.
|
|
func isTgAdmin(memberStatus string) bool {
|
|
return memberStatus == "creator" || memberStatus == "administrator"
|
|
}
|
|
|
|
// isTgAnonymousAdmin returns true if the message was sent by an anonymous admin
|
|
// (owner/admin with "Remain anonymous" enabled). In this case msg.From is
|
|
// @GroupAnonymousBot and msg.SenderChat is the group itself.
|
|
func isTgAnonymousAdmin(msg *TGMessage) bool {
|
|
if msg == nil || msg.SenderChat == nil {
|
|
return false
|
|
}
|
|
return msg.SenderChat.ID == msg.Chat.ID
|
|
}
|
|
|
|
// isMaxGroup returns true if the MAX chat type indicates a group.
|
|
func isMaxGroup(chatType maxschemes.ChatType) bool {
|
|
return chatType == maxschemes.CHAT || chatType == maxschemes.CHANNEL
|
|
}
|
|
|
|
// isMaxUserAdmin returns true if userID is found in the admin members list.
|
|
func isMaxUserAdmin(members []maxschemes.ChatMember, userID int64) bool {
|
|
for _, m := range members {
|
|
if m.UserId == userID {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|