Sources of Telegram bot for cryptopotato chat. https://t.me/devpotato_bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
767 B

  1. import logging
  2. import subprocess
  3. from telegram import Update
  4. from telegram.ext import CallbackContext, run_async
  5. _logger = logging.getLogger(__name__)
  6. @run_async
  7. def _fortune_callback(update: Update, context: CallbackContext):
  8. """Get random epigram from `fortune`."""
  9. try:
  10. result = subprocess.run(['fortune', '-a'], capture_output=True, text=True, timeout=2)
  11. update.message.reply_text(result.stdout, quote=False, disable_web_page_preview=True)
  12. except (OSError, TimeoutError) as error:
  13. _logger.warning('Failed to call fortune executable: %s', error)
  14. def get_handler(**kwargs):
  15. from telegram.ext import Filters, CommandHandler
  16. return CommandHandler("fortune", _fortune_callback, filters=~Filters.update.edited_message)