Ignore updates sent as a channel or anonymous admin
Telegram uses one shared fake user for all anonymous group admins and for messages sent as a channel. Such a sender must not own a wallet: reject its updates, do not tip it and do not create a wallet for it. (cherry picked from commit 1b7478fc505b9ed388474192541185bc40569184) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
committed by
Michilis
parent
064f36889a
commit
8989483891
@@ -28,7 +28,7 @@ func (bot TipBot) registerTelegramHandlers() {
|
||||
}
|
||||
|
||||
func getDefaultBeforeInterceptor(bot TipBot) []intercept.Func {
|
||||
return []intercept.Func{bot.idInterceptor}
|
||||
return []intercept.Func{bot.idInterceptor, bot.rejectPlaceholderSenderInterceptor}
|
||||
}
|
||||
func getDefaultDeferInterceptor(bot TipBot) []intercept.Func {
|
||||
return []intercept.Func{bot.unlockInterceptor}
|
||||
|
||||
@@ -58,6 +58,31 @@ func (bot TipBot) idInterceptor(ctx intercept.Context) (intercept.Context, error
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// isPlaceholderSender reports whether u is one of the fake users Telegram puts
|
||||
// into `from` for messages sent on behalf of a chat: channel posts forwarded
|
||||
// to a discussion group (777000), messages sent as a channel (@Channel_Bot,
|
||||
// 136817688) and anonymous group admins (@GroupAnonymousBot, 1087968824).
|
||||
// Everyone who posts that way shares the same user, so it must never own or
|
||||
// receive money.
|
||||
func isPlaceholderSender(u *tb.User) bool {
|
||||
if u == nil {
|
||||
return false
|
||||
}
|
||||
switch u.ID {
|
||||
case 777000, 136817688, 1087968824:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// rejectPlaceholderSenderInterceptor stops updates sent on behalf of a chat.
|
||||
func (bot TipBot) rejectPlaceholderSenderInterceptor(ctx intercept.Context) (intercept.Context, error) {
|
||||
if isPlaceholderSender(ctx.Sender()) {
|
||||
return ctx, fmt.Errorf("[rejectPlaceholderSenderInterceptor] placeholder sender %d", ctx.Sender().ID)
|
||||
}
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
// answerCallbackInterceptor will answer the callback with the given text in the context
|
||||
func (bot TipBot) answerCallbackInterceptor(ctx intercept.Context) (intercept.Context, error) {
|
||||
c := ctx.Callback()
|
||||
@@ -140,6 +165,9 @@ func (bot TipBot) tryLoadUserInterceptor(ctx intercept.Context) (intercept.Conte
|
||||
func (bot TipBot) loadReplyToInterceptor(ctx intercept.Context) (intercept.Context, error) {
|
||||
if ctx.Message() != nil {
|
||||
if ctx.Message().ReplyTo != nil {
|
||||
if isPlaceholderSender(ctx.Message().ReplyTo.Sender) {
|
||||
return ctx, fmt.Errorf("[loadReplyToInterceptor] reply to placeholder sender %d", ctx.Message().ReplyTo.Sender.ID)
|
||||
}
|
||||
if ctx.Message().ReplyTo.Sender != nil {
|
||||
user, _ := GetUser(ctx.Message().ReplyTo.Sender, bot)
|
||||
user.Telegram = ctx.Message().ReplyTo.Sender
|
||||
|
||||
@@ -100,6 +100,9 @@ func (bot *TipBot) GetUserBalance(user *lnbits.User) (amount int64, err error) {
|
||||
}
|
||||
|
||||
func (bot *TipBot) CreateWalletForTelegramUser(tbUser *tb.User) (*lnbits.User, error) {
|
||||
if isPlaceholderSender(tbUser) {
|
||||
return nil, fmt.Errorf("no wallet for placeholder sender %d", tbUser.ID)
|
||||
}
|
||||
// failsafe: do not create wallet for existing user
|
||||
if _, exists := bot.UserExists(tbUser); exists {
|
||||
return nil, fmt.Errorf("user already exists")
|
||||
|
||||
Reference in New Issue
Block a user