-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwolbot.py
50 lines (39 loc) · 1.74 KB
/
wolbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import config
import telebot
from telebot import types
import time
import os
bot_token = config.token
cid = config.chat_id
serverIp = config.ip
serverMac = config.mac
bot = telebot.TeleBot(bot_token, parse_mode=None)
menuKeyboard = types.InlineKeyboardMarkup()
menuKeyboard.add(types.InlineKeyboardButton('Server status', callback_data='status'), types.InlineKeyboardButton('Start plex server', callback_data='start'))
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
sentMessage = bot.reply_to(message, "Ahoy")
print(str(cid) != str(sentMessage.chat.id))
print(sentMessage.chat.id)
if (str(cid) != str(sentMessage.chat.id)):
bot.edit_message_text("Wrong chat for this command", sentMessage.chat.id, sentMessage.message_id)
return
response = os.system("ping -c 1 " + serverIp)
print(response)
if response == 0:
bot.edit_message_text("Plex server is up", sentMessage.chat.id, sentMessage.message_id)
else:
bot.edit_message_text("Starting plex server...", sentMessage.chat.id, sentMessage.message_id)
waittime = 3
while response != 0 and waittime >= 0:
os.system("sudo etherwake "+ serverMac)
time.sleep(1)
response = os.system("ping -c 1 " + serverIp)
if response != 0 and waittime > 0:
bot.edit_message_text(waittime, sentMessage.chat.id, sentMessage.message_id)
if response != 0 and waittime <= 0:
bot.edit_message_text("Server still down, please try again or contact the server admin", sentMessage.chat.id, sentMessage.message_id)
if response == 0:
bot.edit_message_text("Server is running", sentMessage.chat.id, sentMessage.message_id)
waittime -= 1
bot.infinity_polling()