pm2d

telebot

Mar 1st, 2021
664
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import subprocess;
  3. import ipaddress;
  4. import telebot;
  5. bot = telebot.TeleBot('авотхуйтокен');
  6.  
  7. def is_ip(string):
  8.   try:
  9.     ipaddress.ip_address(string)
  10.     return True
  11.   except ValueError:
  12.     return False
  13.  
  14. def ping(host):
  15.   command = ['ping', '-c1', '-W1', host]
  16.   return subprocess.call(command) == 0
  17.  
  18. @bot.message_handler(commands=['start'])
  19. def command_start(message):
  20.   bot.send_message(message.from_user.id, 'Привет. Твой ID ' + str(message.from_user.id))
  21.  
  22. @bot.message_handler(commands=['id'])
  23. def command_id(message):
  24.   bot.send_message(message.from_user.id, 'Твой ID ' + str(message.from_user.id))
  25.  
  26. @bot.message_handler(commands=['help'])
  27. def command_help(message):
  28.   bot.send_message(message.from_user.id, "/help - справка\n/id - узнать свой ID\n/ping адрес - пропинговать адрес")
  29.  
  30. @bot.message_handler(commands=['ping'])
  31. def command_ping(message):
  32.   command = message.text.split()
  33.   if is_ip(command[1]):
  34.     proc = subprocess.Popen(['ping', '-c3', '-W1', command[1]], stdout=subprocess.PIPE)
  35.     stdout, stderr = proc.communicate()
  36.     print(stdout.decode('ASCII'))
  37.     bot.send_message(message.from_user.id, stdout.decode('ASCII'))
  38.   else:
  39.     bot.send_message(message.from_user.id, 'Неправильный IP-адрес')
  40.  
  41. @bot.message_handler(content_types=['text'])
  42. def get_text_messages(message):
  43.   bot.send_message(message.from_user.id, 'Неизвестная команда. См /help')
  44.   print(' - - - ')
  45.   print(message.from_user.username + ':')
  46.   print(message.text)
  47.  
  48. @bot.callback_query_handler(func=lambda call: True)
  49. def query_handler(call):
  50.   command = call.data.split()
  51.   if command[0] == 'graph' and is_ip(command[1]):
  52.     bot.answer_callback_query(callback_query_id=call.id, text='График отправляется')
  53.     bot.send_chat_action(call.message.chat.id, 'upload_photo')
  54.     graph = open('/var/www/localhost/htdocs/var/ping/' + command[1] + '.png', 'rb')
  55.     bot.send_photo(call.message.chat.id, graph)
  56.     graph.close()
  57.   elif command[0] == 'ping' and is_ip(command[1]):
  58.     if ping(command[1]):
  59.       bot.answer_callback_query(callback_query_id=call.id, text='Хост отвечает')
  60.     else:
  61.       bot.answer_callback_query(callback_query_id=call.id, text='Хост не отвечает')
  62.   else:
  63.     bot.answer_callback_query(callback_query_id=call.id, text='Ошибка, неправильная команда')
  64.   #bot.edit_message_reply_markup(call.message.chat.id, call.message.message_id)
  65.  
  66. bot.polling(none_stop=True, interval=6)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×