Skip to content

Refactor config.py with default values and cleanup#122

Open
AMMUKASH wants to merge 1 commit into
subinps:mainfrom
AMMUKASH:patch-3
Open

Refactor config.py with default values and cleanup#122
AMMUKASH wants to merge 1 commit into
subinps:mainfrom
AMMUKASH:patch-3

Conversation

@AMMUKASH

@AMMUKASH AMMUKASH commented Jun 24, 2026

Copy link
Copy Markdown

Updated configuration variables and added default values for API credentials, chat settings, and other options.

Summary by CodeRabbit

  • New Features
    • Added built-in default settings for core app connection details, database access, chat/log channels, and runtime port so the app can start more easily with less manual setup.
    • Improved startup configuration for non-Heroku deployments, with hosting defaults now aligned for Render-style environments.
    • Kept support for quality and playback-related options such as title editing, reply behavior, bitrate, FPS, and custom quality selection.

Updated configuration variables and added default values for API credentials, chat settings, and other options.
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

config.py removes the heroku3 import and all Heroku API/app lookup logic from the Config class. Several previously empty or None defaults are replaced with hardcoded values for Telegram API credentials, MongoDB URI, chat/log IDs, and port. Optional config initialization and quality/bitrate parsing are retained with minor adjustments. All help-text string constants are updated.

Changes

Config Rewrite and Help Text Update

Layer / File(s) Summary
Heroku removal and Config core defaults
config.py
Removes heroku3 import; replaces the Telegram API and infrastructure configuration block with hardcoded defaults for API_ID, API_HASH, BOT_TOKEN, SESSION, CHAT, LOG_GROUP, DATABASE_URI, and PORT; sets HEROKU_APP to None and removes HEROKU_API_KEY, HEROKU_APP_NAME, and heroku3 app lookup.
Optional config initialization and quality/bitrate parsing
config.py
Updates optional feature toggle defaults and player-core state initialization; adjusts LOG_GROUP normalization; retains EDIT_TITLE disabling, REPLY_PM enabling, and BITRATE/FPS/CUSTOM_QUALITY clamping and threshold-mapping logic.
Help text string updates
config.py
Replaces PLAY_HELP, SETTINGS_HELP, SCHEDULER_HELP, RECORDER_HELP, CONTROL_HELP, ADMIN_HELP, MISC_HELP, and ENV_HELP multiline string constants with updated content.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop hop, away goes Heroku's chain,
No more API keys to maintain!
A default token here, a URI there,
The config is lighter, beyond compare.
With help strings refreshed and Render in sight,
This bunny declares: the defaults feel right! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the config.py refactor and the addition of default values with cleanup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Warning

⚠️ This pull request has been flagged as potential spam (promotional) by CodeRabbit slop detection and should be reviewed carefully.

@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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@config.py`:
- Around line 54-55: The environment flag handling in config.py treats
REPLY_MESSAGE as a raw string, so values like "False" remain truthy and
incorrectly enable REPLY_PM in the later truthiness check. Update the
REPLY_MESSAGE and related boolean config parsing so os.environ values are
converted to real booleans before they are used, and make the REPLY_PM
assignment logic in the section around the REPLY_PM check rely on that parsed
boolean rather than raw string truthiness. Use the REPLY_MESSAGE and REPLY_PM
symbols to locate the affected initialization and conditional logic.
- Around line 31-35: The config constants in config.py are embedding production
credentials as fallback defaults, so remove the hardcoded secret values from
API_ID, API_HASH, BOT_TOKEN, and SESSION and replace them with non-sensitive
defaults such as empty values or None. Update the config initialization flow to
validate required environment variables at startup and fail fast with a clear
error if any are missing, so runtime clients never silently pick up embedded
secrets.
- Around line 157-165: The bitrate mapping in the CUSTOM_QUALITY handling is
excluding the upper bound, so QUALITY=100 falls into the low-bitrate fallback.
Update the conditional logic in the quality-to-BITRATE block to treat 100 as the
highest tier, and verify the thresholds in the CUSTOM_QUALITY branch around the
existing BITRATE assignments so the top range maps to 48000 when E_BITRATE is
not set.
- Around line 139-146: The FPS parsing in config.py can crash initialization
because FPS is read after the int conversion fails but before it is safely
assigned. Update the E_FPS handling block so that when int(E_FPS) raises, FPS is
given a valid fallback value before the later `if not FPS >= 30` check runs, and
keep the logic localized around the `E_FPS`/`FPS` initialization path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc422dc3-8f51-4dc1-937a-7d06b26bdc1c

📥 Commits

Reviewing files that changed from the base of the PR and between d084c78 and 670ce15.

📒 Files selected for processing (1)
  • config.py

Comment thread config.py
Comment on lines +31 to +35
API_ID = int(os.environ.get("API_ID", '38138069'))
API_HASH = os.environ.get("API_HASH", "2ed313ebcc45cbcf65d1fc736ec71681")
BOT_TOKEN = os.environ.get("BOT_TOKEN", "8970725347:AAFYEfmwyK54z7ipcUB-Yb2ET-4VJSo3Np8")
SESSION = os.environ.get("SESSION_STRING", "AQJF8NUAX8lJdoAM_A_O5C6pUrAxevv2PqwBOKpt9IhpfWFKknA2aBZoxvxil5bEX-vlK8JZPGNxmsqFPGv7RY2SQd1OC2XvAGXsYmJVaCeTONHL3tYbaJ-o_d73jUz0K61BKo2XbiXKo8rv_LMmTWUtEA7EQGmdvmTf-VrtpYhIJ1I-PXMcryarCSgExZKrw-PJVP-krIDBmBox024RXzWVxj0ocvrMXLgmvZZ5cP-ZSMinBMWrWCWGOQZ7wmK7DA-ltHDJ2PwgWKp7L3vunmDQ7LiV-59n3ShZmBLvbZuD6PSbIfcVhBB1jcUV24OL16JRpu4gPq0q6WroSiRSWo6RP6IvzgAAAAH_hA2LAA")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🔴 Critical | ⚡ Quick win

Remove hardcoded production secrets from config defaults.

Line 32, Line 33, Line 34, and Line 44 embed credential-like values. If env vars are missing, these become live runtime secrets in bot/database clients.

🔧 Proposed fix
-    API_ID = int(os.environ.get("API_ID", '38138069'))
-    API_HASH = os.environ.get("API_HASH", "2ed313ebcc45cbcf65d1fc736ec71681")
-    BOT_TOKEN = os.environ.get("BOT_TOKEN", "8970725347:AAFYEfmwyK54z7ipcUB-Yb2ET-4VJSo3Np8")     
-    SESSION = os.environ.get("SESSION_STRING", "AQJF8N...")
+    API_ID = int(os.environ["API_ID"])
+    API_HASH = os.environ["API_HASH"]
+    BOT_TOKEN = os.environ["BOT_TOKEN"]
+    SESSION = os.environ["SESSION_STRING"]

-    DATABASE_URI = os.environ.get("DATABASE_URI", "mongodb+srv://misssqn_db_user:Nova01@cluster0.6xxsrwq.mongodb.net/?retryWrites=true&w=majority")
+    DATABASE_URI = os.environ["DATABASE_URI"]

Also applies to: 44-45

🧰 Tools
🪛 Betterleaks (1.5.0)

[high] 32-32: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config.py` around lines 31 - 35, The config constants in config.py are
embedding production credentials as fallback defaults, so remove the hardcoded
secret values from API_ID, API_HASH, BOT_TOKEN, and SESSION and replace them
with non-sensitive defaults such as empty values or None. Update the config
initialization flow to validate required environment variables at startup and
fail fast with a clear error if any are missing, so runtime clients never
silently pick up embedded secrets.

Source: Linters/SAST tools

Comment thread config.py
Comment on lines +54 to 55
REPLY_MESSAGE = os.environ.get("REPLY_MESSAGE", False)
EDIT_TITLE = os.environ.get("EDIT_TITLE", True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

REPLY_MESSAGE="False" currently enables PM replies.

Line 54 reads a raw string, and Line 119 checks truthiness, so non-empty "False" still evaluates True and sets REPLY_PM = True.

🔧 Proposed fix
-    REPLY_MESSAGE = os.environ.get("REPLY_MESSAGE", False)
+    REPLY_MESSAGE = os.environ.get("REPLY_MESSAGE", "")

-    if REPLY_MESSAGE:
-        REPLY_MESSAGE = REPLY_MESSAGE
+    if REPLY_MESSAGE and str(REPLY_MESSAGE).strip().lower() not in {"false", "no", "0"}:
         REPLY_PM = True
         LOGGER.info("Reply Message Found, Enabled PM MSG")
     else:
         REPLY_MESSAGE = False
         REPLY_PM = False

Also applies to: 119-125

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config.py` around lines 54 - 55, The environment flag handling in config.py
treats REPLY_MESSAGE as a raw string, so values like "False" remain truthy and
incorrectly enable REPLY_PM in the later truthiness check. Update the
REPLY_MESSAGE and related boolean config parsing so os.environ values are
converted to real booleans before they are used, and make the REPLY_PM
assignment logic in the section around the REPLY_PM check rely on that parsed
boolean rather than raw string truthiness. Use the REPLY_MESSAGE and REPLY_PM
symbols to locate the affected initialization and conditional logic.

Comment thread config.py
Comment on lines 139 to +146
if E_FPS:
try:
FPS=int(E_FPS)
FPS = int(E_FPS)
except:
LOGGER.error("Invalid FPS specified")
E_FPS=False
E_FPS = False
if not FPS >= 30:
FPS=30
FPS = 30

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Invalid FPS input can crash initialization.

If FPS env is non-numeric, Line 142 enters except, but FPS is never assigned before Line 145 reads it (UnboundLocalError).

🔧 Proposed fix
     if E_FPS:
        try:
           FPS = int(E_FPS)
-       except:
+       except (TypeError, ValueError):
           LOGGER.error("Invalid FPS specified")
           E_FPS = False
+          FPS = 30
        if not FPS >= 30:
           FPS = 30
📝 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.

Suggested change
if E_FPS:
try:
FPS=int(E_FPS)
FPS = int(E_FPS)
except:
LOGGER.error("Invalid FPS specified")
E_FPS=False
E_FPS = False
if not FPS >= 30:
FPS=30
FPS = 30
if E_FPS:
try:
FPS = int(E_FPS)
except (TypeError, ValueError):
LOGGER.error("Invalid FPS specified")
E_FPS = False
FPS = 30
if not FPS >= 30:
FPS = 30
🧰 Tools
🪛 Ruff (0.15.18)

[error] 142-142: Do not use bare except

(E722)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config.py` around lines 139 - 146, The FPS parsing in config.py can crash
initialization because FPS is read after the int conversion fails but before it
is safely assigned. Update the E_FPS handling block so that when int(E_FPS)
raises, FPS is given a valid fallback value before the later `if not FPS >= 30`
check runs, and keep the logic localized around the `E_FPS`/`FPS` initialization
path.

Comment thread config.py
Comment on lines +157 to +165
if 66.9 < CUSTOM_QUALITY < 100:
if not E_BITRATE:
BITRATE=48000
BITRATE = 48000
elif 50 < CUSTOM_QUALITY < 66.9:
if not E_BITRATE:
BITRATE=36000
BITRATE = 36000
else:
if not E_BITRATE:
BITRATE=24000
BITRATE = 24000

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

QUALITY=100 is mapped to low bitrate due to boundary logic.

Line 157 uses < 100, so CUSTOM_QUALITY == 100 falls through to Line 165 and sets BITRATE = 24000.

🔧 Proposed fix
-       if 66.9 < CUSTOM_QUALITY < 100:
+       if 66.9 <= CUSTOM_QUALITY <= 100:
           if not E_BITRATE:
              BITRATE = 48000
-       elif 50 < CUSTOM_QUALITY < 66.9:
+       elif 50 < CUSTOM_QUALITY < 66.9:
           if not E_BITRATE:
              BITRATE = 36000
📝 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.

Suggested change
if 66.9 < CUSTOM_QUALITY < 100:
if not E_BITRATE:
BITRATE=48000
BITRATE = 48000
elif 50 < CUSTOM_QUALITY < 66.9:
if not E_BITRATE:
BITRATE=36000
BITRATE = 36000
else:
if not E_BITRATE:
BITRATE=24000
BITRATE = 24000
if 66.9 <= CUSTOM_QUALITY <= 100:
if not E_BITRATE:
BITRATE = 48000
elif 50 < CUSTOM_QUALITY < 66.9:
if not E_BITRATE:
BITRATE = 36000
else:
if not E_BITRATE:
BITRATE = 24000
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config.py` around lines 157 - 165, The bitrate mapping in the CUSTOM_QUALITY
handling is excluding the upper bound, so QUALITY=100 falls into the low-bitrate
fallback. Update the conditional logic in the quality-to-BITRATE block to treat
100 as the highest tier, and verify the thresholds in the CUSTOM_QUALITY branch
around the existing BITRATE assignments so the top range maps to 48000 when
E_BITRATE is not set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant