* 5. Premium 用户处理 (premium) * allow: Premium 用户自动通过 * ban: Premium 用户自动拦截 * only: 仅允许 Premium 用户(非 Premium 自动拦截) * none: 不做特殊处理
(client: TelegramClient, userId: number, message: Api.Message)
| 1213 | const strategy = cfg.premium(); |
| 1214 | if (strategy === "none") return "skip"; |
| 1215 | |
| 1216 | // 获取用户 premium 状态 |
| 1217 | const sender = (message as any).sender ?? (message as any)._sender; |
| 1218 | let isPremium = false; |
| 1219 | if (sender) { |
| 1220 | isPremium = !!(sender.premium); |
| 1221 | } else { |
| 1222 | try { |
| 1223 | const result = await client.invoke( |
| 1224 | new Api.users.GetFullUser({ id: userId }) |
| 1225 | ) as any; |
| 1226 | isPremium = !!(result?.users?.[0]?.premium); |
| 1227 | } catch (e) { |
| 1228 | log(LogLevel.WARN, `checkPremium: cannot get premium status for ${userId}`, e); |
| 1229 | return "skip"; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | switch (strategy) { |
| 1234 | case "allow": |
| 1235 | if (isPremium) { |
| 1236 | wl.add(userId); |
| 1237 | log(LogLevel.INFO, `Auto-pass Premium user ${userId} (strategy=allow)`); |
| 1238 | return "pass"; |
| 1239 | } |
| 1240 | return "skip"; |
| 1241 | |
| 1242 | case "ban": |
| 1243 | if (isPremium) { |
| 1244 | log(LogLevel.INFO, `Auto-block Premium user ${userId} (strategy=ban)`); |
| 1245 | return "block"; |
| 1246 | } |
| 1247 | return "skip"; |
| 1248 | |
| 1249 | case "only": |
| 1250 | if (!isPremium) { |
| 1251 | log(LogLevel.INFO, `Auto-block non-Premium user ${userId} (strategy=only)`); |
| 1252 | return "block"; |
| 1253 | } |
| 1254 | wl.add(userId); |
| 1255 | log(LogLevel.INFO, `Auto-pass Premium user ${userId} (strategy=only)`); |
| 1256 | return "pass"; |
| 1257 | |
| 1258 | default: |
| 1259 | return "skip"; |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * 执行所有自动过白规则(按优先级顺序) |
| 1265 | * 返回 true 表示已处理(通过或拦截),messageListener 应直接返回 |
| 1266 | * 返回 false 表示继续走验证码流程 |
| 1267 | */ |
no test coverage detected