Refactor config.py with default values and cleanup#122
Conversation
Updated configuration variables and added default values for API credentials, chat settings, and other options.
📝 WalkthroughWalkthrough
ChangesConfig Rewrite and Help Text Update
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 Warning |
There was a problem hiding this comment.
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
| 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") | ||
|
|
There was a problem hiding this comment.
🔒 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
| REPLY_MESSAGE = os.environ.get("REPLY_MESSAGE", False) | ||
| EDIT_TITLE = os.environ.get("EDIT_TITLE", True) |
There was a problem hiding this comment.
🎯 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 = FalseAlso 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.
| 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 |
There was a problem hiding this comment.
🩺 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.
| 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.
| 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 |
There was a problem hiding this comment.
🎯 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.
| 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.
Updated configuration variables and added default values for API credentials, chat settings, and other options.
Summary by CodeRabbit