1
0

vanitybot.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from aiogram.types import message
  2. from aiogram.types.message import Message
  3. from logzero import logger
  4. import logging
  5. from aiogram import Bot, Dispatcher, executor, types
  6. from config import API_TOKEN
  7. # Configure logging
  8. logging.basicConfig(level=logging.INFO)
  9. # Initialize bot and dispatcher
  10. bot = Bot(token=API_TOKEN)
  11. dp = Dispatcher(bot)
  12. @dp.message_handler(commands=['start'])
  13. async def process_start_command(message: types.Message):
  14. await message.reply("Hello!\n\n\
  15. Send me a link paper from arxiv.org and \
  16. I'll send you back arxiv-vanity.com link with paper!\n\
  17. Or add me to chat and I'll be watching the arxiv link and \
  18. reply to them with fancy axiv-vanity links.")
  19. @dp.message_handler(commands=['help'])
  20. async def process_help_command(message: types.Message):
  21. await message.reply("Напиши мне что-нибудь, и я отпрпавлю этот текст тебе в ответ!")
  22. # @dp.message_handler()
  23. # async def echo_message(message: types.Message):
  24. # await bot.send_message(message.from_user.id, message.text)
  25. @dp.message_handler(regexp='arxiv.org/\s*([^\s]*)')
  26. async def cats(message: types.Message):
  27. id_paper = (message.text
  28. .replace('/abs', '')
  29. .replace('/pdf', '')
  30. .replace('.pdf', '')
  31. .split('/')[-1]
  32. .split(' ')[0])
  33. await message.reply(f'https://arxiv-vanity.com/papers/{id_paper}')
  34. # await bot.send_message(message.from_user.id, message.text)
  35. if __name__ == "__main__":
  36. executor.start_polling(dp, skip_updates=True)