Add Promo Manager, Content Drops, admin UI updates and runtime improvements - #88
Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
📝 WalkthroughWalkthroughConfiguration and documentation updates for the Runewager bot. Enhanced .env.example with HMAC key guidance, refined .gitignore rules for environment templates and runtime data, added comprehensive functionality documentation map, updated developer contract requirements in CLAUDE.md, and introduced smoke tests validating callback handler coverage. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
Nitpicks 🔍
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
.gitignore (1)
32-41: Redundant entries:data/*.jsonalready covers the individual JSON files.Lines 32–37 list specific JSON files, but line 40 adds
data/*.jsonwhich already matches all of them. Consider removing the redundant individual entries for cleaner maintainability.Proposed consolidation
# Runtime state files -data/analytics.json -data/dashboard.json -data/helpful_messages.json -data/promo-history.json -data/runtime-state.json -data/sshv-sessions.json - -# Runtime generated data + backups +# Runtime generated data (JSON state + backups) data/*.json data/backups/**🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.gitignore around lines 32 - 41, Remove the redundant explicit JSON file entries (data/analytics.json, data/dashboard.json, data/helpful_messages.json, data/promo-history.json, data/runtime-state.json, data/sshv-sessions.json) and rely on the existing glob entry data/*.json to cover them; keep the data/backups/** entry for backups. Update the .gitignore by deleting the individual data/*.json lines while ensuring data/*.json and data/backups/** remain to preserve the intended ignores.test/smoke.test.js (1)
58-72: Consider using__dirnamefor consistent path resolution.The test uses
'.'as the root directory, which depends on the current working directory at execution time. For robustness across different test runners and execution contexts, consider deriving the root from__dirname(as done intest/runtime.test.js).Proposed fix
+const rootDir = path.resolve(__dirname, '..'); + test('menu callback buttons map to handlers (literal or dynamic patterns)', () => { - const jsFiles = collectJsFiles('.'); + const jsFiles = collectJsFiles(rootDir); const combinedSource = jsFiles🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/smoke.test.js` around lines 58 - 72, The test currently calls collectJsFiles('.') which relies on the process CWD; change it to derive the root from __dirname (e.g., pass __dirname or a path.resolve/ path.join based on __dirname) so collectJsFiles and subsequent fs.readFileSync calls use a stable test directory; update the test invocation where collectJsFiles('.') is used (and import/require path if needed) so combinedSource is built from files under __dirname instead of '.'..env.example (1)
17-17: Document validLOG_LEVELvalues.As per coding guidelines, the
LOG_LEVELenvironment variable should document its valid values.Proposed fix
-LOG_LEVEL=info +LOG_LEVEL=info # Valid values: debug, info, warn, error🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.env.example at line 17, Update the .env.example entry for LOG_LEVEL to document the valid log levels and the default; specifically, replace or augment "LOG_LEVEL=info" with a comment or inline note listing accepted values (e.g., TRACE, DEBUG, INFO, WARN, ERROR, FATAL or similar lowercase variants like trace, debug, info, warn, error, fatal) and indicate the default ("info") and expected format so that consumers know allowable values for LOG_LEVEL.RUNEWAGER_FUNCTIONALITY_MAP.md (1)
266-306: Add language specifier to fenced code blocks.The flowchart blocks at lines 266, 279, 289, and 298 lack language specifiers, which triggers markdownlint warnings (MD040). Use
textorplaintextfor pseudo-code/flowcharts.Example fix for one block
-``` +```text /promo or menu_claim_bonus -> load active promos🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@RUNEWAGER_FUNCTIONALITY_MAP.md` around lines 266 - 306, Add a language specifier (e.g., text or plaintext) to each fenced code block used for flowcharts so markdownlint MD040 is resolved: update the blocks that start with "/promo or menu_claim_bonus", "admin_cmd_announce_start or /announce", "Admin forwards message from channel/group", and "Admin starts wizard (gwiz)" to use ```text (or ```plaintext) instead of bare ``` so the pseudo-code/flow diagrams are explicitly marked as plain text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.env.example:
- Line 6: The .env entry for WEBAPP_HMAC_KEY has a space before the inline
comment and an unquoted empty value which can break dotenv parsers; update the
block referencing WEBAPP_HMAC_KEY by either moving the explanatory comment to
its own preceding line and setting WEBAPP_HMAC_KEY="" (quoted empty string) or
by quoting the value and removing the stray space so it reads with an explicit
empty quoted value and the comment on a separate line; ensure the symbol
WEBAPP_HMAC_KEY is left blank but quoted and that comments are not inline after
the =.
---
Nitpick comments:
In @.env.example:
- Line 17: Update the .env.example entry for LOG_LEVEL to document the valid log
levels and the default; specifically, replace or augment "LOG_LEVEL=info" with a
comment or inline note listing accepted values (e.g., TRACE, DEBUG, INFO, WARN,
ERROR, FATAL or similar lowercase variants like trace, debug, info, warn, error,
fatal) and indicate the default ("info") and expected format so that consumers
know allowable values for LOG_LEVEL.
In @.gitignore:
- Around line 32-41: Remove the redundant explicit JSON file entries
(data/analytics.json, data/dashboard.json, data/helpful_messages.json,
data/promo-history.json, data/runtime-state.json, data/sshv-sessions.json) and
rely on the existing glob entry data/*.json to cover them; keep the
data/backups/** entry for backups. Update the .gitignore by deleting the
individual data/*.json lines while ensuring data/*.json and data/backups/**
remain to preserve the intended ignores.
In `@RUNEWAGER_FUNCTIONALITY_MAP.md`:
- Around line 266-306: Add a language specifier (e.g., text or plaintext) to
each fenced code block used for flowcharts so markdownlint MD040 is resolved:
update the blocks that start with "/promo or menu_claim_bonus",
"admin_cmd_announce_start or /announce", "Admin forwards message from
channel/group", and "Admin starts wizard (gwiz)" to use ```text (or
```plaintext) instead of bare ``` so the pseudo-code/flow diagrams are
explicitly marked as plain text.
In `@test/smoke.test.js`:
- Around line 58-72: The test currently calls collectJsFiles('.') which relies
on the process CWD; change it to derive the root from __dirname (e.g., pass
__dirname or a path.resolve/ path.join based on __dirname) so collectJsFiles and
subsequent fs.readFileSync calls use a stable test directory; update the test
invocation where collectJsFiles('.') is used (and import/require path if needed)
so combinedSource is built from files under __dirname instead of '.'.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.env.example.gitignoreCLAUDE.mdRUNEWAGER_FUNCTIONALITY_MAP.mdindex.jstest/smoke.test.js
| ADMIN_IDS=YOUR_TELEGRAM_USER_ID | ||
| BOT_TOKEN= | ||
| WEBAPP_HMAC_KEY= | ||
| WEBAPP_HMAC_KEY= # 32-byte secret for HMAC-signing webapp payloads/CSRF tokens; generate with: openssl rand -hex 32 (or openssl rand -base64 32); keep secret and never commit real values |
There was a problem hiding this comment.
Fix .env format: remove space before comment and quote the empty value.
The static analysis correctly flags that spaces around = and unquoted values can cause parsing issues with some dotenv implementations. The comment is helpful but should be on a separate line or the value should be properly formatted.
Proposed fix
-WEBAPP_HMAC_KEY= # 32-byte secret for HMAC-signing webapp payloads/CSRF tokens; generate with: openssl rand -hex 32 (or openssl rand -base64 32); keep secret and never commit real values
+# 32-byte secret for HMAC-signing webapp payloads/CSRF tokens
+# Generate with: openssl rand -hex 32 (or openssl rand -base64 32)
+# Keep secret and never commit real values
+WEBAPP_HMAC_KEY=""📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| WEBAPP_HMAC_KEY= # 32-byte secret for HMAC-signing webapp payloads/CSRF tokens; generate with: openssl rand -hex 32 (or openssl rand -base64 32); keep secret and never commit real values | |
| # 32-byte secret for HMAC-signing webapp payloads/CSRF tokens | |
| # Generate with: openssl rand -hex 32 (or openssl rand -base64 32) | |
| # Keep secret and never commit real values | |
| WEBAPP_HMAC_KEY="" |
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 6-6: [SpaceCharacter] The line has spaces around equal sign
(SpaceCharacter)
[warning] 6-6: [ValueWithoutQuotes] This value needs to be surrounded in quotes
(ValueWithoutQuotes)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.env.example at line 6, The .env entry for WEBAPP_HMAC_KEY has a space
before the inline comment and an unquoted empty value which can break dotenv
parsers; update the block referencing WEBAPP_HMAC_KEY by either moving the
explanatory comment to its own preceding line and setting WEBAPP_HMAC_KEY=""
(quoted empty string) or by quoting the value and removing the stray space so it
reads with an explicit empty quoted value and the comment on a separate line;
ensure the symbol WEBAPP_HMAC_KEY is left blank but quoted and that comments are
not inline after the =.
| const patterns = []; | ||
| const matches = source.matchAll(/bot\.action\(\s*\/(.+?)\/([dgimsuvy]*)/g); | ||
| for (const m of matches) { | ||
| try { |
There was a problem hiding this comment.
Suggestion: The smoke test that verifies every menu callback button has a corresponding handler becomes ineffective because extractActionRegexPatterns includes the generic bot.action(/.*/, ...) catch‑all pattern, so every callback ID will match at least one dynamic regex and uncovered will always be empty; to make the test meaningful, the catch‑all pattern (and other similarly generic patterns) should be excluded from dynamicActionPatterns. [logic error]
Severity Level: Major ⚠️
- ⚠️ Catch-all bot.action(/.*/) neuters callback coverage test.
- ⚠️ Missing menu callback handlers may slip through smoke tests.| try { | |
| const patternSource = m[1]; | |
| const flags = m[2]; | |
| // Ignore generic catch-all patterns like /.*/ which don't represent specific menu handlers. | |
| if (patternSource === '.*') continue; | |
| try { | |
| patterns.push(new RegExp(patternSource, flags)); |
Steps of Reproduction ✅
1. Run the smoke tests using Node's test runner: `node --test test/smoke.test.js`; this
executes `test('menu callback buttons map to handlers (literal or dynamic patterns)',
...)` defined in `test/smoke.test.js:58-72`.
2. Inside that test (`test/smoke.test.js:64-66`), `extractActionRegexPatterns` (defined at
`test/smoke.test.js:40-50`) is called with the concatenated contents of all `.js` files,
including `index.js`.
3. In `index.js:9956` there is a generic catch‑all handler `bot.action(/.*/, async (ctx)
=> { ... });` (verified via Grep), which matches the regex
`/bot\.action\(\s*\/(.+?)\/([dgimsuvy]*)/g` used in `extractActionRegexPatterns`.
4. When `extractActionRegexPatterns` processes that line, it constructs `new RegExp('.*',
'')` and adds it to `dynamicActionPatterns`; because `/.*/.test(id)` returns `true` for
every callback ID collected from `Markup.button.callback(...)`, the filter at
`test/smoke.test.js:68-70` always finds `some(pattern => pattern.test(id))` and
`uncovered` is forced to `[]`, so the assertion at line 72 can never fail even if a menu
callback button has no specific `bot.action` handler.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** test/smoke.test.js
**Line:** 44:44
**Comment:**
*Logic Error: The smoke test that verifies every menu callback button has a corresponding handler becomes ineffective because `extractActionRegexPatterns` includes the generic `bot.action(/.*/, ...)` catch‑all pattern, so every callback ID will match at least one dynamic regex and `uncovered` will always be empty; to make the test meaningful, the catch‑all pattern (and other similarly generic patterns) should be excluded from `dynamicActionPatterns`.
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. |
User description
Motivation
Description
promoManagerStorepersistence, promo normalization, eligibility evaluation, claim records, CLI admin commands (/pmapprove,/pmdeny) and full create/edit/pause/delete/preview flows reachable from a new Promo Manager admin UI; promo DB saved todata/promo-manager-db.jsonand loaded/saved vialoadPromoManagerDb()/savePromoManagerDb()inindex.js./promoand claim flow now show DB-backed promos and enforce new rules (new-user vs existing, wager requirements, cooldowns, claim limit, auto-approve vs admin review).postTipToConfiguredTarget, auto-register forwarded chats,/register_chatcommand, improved scheduler, and admin test/send controls.sendAnnouncementTargetshelper, addedverify_bot_setupandregister_chatcommands, and many callback handlers / aliases for compatibility..env.exampleclarifiedWEBAPP_HMAC_KEYand placeholders,.gitignoreadjusted to keep.env.exampleand addeddata/*.json/backups patterns, addedbroadcastConfigStore,PROMO_STATUS/PROMO_REQUIREMENTenums and numerous migration/shimming changes to keep backward compatibility for older persisted state.RUNEWAGER_FUNCTIONALITY_MAP.md(comprehensive functionality map) and updatedCLAUDE.mdwith AI agent contract requirements.test/smoke.test.jsto verify that literal callback_ids andbot.actionhandlers are covered (scans project JS files, validates literal and regex handlers).Testing
node --check index.jsas part of the smoke test and it passed.test/smoke.test.jswhich validates callback/button handler coverage; the test run completed and tests passed.Codex Task
Summary by CodeRabbit
Release Notes
Documentation
Chores
CodeAnt-AI Description
Add static smoke test for callback/action coverage, expand functionality map, and clarify WEBAPP_HMAC_KEY in env example
What Changed
Impact
✅ Fewer missing callback handler regressions reaching runtime✅ Clearer setup instructions for webapp HMAC configuration✅ Faster developer onboarding and audits with a single source-of-truth💡 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.