mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-03 03:35:04 +03:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user