diff --git a/aiogram/utils/executor.py b/aiogram/utils/executor.py index 65594371..cdb3fe91 100644 --- a/aiogram/utils/executor.py +++ b/aiogram/utils/executor.py @@ -339,7 +339,7 @@ class Executor: async def _skip_updates(self): await self.dispatcher.reset_webhook(True) await self.dispatcher.skip_updates() - log.warning(f"Updates are skipped successfully.") + log.warning(f'Updates were skipped successfully.') async def _welcome(self): user = await self.dispatcher.bot.me diff --git a/examples/callback_data_factory.py b/examples/callback_data_factory.py index 8fd197df..9a8affe9 100644 --- a/examples/callback_data_factory.py +++ b/examples/callback_data_factory.py @@ -1,4 +1,3 @@ -import asyncio import logging import random import uuid @@ -21,12 +20,12 @@ dp.middleware.setup(LoggingMiddleware()) POSTS = { str(uuid.uuid4()): { - 'title': f"Post {index}", + 'title': f'Post {index}', 'body': 'Lorem ipsum dolor sit amet, ' 'consectetur adipiscing elit, ' 'sed do eiusmod tempor incididunt ut ' 'labore et dolore magna aliqua', - 'votes': random.randint(-2, 5) + 'votes': random.randint(-2, 5), } for index in range(1, 6) } @@ -42,21 +41,24 @@ def get_keyboard() -> types.InlineKeyboardMarkup: markup.add( types.InlineKeyboardButton( post['title'], - callback_data=posts_cb.new(id=post_id, action='view')) + callback_data=posts_cb.new(id=post_id, action='view')), ) return markup def format_post(post_id: str, post: dict) -> (str, types.InlineKeyboardMarkup): - text = f"{md.hbold(post['title'])}\n" \ - f"{md.quote_html(post['body'])}\n" \ - f"\n" \ - f"Votes: {post['votes']}" + text = md.text( + md.hbold(post['title']), + md.quote_html(post['body']), + '', # just new empty line + f"Votes: {post['votes']}", + sep = '\n', + ) markup = types.InlineKeyboardMarkup() markup.row( types.InlineKeyboardButton('👍', callback_data=posts_cb.new(id=post_id, action='like')), - types.InlineKeyboardButton('👎', callback_data=posts_cb.new(id=post_id, action='unlike')), + types.InlineKeyboardButton('👎', callback_data=posts_cb.new(id=post_id, action='dislike')), ) markup.add(types.InlineKeyboardButton('<< Back', callback_data=posts_cb.new(id='-', action='list'))) return text, markup @@ -84,7 +86,7 @@ async def query_view(query: types.CallbackQuery, callback_data: dict): await query.message.edit_text(text, reply_markup=markup) -@dp.callback_query_handler(posts_cb.filter(action=['like', 'unlike'])) +@dp.callback_query_handler(posts_cb.filter(action=['like', 'dislike'])) async def query_post_vote(query: types.CallbackQuery, callback_data: dict): try: await dp.throttle('vote', rate=1) @@ -100,10 +102,10 @@ async def query_post_vote(query: types.CallbackQuery, callback_data: dict): if action == 'like': post['votes'] += 1 - elif action == 'unlike': + elif action == 'dislike': post['votes'] -= 1 - await query.answer('Voted.') + await query.answer('Vote accepted') text, markup = format_post(post_id, post) await query.message.edit_text(text, reply_markup=markup) @@ -114,4 +116,4 @@ async def message_not_modified_handler(update, error): if __name__ == '__main__': - executor.start_polling(dp, loop=loop, skip_updates=True) + executor.start_polling(dp, skip_updates=True)