Skip to content

Commit 10b43d4

Browse files
committed
Update to PTB v20.2 and add debugging details for join requests
1 parent 9ac535e commit 10b43d4

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ repos:
2727
additional_dependencies:
2828
- beautifulsoup4~=4.11.0
2929
- thefuzz~=0.19.0
30-
- python-telegram-bot[job-queue]==20.0
30+
- python-telegram-bot[job-queue]==20.2
3131
- Sphinx~=5.0.2
3232
- httpx~=0.23.0
3333
- gql[aiohttp]~=3.3.0
@@ -39,7 +39,7 @@ repos:
3939
additional_dependencies:
4040
- beautifulsoup4~=4.11.0
4141
- thefuzz~=0.19.0
42-
- python-telegram-bot[job-queue]==20.0
42+
- python-telegram-bot[job-queue]==20.2
4343
- Sphinx~=5.0.2
4444
- httpx~=0.23.0
4545
- gql[aiohttp]~=3.3.0

components/joinrequests.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ async def decline_user(
7474
async def join_request_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
7575
join_request = cast(ChatJoinRequest, update.chat_join_request)
7676
user = join_request.from_user
77+
user_chat_id = join_request.user_chat_id
7778
chat_id = join_request.chat.id
7879
jobs = cast(JobQueue, context.job_queue).get_jobs_by_name(f"JOIN_TIMEOUT {chat_id} {user.id}")
7980
if jobs:
@@ -87,6 +88,8 @@ async def join_request_callback(update: Update, context: ContextTypes.DEFAULT_TY
8788
user_data.setdefault(int(chat_id), {}).setdefault("received join request", []).append(
8889
get_dtm_str()
8990
)
91+
user_data[int(chat_id)]["user_chat_id"] = user_chat_id
92+
user_data[int(chat_id)]["user_id"] = user.id
9093

9194
text = (
9295
f"Hi, {user.mention_html()}! I'm {context.bot.bot.mention_html()}, the "
@@ -104,7 +107,9 @@ async def join_request_callback(update: Update, context: ContextTypes.DEFAULT_TY
104107
)
105108
)
106109
try:
107-
message = await user.send_message(text=text, reply_markup=reply_markup)
110+
message = await context.bot.send_message(
111+
chat_id=user_chat_id, text=text, reply_markup=reply_markup
112+
)
108113
except Forbidden:
109114
# If the user blocked the bot, let's give the admins a chance to handle that
110115
# TG also notifies the user and forwards the message once the user unblocks the bot, but
@@ -155,9 +160,7 @@ async def join_request_buttons(update: Update, context: ContextTypes.DEFAULT_TYP
155160
if "User_already_participant" not in exc.message:
156161
raise exc
157162

158-
context.application.create_task(
159-
user.send_message("Nice! Have fun in the group 🙂"), update=update
160-
)
163+
await user.send_message("Nice! Have fun in the group 🙂")
161164
reply_markup = None
162165
else:
163166
user_data.setdefault(int(chat_id), {}).setdefault("pressed button 1", []).append(

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
beautifulsoup4~=4.11.0
44
thefuzz~=0.19.0
55
python-Levenshtein~=0.12.0
6-
python-telegram-bot[job-queue]==20.0
6+
python-telegram-bot[job-queue]==20.2
77
Sphinx~=5.0.2
88
httpx~=0.23.0
99
gql[aiohttp]~=3.3.0

0 commit comments

Comments
 (0)