Guest User

telepot

a guest
Jul 29th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import time, datetime
  2. import subprocess
  3. import os
  4. import telepot
  5. from telepot.loop import MessageLoop
  6. from telepot.namedtuple import ReplyKeyboardMarkup
  7.  
  8. #libraties
  9. now = datetime.datetime.now()
  10.  
  11. def handle(msg):
  12.     chat_id = msg['chat']['id'] # Receiving the message from telegram
  13.     command = msg['text']   # Getting text from the message
  14.    
  15.     markup = ReplyKeyboardMarkup(keyboard=[['Snapshot','HTPC']], one_time_keyboard=False, resize_keyboard=True)
  16.    
  17.     print ('Received:')
  18.     print(command)
  19.  
  20. #commands
  21.     if command == '/start':
  22.         bot.sendMessage(chat_id, 'What can I do for you?', reply_markup=markup)
  23.  
  24.     if command == '/hi':
  25.         bot.sendMessage (chat_id, str("Hi! Shufflepanda"))
  26.        
  27.     elif command == '/time':
  28.         bot.sendMessage (chat_id, str(now))
  29.        
  30.     elif command == 'Snapshot':
  31.         subprocess.call(['/home/A11BoxPr0jectAdm/telepot/send_camshot.sh'])
  32.        
  33.     elif command == '/snapshot':
  34.         subprocess.call(['/home/A11BoxPr0jectAdm/telepot/send_camshot.sh'])
  35.        
  36.     elif command == '/entree':
  37.         os.system ('curl -s "http://192.168.1.30:8702/json.htm?type=command&param=switchscene&idx=3&switchcmd=Toggle"')
  38.        
  39.     elif command == '/salon':
  40.         os.system ('curl -s "http://192.168.1.30:8702/json.htm?type=command&param=switchscene&idx=2&switchcmd=Toggle"')
  41.        
  42.     elif command == 'HTPC':
  43.         os.system ('curl -s "http://192.168.1.30:8702/json.htm?type=command&param=switchlight&idx=5&switchcmd=Toggle"')
  44.         os.system ('curl -s "http://192.168.1.30:8702/json.htm?type=command&param=switchlight&idx=5&switchcmd=Toggle"')
  45.        
  46.  
  47. bot = telepot.Bot('put.your.telegram.bot.ID')
  48. MessageLoop(bot, handle).run_as_thread()
  49. print ('I am listening ...')
  50.  
  51. while 1:
  52.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment