fix: resolve critical bugs from telepot→python-telegram-bot migration#12
Merged
Conversation
…) and replace RegexHandler
…ent substring collisions
Owner
Author
⛔ Snyk checks have failed. 15 issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Pull request overview
Fixes nine bugs from the prior telepot → python-telegram-bot migration: fixes the requirement, ports all handlers to v13's (update, context) API, hardens parsing (ALLOWED_IDS whitespace, container name rsplit, anchored docker name filter), validates API_KEY at startup, guards error_handler against non-message updates, dynamically resolves the source path for /start, and updates the Dockerfile for ubuntu:24.10.
Changes:
requirements.txt: replace unusedtelepotwithpython-telegram-bot==13.15.dockerbot.py: full v13 API rewrite — per-command functions, authorization helper, error handler, container parsing viaendswith/rsplitand anchored name filter, dynamic/starthelp generation.Dockerfile: consolidated apt install (addspython3/python3-pip),WORKDIR,PYTHONUNBUFFERED/PYTHONDONTWRITEBYTECODE, switchesENTRYPOINTtoCMD ["python3", ...].
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| requirements.txt | Switches to the actual telegram lib used by code. |
| Dockerfile | Restructured base image setup; adds python3, env vars, new speedtest.py path. |
| dockerbot.py | Migrates to python-telegram-bot v13 handler signatures and fixes parsing/auth bugs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+39
to
+48
| number = command.rfind("def ") | ||
| if number != -1: | ||
| command = command[number+4:] | ||
| space_pos = command.find("(") | ||
| if space_pos != -1: | ||
| command_name = command[:space_pos] | ||
| help_text = getCommandHelp(line) | ||
| if help_text: | ||
| command = f"/{command_name} {help_text}\n" | ||
| list_of_results.append(command) |
Comment on lines
+26
to
+27
| RUN pip3 install --no-cache-dir --upgrade pip && \ | ||
| pip3 install --no-cache-dir -r requirements.txt |
| pip3 install --no-cache-dir -r requirements.txt | ||
|
|
||
| # Install speedtest-cli script | ||
| RUN wget https://raw.githubusercontent.com/sivel/speedtest-cli/v2.1.3/speedtest.py -O /usr/local/lib/python3.12/site-packages/speedtest.py |
| dp.add_handler(CommandHandler("stat", stat_command)) | ||
| dp.add_handler(CommandHandler("list_containers", list_containers_command)) | ||
|
|
||
| dp.add_handler(MessageHandler(Filters.regex(r"^/[a-zA-Z0-9_-]+_(restart|stop|start)$"), container_command)) |
| import sys | ||
| import docker | ||
| from telepot.loop import MessageLoop | ||
| import telegram |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This branch fixes 9 bugs identified during a code review of the
telepot → python-telegram-bot rewrite.
Changes
requirements.txt — replaced
telepot(wrong library, never imported) withpython-telegram-bot==13.15(the library the code actually uses)v13 API migration — all handler callbacks updated from the removed v12
(bot, update)signature to the v13(update, context)signature;RegexHandler(removed in v13) replaced withMessageHandler(Filters.regex(...)); all bot calls updated tocontext.bot.send_*ALLOWED_IDS whitespace — each entry is now
.strip()-ed so values like"123456, 789012"(space after comma, common in docker-compose) are parsedcorrectly
API_KEY validation — bot exits with a clear message at startup if
API_KEYis not set, instead of passingNonetoUpdaterand crashingwith an opaque library error
Container name parsing — replaced
split('_')[0]withrspliton theoperation suffix; switched operation detection from
intoendswithsocontainer names containing underscores (e.g.
my_app) resolve correctlyDocker name filter — filter changed from
{'name': container_name}(asubstring match) to
{'name': '^/container_name$'}(anchored exact match)to prevent operating on the wrong container
error_handler crash — added
update.messageNone guard; non-messageupdates (callback queries, inline queries, channel posts) previously caused
original error
Hardcoded source path —
/startnow readsos.path.abspath(__file__)instead of the hardcoded
/opt/dockerbot/dockerbot.py; only functions witha
#[ ... ]#help marker are listed, hiding internal helpers from usersDockerfile — added
python3andpython3-pipto theapt installstep(ubuntu:24.10 ships neither by default); changed
CMDfrompythontopython3Test plan
docker buildcompletes without errorAPI_KEYAPI_KEYis unset/startshows only user-facing commands (no internal helpers)/list_containerslists containers; clicking a generated commandrestarts/stops/starts the correct container, including containers whose
names contain underscores
image;
ALLOWED_IDSwith spaces after commas works correctly