(msg: any)
| 813 | chatId = String(msg.peerId); |
| 814 | } else if (msg.chatId) { |
| 815 | chatId = String(msg.chatId); |
| 816 | } else { |
| 817 | return; |
| 818 | } |
| 819 | } catch { |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | const activeLottery = getActiveLottery(chatId); |
| 824 | if (!activeLottery || msg.message.trim() !== activeLottery.keyword) { |
| 825 | return; |
| 826 | } |
| 827 | |
| 828 | const sender = await msg.getSender(); |
| 829 | if (!sender || sender.bot) { |
| 830 | return; |
| 831 | } |
| 832 | |
| 833 | // Check if user already participated |
| 834 | const participants = getLotteryParticipants(activeLottery.id); |
| 835 | const alreadyParticipated = participants.some(p => p.user_id === String(sender.id || sender)); |
| 836 | |
| 837 | if (alreadyParticipated) { |
| 838 | try { |
| 839 | const replyMsg = await msg.reply({ |
| 840 | message: `⚠️ <b>重复参与</b>\n\n您已参加过抽奖,请勿重复参加`, |
| 841 | parseMode: "html", |
| 842 | }); |
| 843 | |
| 844 | // Delete both messages after delay (generation-safe) |
| 845 | const gen1 = getCurrentGeneration(); |
| 846 | const t1 = setTimeout(async () => { |
| 847 | pendingTimers.delete(t1); |
| 848 | if (getCurrentGeneration() !== gen1) return; |
| 849 | try { |
| 850 | await replyMsg.delete(); |
| 851 | await msg.delete(); |
| 852 | } catch (error) { |
| 853 | console.warn("Failed to delete duplicate participation messages:", error); |
| 854 | } |
| 855 | }, activeLottery.delete_delay * 1000); |
| 856 | pendingTimers.add(t1); |
| 857 | } catch (error) { |
| 858 | console.warn("Failed to handle duplicate participation:", error); |
| 859 | } |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | // Validate user conditions |
| 864 | const validation = await validateUserConditions(msg.client, sender, activeLottery, chatId); |
| 865 | if (!validation.valid) { |
| 866 | try { |
| 867 | await msg.delete(); // Silently delete invalid participation |
| 868 | } catch (error) { |
| 869 | console.warn("Failed to delete invalid participation message:", error); |
| 870 | } |
| 871 | return; |
| 872 | } |
nothing calls this directly
no test coverage detected