5
5
6
6
from slugify import slugify
7
7
from telegram import Bot , Message , Update
8
+ from telegram .ext import CallbackContext
8
9
import telegram
9
10
10
11
from picobot import responses
@@ -45,12 +46,13 @@ def build_pack_name(title: str, bot: Bot) -> str:
45
46
return f'{ slug } _by_{ bot .username } '
46
47
47
48
48
- def start (bot , update ):
49
+ def start (update : Update , context : CallbackContext ):
49
50
"""Send a message when the command /start is issued."""
50
51
update .message .reply_text (responses .GREETING )
51
52
52
53
53
- def create_pack (bot : Bot , update : Update ):
54
+ def create_pack (update : Update , context : CallbackContext ):
55
+ bot = context .bot
54
56
user = update .message .from_user
55
57
56
58
if not check_msg_format (update .message .text ):
@@ -82,7 +84,8 @@ def create_pack(bot: Bot, update: Update):
82
84
png_sticker .close ()
83
85
84
86
85
- def add_sticker (bot : Bot , update : Update ):
87
+ def add_sticker (update : Update , context : CallbackContext ):
88
+ bot = context .bot
86
89
msg = update .message
87
90
88
91
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):
188
191
return True
189
192
190
193
191
- def caption_handler (bot : Bot , update : Update ):
194
+ def caption_handler (update : Update , context : CallbackContext ):
192
195
text = update .message .caption
193
196
if text is None or text == '' :
194
197
return
195
198
if text .split ()[0 ] == '/addsticker' :
196
199
update .message .text = text
197
- add_sticker (bot , update )
200
+ add_sticker (context . bot , update )
198
201
199
202
200
203
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,
279
282
return True
280
283
281
284
282
- def del_sticker (bot : Bot , update : Update ):
285
+ def del_sticker (update : Update , context : CallbackContext ):
286
+ bot = context .bot
283
287
msg : Message = update .message
284
288
msg_type = get_msg_type (msg )
285
289
user_id = msg .from_user .id
@@ -311,7 +315,8 @@ def del_sticker(bot: Bot, update: Update):
311
315
msg .reply_text (responses .REMOVE_STICKER_HELP )
312
316
313
317
314
- def set_default_pack (bot : Bot , update : Update ):
318
+ def set_default_pack (update : Update , context : CallbackContext ):
319
+ bot = context .bot
315
320
msg : Message = update .message
316
321
user_id = msg .from_user .id
317
322
@@ -330,22 +335,22 @@ def set_default_pack(bot: Bot, update: Update):
330
335
update .message .reply_text (responses .INVALID_MSG )
331
336
332
337
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 )
335
340
336
341
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 )
339
344
340
345
341
- def _set_pack_public (bot : Bot , update : Update , is_public : bool ):
346
+ def _set_pack_public (update : Update , context : CallbackContext , is_public : bool ):
342
347
msg : Message = update .message
343
348
user_id = msg .from_user .id
344
349
345
350
if check_msg_format (msg .text ):
346
351
splittext = shlex .split (msg .text )
347
352
title = splittext [1 ]
348
- pack_name = build_pack_name (title , bot )
353
+ pack_name = build_pack_name (title , context . bot )
349
354
350
355
# check if user is pack's owner
351
356
if repository ().check_permission (user_id , pack_name ):
@@ -359,7 +364,7 @@ def _set_pack_public(bot: Bot, update: Update, is_public: bool):
359
364
360
365
361
366
@creator_only
362
- def add_pack_to_user (bot : Bot , update : Update ):
367
+ def add_pack_to_user (update : Update , context : CallbackContext ):
363
368
msg : Message = update .message
364
369
try :
365
370
user = msg .reply_to_message .forward_from
@@ -369,7 +374,7 @@ def add_pack_to_user(bot: Bot, update: Update):
369
374
if check_msg_format (msg .text ):
370
375
splittext = shlex .split (msg .text )
371
376
title = splittext [1 ]
372
- pack_name = build_pack_name (title , bot )
377
+ pack_name = build_pack_name (title , context . bot )
373
378
374
379
repository ().add_pack_to_user (user , pack_name )
375
380
else :
@@ -403,11 +408,11 @@ def get_msg_type(message: Message):
403
408
return msg_type
404
409
405
410
406
- def handler_help (bot , update ):
411
+ def handler_help (update : Update , context : CallbackContext ):
407
412
"""Send a message when the command /help is issued."""
408
413
update .message .reply_text (responses .HELP_MSG )
409
414
410
415
411
- def error (bot , update , error ):
416
+ def error (update : Update , context : CallbackContext ):
412
417
"""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