Skip to content

Admin mode rewrite + env + gitignore - #71

Merged
gamblecodezcom merged 6 commits into
mainfrom
codex/configure-git-and-update-project-files
Feb 24, 2026
Merged

Admin mode rewrite + env + gitignore#71
gamblecodezcom merged 6 commits into
mainfrom
codex/configure-git-and-update-project-files

Conversation

@gamblecodezcom

@gamblecodezcom gamblecodezcom commented Feb 24, 2026

Copy link
Copy Markdown
Owner

User description

Motivation

  • Consolidate and simplify admin UX so /admin is the single admin entry and admin-mode toggles always behave predictably.
  • Secure repository state by ignoring environment and log files and ensure local git metadata points to the correct remote and default branch.

Description

  • Reworked admin-mode logic in index.js so /on sets adminModeOn = true and replies 🔧 Admin Mode Enabled, and /off sets adminModeOn = false and replies 👤 Admin Mode Disabled, and those toggles always work for admins.
  • Removed legacy admin command handlers (/admin_help, /admin_dashboard, /adminmode, and a few legacy admin_mode handlers) and kept bot.command('admin', ...) as the single admin entry that opens the Admin Dashboard.
  • Updated admin dashboard wiring and menus so admin button callback uses callback_data: admin_dashboard, the persistent admin menu shows the requested sections (Users & Stats, Giveaways, Promo Tools, System Tools, Mode Toggle) and header shows ON/OFF status.
  • Added a safe .gitignore file with the requested rules to exclude .env, *.env, logs/, node_modules/, temp/cache/build dirs, and common system files, and updated repository metadata (.git/config and .git/HEAD) to set the remote to git@github.com:gamblecodezcom/Runewager.git and default branch to main.

Testing

  • Ran syntax/quick-check with npm run check and it completed successfully.
  • Ran the full test suite with npm test and all tests passed (33/33 passing).
  • Launched a short runtime smoke test with BOT_TOKEN=123:TEST ADMIN_IDS=1 node index.js and the bot started with expected runtime message.
  • Verified .gitignore is excluding .env and logs with git check-ignore -v .env logs/example.log which returned the .gitignore matches.

Note: I could not import the Android .env file because the provided source path was not present in this environment, so the .env file was not copied (per your instructions it should not be committed anyway). READY FOR PUSH — You may now run:
git add .
git commit -m 'Admin mode rewrite + env + gitignore'
git push origin main


Codex Task


CodeAnt-AI Description

Unify admin dashboard entry and simplify admin-mode behavior

What Changed

  • Admin dashboard and admin menu buttons use a single, consistent entry ("Admin Dashboard") and show clearer section names (Users & Stats, Giveaways, Promo Tools, System Tools) with a visible Mode Toggle status line
  • Admin-mode toggles (/on, /off and dashboard toggle buttons) now send simple, consistent confirmations ("🔧 Admin Mode Enabled" / "👤 Admin Mode Disabled"); the legacy adminmode, admin_help and admin_dashboard commands were removed
  • Admin checks no longer block admin-only actions when an admin has previously switched to "user mode"; admin-only help and admin actions (e.g., giveaway pause/resume, dashboard access) remain available to admins even after using /on

Impact

✅ Single admin dashboard entry in menus
✅ Consistent admin-mode feedback messages
✅ Admin actions available while testing in user mode

💡 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:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

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:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

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.

Summary by CodeRabbit

  • Improvements

    • Admin dashboard interface updated with consistent naming and navigation
    • Admin menu now displays current mode toggle status
    • Admin commands remain functional across different user modes
    • Administrative command descriptions clarified
  • Removed

    • Admin help command removed

@codeant-ai

codeant-ai Bot commented Feb 24, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@codeant-ai codeant-ai Bot added the size:S This PR changes 10-29 lines, ignoring generated files label Feb 24, 2026
@codeant-ai

codeant-ai Bot commented Feb 24, 2026

Copy link
Copy Markdown

Sequence Diagram

Shows the simplified admin-mode toggles (/on and /off) and the single admin dashboard entry (/admin /admin_dashboard). The PR centralizes admin access, updates dashboard callbacks, and ensures toggles always update the stored user adminModeOn state and the persistent admin menu reflects the current mode.

sequenceDiagram
    participant Admin
    participant Bot
    participant UserStore

    Admin->>Bot: /on (enable admin-mode view)
    Bot->>UserStore: set user.adminModeOn = true
    Bot-->>Admin: "🔧 Admin Mode Enabled"

    Admin->>Bot: /admin or press Admin Dashboard
    Bot->>UserStore: get user
    Bot-->>Admin: sendPersistentAdminMenu (shows Mode Toggle status: ON)

    Admin->>Bot: press Mode Toggle OFF (callback)
    Bot->>UserStore: set user.adminModeOn = false
    Bot-->>Admin: "👤 Admin Mode Disabled"
Loading

Generated by CodeAnt AI

@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@gamblecodezcom has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between cc2b416 and a57f2ca.

📒 Files selected for processing (1)
  • index.js
📝 Walkthrough

Walkthrough

Updates .gitignore to consolidate environment and log file patterns, and refactors admin command handling in index.js by removing admin-mode validation bypass, renaming dashboard callbacks, updating function signatures, and removing the admin help command.

Changes

Cohort / File(s) Summary
VCS Configuration
.gitignore
Consolidates environment patterns to *.env, removes granular state file rules, standardizes log patterns, adds dist/build/cache directories and system files.
Admin Command Refactoring
index.js
Removes admin-bypass validation in requireAdmin, renames admin_dashboard_action to admin_dashboard, updates adminMainMenuText(user) signature to include mode toggle status, removes admin_help command, and updates menu/help text references.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size:L

Poem

🐰 Admin paths are now so clean,
Dashboard named where it's been,
Modes and menus realigned,
Guard removed, new flow designed—
Command consistency at last! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Admin mode rewrite + env + gitignore' accurately captures the three main categories of changes: admin mode refactoring, environment file handling, and gitignore updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/configure-git-and-update-project-files

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread index.js Outdated
const user = getUser(ctx);
// Block if not admin, or if admin is in user-mode (/on)
if (!ADMIN_IDS.includes(Number(user.id)) || user.adminModeOn) { await ctx.answerCbQuery('Admin only.'); return; }
if (!ADMIN_IDS.includes(Number(user.id))) { await ctx.answerCbQuery('Admin only.'); return; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The help_tab_admin handler only checks whether the user is in ADMIN_IDS, but the surrounding comments and buildHelpPages logic treat user.adminModeOn as a "user-mode (/on)" flag that should hide admin content; as a result, when an admin has toggled user-mode on, tapping the "Admin Help" button still routes through help_tab_admin and calls sendHelpMenu(ctx, user, 6), which silently falls back to the non-admin help page and makes the "Admin Help" button behave inconsistently with its label and comment. Adding a user.adminModeOn check to the guard makes this handler correctly block admin help while in user-mode, matching the rest of the admin-mode logic. [logic error]

Severity Level: Major ⚠️
- ⚠️ Admin Help button shows generic user help when user-mode.
- ⚠️ User-mode toggle semantics inconsistent for admin help navigation.
Suggested change
if (!ADMIN_IDS.includes(Number(user.id))) { await ctx.answerCbQuery('Admin only.'); return; }
if (!ADMIN_IDS.includes(Number(user.id)) || user.adminModeOn) {
await ctx.answerCbQuery('Admin only.');
return;
}
Steps of Reproduction ✅
1. Start the bot and log in as an admin whose Telegram ID is in `ADMIN_IDS` (checked in
`isAdmin(ctx)` and `requireAdmin(ctx)` in `index.js` around lines 695–706).

2. Open the Admin Panel from the main menu so that a message containing the `Admin Help`
button (`callback_data: 'help_tab_admin'`) is sent; this button is created in
`menu_admin_tab` at `index.js:4581–4592`.

3. In the same DM, run the `/on` command (`bot.command('on', ...)` at
`index.js:3212–3216`), which sets `user.adminModeOn = true` for the current admin user.

4. Tap the existing `Admin Help` inline button, which triggers
`bot.action('help_tab_admin', ...)` at `index.js:4218–4223`; because the current guard
only checks `ADMIN_IDS` and not `user.adminModeOn`, it calls `sendHelpMenu(ctx, user, 6)`,
but `buildHelpPages(user)` (around `index.js:2335+`) computes `adminUser =
ADMIN_IDS.includes(user.id) && !user.adminModeOn`, so with `adminModeOn === true` there is
no page 6 and `sendHelpMenu` silently clamps to the user help page (page 5). The button
labeled "Admin Help" thus shows the non-admin help page instead of blocking access while
in user-mode.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** index.js
**Line:** 4221:4221
**Comment:**
	*Logic Error: The `help_tab_admin` handler only checks whether the user is in `ADMIN_IDS`, but the surrounding comments and `buildHelpPages` logic treat `user.adminModeOn` as a "user-mode (/on)" flag that should hide admin content; as a result, when an admin has toggled user-mode on, tapping the "Admin Help" button still routes through `help_tab_admin` and calls `sendHelpMenu(ctx, user, 6)`, which silently falls back to the non-admin help page and makes the "Admin Help" button behave inconsistently with its label and comment. Adding a `user.adminModeOn` check to the guard makes this handler correctly block admin help while in user-mode, matching the rest of the admin-mode logic.

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.
👍 | 👎

Comment thread index.js Outdated
const user = getUser(ctx);
// Block if not admin, or if admin is in user-mode (/on)
if (!ADMIN_IDS.includes(Number(user.id)) || user.adminModeOn) { await ctx.answerCbQuery('Admin only.'); return; }
if (!ADMIN_IDS.includes(Number(user.id))) { await ctx.answerCbQuery('Admin only.'); return; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The menu_admin_tab callback currently blocks only non-admin users, but the comment and mode-status text treat user.adminModeOn as a "user-mode (/on)" flag that should also suppress admin controls; without checking user.adminModeOn, an admin who has turned user-mode on (via /on or the Mode Toggle buttons) can still open the full Admin Panel from any stale "Admin Panel" button, undermining the purpose of user-mode as a safe, user-view-only mode. Including user.adminModeOn in the guard ensures that when user-mode is active, the Admin Panel cannot be opened until the admin turns it off again. [logic error]

Severity Level: Major ⚠️
- ⚠️ User-mode still allows opening full Admin Panel.
- ⚠️ Admins may mistakenly think admin controls are disabled.
Suggested change
if (!ADMIN_IDS.includes(Number(user.id))) { await ctx.answerCbQuery('Admin only.'); return; }
if (!ADMIN_IDS.includes(Number(user.id)) || user.adminModeOn) {
await ctx.answerCbQuery('Admin only.');
return;
}
Steps of Reproduction ✅
1. Start the bot and log in as an admin whose ID is in `ADMIN_IDS`, then open the main
menu page 2; `mainMenuKeyboard` at `index.js:880–899` adds a `🔧 Admin Panel` button with
`callback_data: 'menu_admin_tab'` for admins.

2. Tap `🔧 Admin Panel` to trigger `bot.action('menu_admin_tab', ...)` at
`index.js:4581–4592`, confirming that the Admin Panel opens with admin controls and shows
the mode status line.

3. In the same DM, run the `/on` command defined at `index.js:3212–3216`, which sets
`user.adminModeOn = true` for this admin, putting them into "user mode" according to the
mode status string in `menu_admin_tab` and the logic in `buildHelpPages` and
`userMainMenuKeyboard` (which hide admin UI when `adminModeOn` is true).

4. Tap the existing `🔧 Admin Panel` button again; because `menu_admin_tab` currently only
checks `ADMIN_IDS` and does not consider `user.adminModeOn`, the handler still opens the
full Admin Panel (including `Admin Dashboard`, `Admin Help`, and other admin actions)
while `user.adminModeOn === true`, contradicting the user-mode design used elsewhere in
`index.js`.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** index.js
**Line:** 4584:4584
**Comment:**
	*Logic Error: The `menu_admin_tab` callback currently blocks only non-admin users, but the comment and mode-status text treat `user.adminModeOn` as a "user-mode (/on)" flag that should also suppress admin controls; without checking `user.adminModeOn`, an admin who has turned user-mode on (via `/on` or the Mode Toggle buttons) can still open the full Admin Panel from any stale "Admin Panel" button, undermining the purpose of user-mode as a safe, user-view-only mode. Including `user.adminModeOn` in the guard ensures that when user-mode is active, the Admin Panel cannot be opened until the admin turns it off again.

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

codeant-ai Bot commented Feb 24, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
index.js (1)

4453-4467: ⚠️ Potential issue | 🟡 Minor

Mode-toggle actions should refresh the persistent admin menu immediately.

These handlers change state and reply, but they don’t re-render the persistent admin menu header, so ON/OFF status can remain stale until another navigation action.

🔧 Proposed fix
 bot.action('admin_cmd_mode_on', async (ctx) => {
   if (!requireAdmin(ctx)) return;
   await ctx.answerCbQuery('Admin mode enabled');
   const user = getUser(ctx);
   user.adminModeOn = true;
   await ctx.reply('🔧 Admin Mode Enabled');
+  await sendPersistentAdminMenu(ctx, user);
 });

 bot.action('admin_cmd_mode_off', async (ctx) => {
   if (!requireAdmin(ctx)) return;
   await ctx.answerCbQuery('Admin mode disabled');
   const user = getUser(ctx);
   user.adminModeOn = false;
   await ctx.reply('👤 Admin Mode Disabled');
+  await sendPersistentAdminMenu(ctx, user);
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@index.js` around lines 4453 - 4467, The admin toggle handlers
('admin_cmd_mode_on' and 'admin_cmd_mode_off') update user.adminModeOn but do
not refresh the persistent admin menu header, leaving the displayed ON/OFF
stale; after setting user.adminModeOn (and after await ctx.answerCbQuery /
ctx.reply) call the function that re-renders the persistent admin admin
menu/header (e.g., renderPersistentAdminMenu(ctx, user) or
updateAdminMenuHeader(ctx, user)) so the UI reflects the new state
immediately—if no such helper exists, extract the menu/header rendering logic
into a function and invoke it from both handlers right after updating
getUser(ctx).adminModeOn.
🧹 Nitpick comments (1)
index.js (1)

4221-4221: Inline comments are now out of sync with the guard logic.

Both comments mention blocking admins in user-mode, but the conditions only check admin identity. Please update comment text to match runtime behavior.

Also applies to: 4584-4584

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@index.js` at line 4221, The inline comment near the guard that checks
ADMIN_IDS and user.id is misleading (it says it blocks admins in user-mode but
the runtime only checks admin identity); update the comment text adjacent to the
guard using ADMIN_IDS and user.id (and the similar guard around the other
occurrence) so it accurately describes that the code is denying access to
non-admin users or that it only checks admin identity rather than blocking
admins in user-mode; ensure both places (the guard that calls
ctx.answerCbQuery('Admin only.') and the other similar check) have matching,
correct comments describing the actual behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@index.js`:
- Around line 1912-1913: The /on and /off commands and their copy are
inconsistent with the admin-view gating: the commands set/announce adminModeOn =
true but visibility checks use !user.adminModeOn, so enabling behaves like
user-mode; fix by making the semantics consistent—either flip the command
behavior or (preferred) flip the predicates and copy so adminModeOn === true
means admin view is shown: update the command descriptors ("Enable admin mode
view"/"Disable admin mode view") and the announcement text where /on and /off
are handled to match that meaning, and replace occurrences of the inverted
checks (instances of !user.adminModeOn) with user.adminModeOn across the
codebase (search for the symbol adminModeOn and all places using
!user.adminModeOn) so gating, UI, and messages are aligned.

---

Outside diff comments:
In `@index.js`:
- Around line 4453-4467: The admin toggle handlers ('admin_cmd_mode_on' and
'admin_cmd_mode_off') update user.adminModeOn but do not refresh the persistent
admin menu header, leaving the displayed ON/OFF stale; after setting
user.adminModeOn (and after await ctx.answerCbQuery / ctx.reply) call the
function that re-renders the persistent admin admin menu/header (e.g.,
renderPersistentAdminMenu(ctx, user) or updateAdminMenuHeader(ctx, user)) so the
UI reflects the new state immediately—if no such helper exists, extract the
menu/header rendering logic into a function and invoke it from both handlers
right after updating getUser(ctx).adminModeOn.

---

Nitpick comments:
In `@index.js`:
- Line 4221: The inline comment near the guard that checks ADMIN_IDS and user.id
is misleading (it says it blocks admins in user-mode but the runtime only checks
admin identity); update the comment text adjacent to the guard using ADMIN_IDS
and user.id (and the similar guard around the other occurrence) so it accurately
describes that the code is denying access to non-admin users or that it only
checks admin identity rather than blocking admins in user-mode; ensure both
places (the guard that calls ctx.answerCbQuery('Admin only.') and the other
similar check) have matching, correct comments describing the actual behavior.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a308d5f and cc2b416.

📒 Files selected for processing (2)
  • .gitignore
  • index.js

Comment thread index.js
@gamblecodezcom
gamblecodezcom merged commit a57f2ca into main Feb 24, 2026
3 of 5 checks passed
@gamblecodezcom
gamblecodezcom deleted the codex/configure-git-and-update-project-files branch February 24, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex size:S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant