telegram_main.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/python3
  2. from telegram.ext import Updater, CommandHandler
  3. from randstrip import createStrip,readConfig
  4. import requests
  5. import os
  6. fileDir = os.path.dirname(os.path.abspath(__file__))
  7. fileDir = fileDir +"/"
  8. def newStrip(update, context):
  9. config = readConfig(platform="telegram",profile=context.args)
  10. status = createStrip(config)
  11. if status == 0:
  12. try:
  13. strip_file=open(config["saveLocation"]+config["filename"],"rb")
  14. context.bot.send_photo(chat_id=update.message.chat_id,photo=strip_file)
  15. strip_file.close()
  16. os.remove(config["saveLocation"]+config["filename"])
  17. except Exception as err:
  18. print(err)
  19. else:
  20. print("Creation of image failed\n")
  21. print(status)
  22. if __name__ == "__main__":
  23. config = readConfig(platform="telegram")
  24. with open(config["token"]) as token_file:
  25. content = token_file.readlines()
  26. token = content[0].strip()
  27. updater = Updater(token, use_context=True)
  28. dp = updater.dispatcher
  29. dp.add_handler(CommandHandler('strip',newStrip, pass_args=True))
  30. updater.start_polling()
  31. updater.idle()