fix(tgbot): treat messages sent on behalf of a chat as strangers

Telegram fills a message's From with one of three fixed placeholder
users whenever it is posted on behalf of a chat, by an anonymous group
admin or a channel. The level gate and the invite claim took that
placeholder for the account acting, so it got a throttle window of its
own, and a claim bound the client to an id every anonymous admin shares.

Such a message is rated as a stranger whatever the placeholder id is
bound to, and its invite claim is refused before it is counted or bound.
This commit is contained in:
MHSanaei
2026-11-01 13:47:40 +01:00
parent 8f3dd70db4
commit 99f386820d
4 changed files with 74 additions and 2 deletions
+10 -1
View File
@@ -46,10 +46,19 @@ func commandAllowed(level userLevel, command string) bool {
return commandsByLevel[level][command]
}
// sentForChat reports that no account stands behind message.From: a post by an
// anonymous admin or a channel carries a placeholder user shared by everybody.
func sentForChat(message *telego.Message) bool {
return message.SenderChat != nil || message.From.IsBot
}
// gateCommand reports whether a command reaches answerCommand, and as whom. A
// stranger's refused command gets no reply, so the bot reveals nothing to probe.
func (t *Tgbot) gateCommand(message *telego.Message) (isAdmin bool, ok bool) {
level := t.levelOf(message.From.ID)
level := levelStranger
if !sentForChat(message) {
level = t.levelOf(message.From.ID)
}
command, _, _ := tu.ParseCommand(message.Text)
if commandAllowed(level, command) {
return level == levelAdmin, true