bystartw_1

TG Bot on Python

Aug 24th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. __author__ = "byStarTW"
  2. import telepot # pip install telepot
  3. import time
  4. import os
  5. if os.name == "nt":
  6.     os.system ('cls')
  7.     os.system ('title Telegram Bot 訊息傳送')
  8. else:
  9.     os.system ('clear')
  10. # settings
  11. token = ('') # your bot token! (@botfather)
  12. bot = telepot.Bot(token)
  13. def sendMessage(chat_id, message):
  14.     bot.sendMessage(chat_id, message)
  15. def sendMessage_markdown(chat_id, message):
  16.     bot.sendMessage(chat_id, message, 'markdown')
  17. chat_id = str('') # chat_id
  18. # confim settings
  19. if chat_id == (''):
  20.     print ("未設定 chat_id")
  21.     exit()
  22. if token == (''):
  23.     print ("未設定 TG token")
  24.     exit()
  25. # Main Menu
  26. msgMode = input("請輸入輸出文字模式 (Plain Text / Markdown): ")
  27. if msgMode == "Plain Text":
  28.     msgMode = "False"
  29. elif msgMode == "Markdown":
  30.     msgMode = "True"
  31. else:
  32.     exit()
  33. msgText = input("請輸入輸出的文字: ")
  34. if msgText != "":
  35.     msgText2 = input("你確定要輸出 '" + msgText + "' 嗎? (Yes / No): " )
  36.     if msgText2 == "Yes":
  37.         if msgMode == "False":
  38.             print ("請稍候... 正在傳送訊息... ")
  39.             sendMessage(chat_id, msgText)
  40.             print ("已經傳送! :-)")
  41.         elif msgMode == "True":
  42.             print ("請稍候... 正在傳送訊息... ")
  43.             sendMessage_markdown(chat_id, msgText)
  44.             print ("已經傳送! :-)")
  45.         else:
  46.             exit()
  47.     else:
  48.         exit()
  49. else:
  50.    exit()
Advertisement
Add Comment
Please, Sign In to add comment