@@ -102,9 +102,9 @@ def on_error(update, context):
102102
103103def catch_exceptions (func ):
104104 @wraps (func )
105- def wrapper (bot , update , * args , ** kwargs ):
105+ def wrapper (update , context , * args , ** kwargs ):
106106 try :
107- return func (bot , update , * args , ** kwargs )
107+ return func (update , context , * args , ** kwargs )
108108 except Exception as e :
109109 logger .error ('Exception in {}: {}' .format (func .__name__ , e ))
110110 traceback .print_exc ()
@@ -116,11 +116,11 @@ def wrapper(bot, update, *args, **kwargs):
116116def observe_metrics (command_name ):
117117 def decorator (func ):
118118 @wraps (func )
119- def wrapper (bot , update , * args , ** kwargs ):
119+ def wrapper (update , context , * args , ** kwargs ):
120120 metrics .telegram_commands_total .labels (command = command_name ).inc ()
121121 start_time = time .time ()
122122 try :
123- result = func (bot , update , * args , ** kwargs )
123+ result = func (update , context , * args , ** kwargs )
124124 duration = time .time () - start_time
125125 metrics .telegram_command_duration_seconds .labels (command = command_name ).observe (duration )
126126 return result
@@ -147,13 +147,13 @@ def wrapper(*args, db_session_maker, **kwargs):
147147
148148@catch_exceptions
149149@observe_metrics ('start' )
150- def start (bot , update ):
150+ def start (update , context ):
151151 update .message .reply_text ('Команда /new настроит новый канал. В канал будут пересылаться посты из группы ВК' )
152152
153153
154154@catch_exceptions
155155@observe_metrics ('new' )
156- def new (bot , update ):
156+ def new (update , context ):
157157 metrics .telegram_conversations_total .labels (type = 'new' , status = 'started' ).inc ()
158158
159159 update .message .reply_text ('Отправьте ссылку на группу ВК' )
@@ -162,7 +162,7 @@ def new(bot, update):
162162
163163
164164@catch_exceptions
165- def new_in_state_asked_vk_group_link (bot , update , users_state ):
165+ def new_in_state_asked_vk_group_link (update , context , users_state ):
166166 vk_url = update .message .text
167167 vk_domain = vk_url .split ('/' )[- 1 ]
168168 users_state [update .message .from_user .id ] = dict ()
@@ -178,15 +178,15 @@ def new_in_state_asked_vk_group_link(bot, update, users_state):
178178
179179
180180@catch_exceptions
181- def new_in_state_asked_channel_access (bot , update ):
181+ def new_in_state_asked_channel_access (update , context ):
182182 update .message .reply_text ('Хорошо. Перешлите любое сообщение из канала' , reply_markup = ReplyKeyboardRemove ())
183183
184184 return ASKED_CHANNEL_MESSAGE_IN_NEW
185185
186186
187187@catch_exceptions
188188@make_db_session
189- def new_in_state_asked_channel_message (bot , update , db , users_state ):
189+ def new_in_state_asked_channel_message (update , context , db , users_state ):
190190 user_id = update .message .from_user .id
191191 username = update .message .from_user .username
192192 channel_id = str (update .message .forward_from_chat .id )
@@ -208,7 +208,7 @@ def new_in_state_asked_channel_message(bot, update, db, users_state):
208208 logger .warning ('Cannot delete disabled channel of {}' .format (channel_id ))
209209 traceback .print_exc ()
210210
211- bot .send_message (channel_id , 'Канал работает с помощью @vk_channelify_bot' )
211+ context . bot .send_message (channel_id , 'Канал работает с помощью @vk_channelify_bot' )
212212
213213 update .message .reply_text ('Готово!' )
214214 update .message .reply_text ('Бот будет проверять группу каждые 15 минут' )
@@ -221,7 +221,7 @@ def new_in_state_asked_channel_message(bot, update, db, users_state):
221221
222222
223223@catch_exceptions
224- def cancel_new (bot , update , users_state ):
224+ def cancel_new (update , context , users_state ):
225225 metrics .telegram_conversations_total .labels (type = 'new' , status = 'cancelled' ).inc ()
226226
227227 update .message .reply_text ('Ладно' , reply_markup = ReplyKeyboardRemove ())
@@ -235,7 +235,7 @@ def cancel_new(bot, update, users_state):
235235@catch_exceptions
236236@make_db_session
237237@observe_metrics ('filter_by_hashtag' )
238- def filter_by_hashtag (bot , update , db , users_state ):
238+ def filter_by_hashtag (update , context , db , users_state ):
239239 user_id = update .message .from_user .id
240240
241241 metrics .telegram_conversations_total .labels (type = 'filter_by_hashtag' , status = 'started' ).inc ()
@@ -246,7 +246,7 @@ def filter_by_hashtag(bot, update, db, users_state):
246246 keyboard_row = []
247247 for channel in db .query (Channel ).filter (Channel .owner_id == str (user_id )).order_by (Channel .created_at .desc ()):
248248 try :
249- channel_chat = bot .get_chat (chat_id = channel .channel_id )
249+ channel_chat = context . bot .get_chat (chat_id = channel .channel_id )
250250 users_state [user_id ]['channels' ][channel_chat .title ] = channel .channel_id
251251 keyboard_row .append (channel_chat .title )
252252 if len (keyboard_row ) == 2 :
@@ -265,7 +265,7 @@ def filter_by_hashtag(bot, update, db, users_state):
265265
266266@catch_exceptions
267267@make_db_session
268- def filter_by_hashtag_in_state_asked_channel_id (bot , update , db , users_state ):
268+ def filter_by_hashtag_in_state_asked_channel_id (update , context , db , users_state ):
269269 user_id = update .message .from_user .id
270270 channel_title = update .message .text
271271 channel_id = str (users_state [user_id ]['channels' ][channel_title ])
@@ -282,7 +282,7 @@ def filter_by_hashtag_in_state_asked_channel_id(bot, update, db, users_state):
282282
283283@catch_exceptions
284284@make_db_session
285- def filter_by_hashtag_in_state_asked_hashtags (bot , update , db , users_state ):
285+ def filter_by_hashtag_in_state_asked_hashtags (update , context , db , users_state ):
286286 user_id = update .message .from_user .id
287287 channel = users_state [user_id ]['channel' ]
288288
@@ -303,8 +303,9 @@ def filter_by_hashtag_in_state_asked_hashtags(bot, update, db, users_state):
303303
304304
305305@catch_exceptions
306- def cancel_filter_by_hashtag (bot , update , users_state ):
306+ def cancel_filter_by_hashtag (update , context , users_state ):
307307 metrics .telegram_conversations_total .labels (type = 'filter_by_hashtag' , status = 'cancelled' ).inc ()
308+
308309 update .message .reply_text ('Ладно' , reply_markup = ReplyKeyboardRemove ())
309310 update .message .reply_text ('Настроить фильтр по хештегам можно командой /filter_by_hashtag' )
310311 update .message .reply_text ('Команда /new настроит новый канал' )
@@ -317,7 +318,7 @@ def cancel_filter_by_hashtag(bot, update, users_state):
317318@catch_exceptions
318319@make_db_session
319320@observe_metrics ('recover' )
320- def recover (bot , update , db , users_state ):
321+ def recover (update , context , db , users_state ):
321322 user_id = update .message .from_user .id
322323
323324 metrics .telegram_conversations_total .labels (type = 'recover' , status = 'started' ).inc ()
@@ -349,7 +350,7 @@ def recover(bot, update, db, users_state):
349350
350351@catch_exceptions
351352@make_db_session
352- def recover_in_state_asked_channel_id (bot , update , db , users_state ):
353+ def recover_in_state_asked_channel_id (update , context , db , users_state ):
353354 user_id = update .message .from_user .id
354355 channel_title = update .message .text
355356 channel_id = str (users_state [user_id ]['channels' ][channel_title ])
@@ -381,7 +382,7 @@ def recover_in_state_asked_channel_id(bot, update, db, users_state):
381382
382383
383384@catch_exceptions
384- def cancel_recover (bot , update , users_state ):
385+ def cancel_recover (update , context , users_state ):
385386 metrics .telegram_conversations_total .labels (type = 'recover' , status = 'cancelled' ).inc ()
386387
387388 update .message .reply_text ('Ладно' , reply_markup = ReplyKeyboardRemove ())
0 commit comments