ping command

This commit is contained in:
3err0 2019-06-24 13:50:39 +08:00
parent 8eb463cd57
commit 98b9b475e7

18
main.py
View File

@ -24,6 +24,12 @@ def check_permission(uid):
def file_ext(filename): def file_ext(filename):
return filename.split(".")[-1] return filename.split(".")[-1]
def extract_text(text):
try:
return text.split()[1]
except:
pass
@bot.message_handler(commands=['help', 'start']) @bot.message_handler(commands=['help', 'start'])
def send_welcome(message): def send_welcome(message):
bot.reply_to(message, "Я тупая машина, и я ничего не умею") bot.reply_to(message, "Я тупая машина, и я ничего не умею")
@ -32,6 +38,18 @@ def send_welcome(message):
def my_id(message): def my_id(message):
bot.send_message(message.chat.id, 'Твой ID: ' + str(message.chat.id)) bot.send_message(message.chat.id, 'Твой ID: ' + str(message.chat.id))
@bot.message_handler(commands=['ping'])
def ping(message):
ip = extract_text(message.text)
if not ip:
bot.send_message(message.chat.id, 'Используйте комманду /ping 127.0.0.1: ')
else:
resource = os.system("ping -c 1 " + ip)
if resource == 0:
bot.reply_to(message, "Is UP")
else:
bot.reply_to(message, "Is down")
@bot.message_handler(func=lambda message: True) @bot.message_handler(func=lambda message: True)
def echo_message(message): def echo_message(message):
bot.reply_to(message, message.text) bot.reply_to(message, message.text)