Commit 6820d23
Fix: Delete join service message for auto-banned users (#22)
When a user joins, the bot might receive a `ChatMemberUpdated` event before the `NewChatMembers` service message. If the auto-ban is triggered by the `ChatMemberUpdated` event, the service message ID is not yet known, leaving the "X joined the group" message visible.
This change introduces a structured `JoinProcessedCache` that tracks the `JoinMsgID` and `IsBanned` status. If a join message ID arrives for an already banned user (within 10 seconds of the initial join detection), it is now retroactively deleted.
Changes:
- Replaced `JoinProcessedCache map[int64]time.Time` with `map[int64]*JoinProcessedEntry`.
- Added `JoinProcessedEntry` struct in `telegram/telegram.go`.
- Updated `processJoin` in `telegram/autoban.go` to handle late message IDs and mark banned users.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: birabittoh <26506860+birabittoh@users.noreply.github.com>1 parent 43d716a commit 6820d23
2 files changed
Lines changed: 33 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
71 | 80 | | |
72 | 81 | | |
73 | 82 | | |
| |||
81 | 90 | | |
82 | 91 | | |
83 | 92 | | |
84 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
85 | 100 | | |
86 | 101 | | |
87 | 102 | | |
| |||
97 | 112 | | |
98 | 113 | | |
99 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
100 | 120 | | |
101 | 121 | | |
102 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
49 | 56 | | |
50 | 57 | | |
51 | 58 | | |
| |||
231 | 238 | | |
232 | 239 | | |
233 | 240 | | |
234 | | - | |
| 241 | + | |
235 | 242 | | |
236 | 243 | | |
237 | 244 | | |
| |||
0 commit comments