Advertisement
techblog

telebot.py

Aug 9th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import time
  2. import random
  3. import datetime
  4. import telepot
  5. from subprocess import call
  6. import subprocess
  7. import os
  8. from telepot.loop import MessageLoop
  9.  
  10. def handle(msg):
  11.     chat_id = msg['chat']['id']
  12.     command = msg['text']
  13.  
  14.     print ('Got command: %s')%command
  15.     if command == '/time':
  16.         bot.sendMessage(chat_id, str(datetime.datetime.now()))
  17.     elif command == '/speed':
  18.         x = subprocess.check_output(['speedtest-cli','--share'])
  19.         bot.sendMessage(chat_id,x)
  20.     elif command == '/ip':
  21.         x = subprocess.check_output(['curl','ipinfo.io/ip'])
  22.         bot.sendMessage(chat_id,x)
  23.     elif command == '/disk':
  24.         x = subprocess.check_output(['df'])
  25.         bot.sendMessage(chat_id,x)
  26.     elif command == '/mem':
  27.         x = subprocess.check_output(['cat','/proc/meminfo'])
  28.         bot.sendMessage(chat_id,x)
  29.     elif command == '/stat':
  30.         bot.sendMessage(chat_id,'Number five is alive!')
  31.     elif command == '/ddns':
  32.         x = subprocess.check_output(['python','/opt/telepi/ddns.py'])
  33.         bot.sendMessage(chat_id,x)
  34.     elif command == '/services':
  35.         x = subprocess.check_output('service --status-all|grep "+"', shell = True)
  36.         bot.sendMessage(chat_id,x)
  37.  
  38. bot = telepot.Bot('*** your telebot token from step 2*********')
  39. MessageLoop(bot, handle).run_as_thread()
  40. print('I am listening ...')
  41.  
  42. while 1:
  43.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement