Skip to content

Commit 779c2e3

Browse files
committed
Update python-telegram-bot API to 13.11, pin typed-ast version
Previous typed-ast version fails to build in newer versions of Python (3.10+) with "unknown type PyArena". For more details, see: python/typed_ast#159.
1 parent 900c5ab commit 779c2e3

File tree

3 files changed

+245
-165
lines changed

3 files changed

+245
-165
lines changed

picobot/handlers.py

+23-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from slugify import slugify
77
from telegram import Bot, Message, Update
8+
from telegram.ext import CallbackContext
89
import telegram
910

1011
from picobot import responses
@@ -45,12 +46,13 @@ def build_pack_name(title: str, bot: Bot) -> str:
4546
return f'{slug}_by_{bot.username}'
4647

4748

48-
def start(bot, update):
49+
def start(update: Update, context: CallbackContext):
4950
"""Send a message when the command /start is issued."""
5051
update.message.reply_text(responses.GREETING)
5152

5253

53-
def create_pack(bot: Bot, update: Update):
54+
def create_pack(update: Update, context: CallbackContext):
55+
bot = context.bot
5456
user = update.message.from_user
5557

5658
if not check_msg_format(update.message.text):
@@ -82,7 +84,8 @@ def create_pack(bot: Bot, update: Update):
8284
png_sticker.close()
8385

8486

85-
def add_sticker(bot: Bot, update: Update):
87+
def add_sticker(update: Update, context: CallbackContext):
88+
bot = context.bot
8689
msg = update.message
8790

8891
msg_type = get_msg_type(msg)
@@ -188,13 +191,13 @@ def add_text(bot: Bot, msg: Message, user_id: int, pack_name: str, emoji: str):
188191
return True
189192

190193

191-
def caption_handler(bot: Bot, update: Update):
194+
def caption_handler(update: Update, context: CallbackContext):
192195
text = update.message.caption
193196
if text is None or text == '':
194197
return
195198
if text.split()[0] == '/addsticker':
196199
update.message.text = text
197-
add_sticker(bot, update)
200+
add_sticker(context.bot, update)
198201

199202

200203
def add_photo(bot: Bot, msg: Message, user_id: int, pack_name: str, emoji: str, replied: bool):
@@ -279,7 +282,8 @@ def insert_sticker_in_pack(bot: Bot, msg: Message, user_id: int, pack_name: str,
279282
return True
280283

281284

282-
def del_sticker(bot: Bot, update: Update):
285+
def del_sticker(update: Update, context: CallbackContext):
286+
bot = context.bot
283287
msg: Message = update.message
284288
msg_type = get_msg_type(msg)
285289
user_id = msg.from_user.id
@@ -311,7 +315,8 @@ def del_sticker(bot: Bot, update: Update):
311315
msg.reply_text(responses.REMOVE_STICKER_HELP)
312316

313317

314-
def set_default_pack(bot: Bot, update: Update):
318+
def set_default_pack(update: Update, context: CallbackContext):
319+
bot = context.bot
315320
msg: Message = update.message
316321
user_id = msg.from_user.id
317322

@@ -330,22 +335,22 @@ def set_default_pack(bot: Bot, update: Update):
330335
update.message.reply_text(responses.INVALID_MSG)
331336

332337

333-
def handler_pack_public(bot: Bot, update: Update):
334-
_set_pack_public(bot, update, True)
338+
def handler_pack_public(update: Update, context: CallbackContext):
339+
_set_pack_public(update, context, True)
335340

336341

337-
def handler_pack_private(bot: Bot, update: Update):
338-
_set_pack_public(bot, update, False)
342+
def handler_pack_private(update: Update, context: CallbackContext):
343+
_set_pack_public(update, context, False)
339344

340345

341-
def _set_pack_public(bot: Bot, update: Update, is_public: bool):
346+
def _set_pack_public(update: Update, context: CallbackContext, is_public: bool):
342347
msg: Message = update.message
343348
user_id = msg.from_user.id
344349

345350
if check_msg_format(msg.text):
346351
splittext = shlex.split(msg.text)
347352
title = splittext[1]
348-
pack_name = build_pack_name(title, bot)
353+
pack_name = build_pack_name(title, context.bot)
349354

350355
# check if user is pack's owner
351356
if repository().check_permission(user_id, pack_name):
@@ -359,7 +364,7 @@ def _set_pack_public(bot: Bot, update: Update, is_public: bool):
359364

360365

361366
@creator_only
362-
def add_pack_to_user(bot: Bot, update: Update):
367+
def add_pack_to_user(update: Update, context: CallbackContext):
363368
msg: Message = update.message
364369
try:
365370
user = msg.reply_to_message.forward_from
@@ -369,7 +374,7 @@ def add_pack_to_user(bot: Bot, update: Update):
369374
if check_msg_format(msg.text):
370375
splittext = shlex.split(msg.text)
371376
title = splittext[1]
372-
pack_name = build_pack_name(title, bot)
377+
pack_name = build_pack_name(title, context.bot)
373378

374379
repository().add_pack_to_user(user, pack_name)
375380
else:
@@ -403,11 +408,11 @@ def get_msg_type(message: Message):
403408
return msg_type
404409

405410

406-
def handler_help(bot, update):
411+
def handler_help(update: Update, context: CallbackContext):
407412
"""Send a message when the command /help is issued."""
408413
update.message.reply_text(responses.HELP_MSG)
409414

410415

411-
def error(bot, update, error):
416+
def error(update: Update, context: CallbackContext):
412417
"""Log Errors caused by Updates."""
413-
logger.warning('Update "%s" caused error "%s"', update, error)
418+
logger.warning('Update "%s" caused error "%s"', update, context.error)

0 commit comments

Comments
 (0)