Resolve PR #2 review comments: startup, reminders, callbacks, and persistence - #3
Conversation
|
CodeAnt AI is reviewing your PR. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughA comprehensive Telegram bot implementation using Telegraf is introduced with full-featured functionality including user management, promo codes, giveaways with eligibility checks, admin controls, state persistence, and periodic task scheduling. The bot enforces verification flows, tracks user participation, and stores state to a JSON file. Changes
Sequence DiagramssequenceDiagram
participant User as Telegram User
participant Bot as Bot (Telegraf)
participant State as State Store
participant File as bot_state.json
User->>Bot: /start command
Bot->>State: Check if user exists
alt User not in system
Bot->>State: Create default user profile
Bot->>Bot: Present age gate keyboard
else User exists
Bot->>Bot: Show main menu keyboard
end
State->>File: Mark state dirty (scheduled persist)
Bot->>User: Send welcome message with keyboard
sequenceDiagram
participant Admin as Admin User
participant Bot as Bot (Telegraf)
participant State as State Store
participant User as Participant User
participant File as bot_state.json
Admin->>Bot: /admin_giveaway_create
Bot->>Admin: Request giveaway details (pending action)
Admin->>Bot: Provide title, description, duration
Bot->>State: Create giveaway, schedule expiry timer
State->>File: Persist giveaway entry
Bot->>Admin: Confirm creation
loop Participant Flow
User->>Bot: Click "Join Giveaway" button
Bot->>State: Check eligibility (linked username, joins, age, verification, promos, walkthrough)
alt Eligible
Bot->>State: Add user to giveaway participants
Bot->>User: Confirm participation
else Not Eligible
Bot->>User: Show eligibility failure reason
end
end
loop Countdown Phase
Bot->>Bot: Scheduled reminder at T-1h, T-10m
Bot->>User: Send participation reminders
end
Bot->>Bot: Giveaway expires (timer fires)
Bot->>State: Select random unique winner from participants
Bot->>User: Notify winner
Bot->>Admin: Notify admin of giveaway completion
State->>File: Finalize and persist giveaway result
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| { title: '1) First Time Setup Wizard', body: 'Use /start, pass age gate, and open the main menu.' }, | ||
| { title: '2) Create Runewager Account', body: `Open signup link and create your account: ${LINKS.runewagerSignup}` }, | ||
| { title: '3) Generate Discord Verification Code', body: 'Go to Profile → Generate Code in Runewager.', imageUrl: DISCORD_CODE_GENERATION_IMAGE_URL }, | ||
| { title: '4) Verify in Discord', body: `Join Runewager Discord and post code in #web-link channel:\n${LINKS.runewagerDiscord}\n${LINKS.discordWebLink}`, imageUrl: DISCORD_VERIFY_IMAGE_URL }, |
There was a problem hiding this comment.
Suggestion: The walkthrough step text hardcodes a specific promo code from promoStore.code, but admins can later change the promo via the admin panel, leading to stale and incorrect instructions for users; removing the hardcoded code from the walkthrough and referring generically to the current promo code avoids this mismatch. [logic error]
Severity Level: Major ⚠️
- ⚠️ Walkthrough step can display outdated promo code instructions.
- ⚠️ New users may follow wrong promo setup guidance.| { title: '4) Verify in Discord', body: `Join Runewager Discord and post code in #web-link channel:\n${LINKS.runewagerDiscord}\n${LINKS.discordWebLink}`, imageUrl: DISCORD_VERIFY_IMAGE_URL }, | |
| { title: '5) Enter Promo Code', body: 'Open promo input page and enter the current promo code shown in the bot.', imageUrl: PROMO_ENTRY_IMAGE_URL }, |
Steps of Reproduction ✅
1. Start the bot with `node index.js`; on startup `buildWalkthroughCatalog()` at
`index.js:1536-1572` runs once and populates `walkthroughCatalog` (defined at
`index.js:215`) with step 5 text using the initial `promoStore.code` value defined at
`index.js:56-64`.
2. As an admin (ID present in `ADMIN_IDS`), run `/admin` in any chat to open the admin
keyboard via the handler at `index.js:495-501`, then tap "✏️ Edit Promo Code" which
triggers `admin_edit_code` at `index.js:782-789`.
3. Respond with a new promo code string and confirm via the "✅ Confirm" button handled by
`admin_edit_code_yes` at `index.js:1448-1455`, which updates `promoStore.code` to the new
value while leaving the already-constructed `walkthroughCatalog` unchanged.
4. As a regular user, run `/walkthrough` (handler at `index.js:481-485`) or tap "🧭 Guided
Walkthrough" (callback `menu_walkthrough` at `index.js:748-754`), causing
`sendWalkthroughStep()` at `index.js:1508-1533` to render step 5 with the stale hardcoded
body using the old promo code, while current promo flows such as `menu_claim_bonus` at
`index.js:605-637` display the updated `promoStore.code`, leading to conflicting
instructions.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** index.js
**Line:** 1540:1540
**Comment:**
*Logic Error: The walkthrough step text hardcodes a specific promo code from `promoStore.code`, but admins can later change the promo via the admin panel, leading to stale and incorrect instructions for users; removing the hardcoded code from the walkthrough and referring generically to the current promo code avoids this mismatch.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.|
CodeAnt AI finished reviewing your PR. |
Audit PR #3 merge and fix walkthrough promo-code staleness
Resolve PR #2 review comments: startup, reminders, callbacks, and persistence
Audit PR #3 merge and fix walkthrough promo-code staleness
User description
Motivation
bot.launch()is awaited and failures are handled explicitly to avoid unhandled rejections and silent crashes.Description
bot.launch()with an asyncstartBot()that callsloadStateSafe(), restores giveaway timers,await bot.launch(), logs success, andprocess.exit(1)on startup failure.bot_state.json) with Map/Set serialization/deserialization foruserStore,promoStore, andgiveawayStore, plus periodic flush (every 5s) and save-on-shutdown hooks (SIGINT/SIGTERM) and restore logic for running giveaways.user.wagerBonus.notifyAttempts >= 3so locked users are no longer re-reminded.answerCbSafe(ctx, ...)and applied it to regex callback handlers that have early-return paths soctx.answerCbQuery()is always invoked before returning.beginPendingAction()which clears any priorpendingActionbefore starting a new multi-step flow and a/cancelcommand to clear stale flows.walk_done) and made image sends robust by validating URLs (isValidHttpUrl) and falling back to text on errors.gw_cancel_yesnow clears all scheduled reminder timers and emptiesgiveaway.reminders; restore routines re-schedule reminders and timers on startup.Math.random()withcrypto.randomIntinpickRandomUniquefor secure randomness.bot.use()middleware to ensure users are loaded andmarkStateDirty()tracking to minimize unnecessary writes.Testing
node --check index.jswhich completed successfully.answerCbQuerypaths, walkthrough marking and image fallback, pending-action clearing, giveaway reminder cleanup, broadcast rate-limiting, andrandomIntusage) by updating and re-checking the file.BOT_TOKENandADMIN_IDSto exercise DM delivery, callback interactions, scheduled reminders, and persistence restore behavior.Codex Task
Summary by CodeRabbit
CodeAnt-AI Description
Persist bot state to survive restarts and fix reminder/callback/workflow reliability
What Changed
Impact
✅ Durable user state across restarts✅ Fewer repeated reminder messages to locked users✅ Clearer broadcast delivery results and fewer hanging Telegram spinners💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.