* 5. Premium 用户处理 (premium) * allow: Premium 用户自动通过 * ban: Premium 用户自动拦截 * only: 仅允许 Premium 用户(非 Premium 自动拦截) * none: 不做特殊处理
(client: TelegramClient, userId: number, message: Api.Message)
| 1213 | // 白名单关键词检查 |
| 1214 | const wlWords = cfg.wlWords(); |
| 1215 | if (wlWords.length > 0) { |
| 1216 | for (const word of wlWords) { |
| 1217 | if (text.includes(word)) { |
| 1218 | wl.add(userId); |
| 1219 | log(LogLevel.INFO, `Auto-pass user ${userId} by whitelist word: "${word}"`); |
| 1220 | return "pass"; |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | // 黑名单关键词检查 |
| 1226 | const blWords = cfg.blWords(); |
| 1227 | if (blWords.length > 0) { |
| 1228 | for (const word of blWords) { |
| 1229 | if (text.includes(word)) { |
| 1230 | log(LogLevel.INFO, `Auto-block user ${userId} by blacklist word: "${word}"`); |
| 1231 | return "block"; |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | return "skip"; |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * 5. Premium 用户处理 (premium) |
| 1241 | * allow: Premium 用户自动通过 |
| 1242 | * ban: Premium 用户自动拦截 |
| 1243 | * only: 仅允许 Premium 用户(非 Premium 自动拦截) |
| 1244 | * none: 不做特殊处理 |
| 1245 | */ |
| 1246 | async function checkPremium(client: TelegramClient, userId: number, message: Api.Message): Promise<AutoRuleResult> { |
| 1247 | const strategy = cfg.premium(); |
| 1248 | if (strategy === "none") return "skip"; |
| 1249 | |
| 1250 | // 获取用户 premium 状态 |
| 1251 | const sender = (message as any).sender ?? (message as any)._sender; |
| 1252 | let isPremium = false; |
| 1253 | if (sender) { |
| 1254 | isPremium = !!(sender.premium); |
| 1255 | } else { |
| 1256 | try { |
| 1257 | const result = await client.invoke( |
| 1258 | new Api.users.GetFullUser({ id: peerTarget(userId) }) |
| 1259 | ) as any; |
| 1260 | isPremium = !!(result?.users?.[0]?.premium); |
| 1261 | } catch (e) { |
| 1262 | log(LogLevel.WARN, `checkPremium: cannot get premium status for ${userId}`, e); |
| 1263 | return "skip"; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | switch (strategy) { |
no test coverage detected