-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoffee-discord-bash-bot.py
56 lines (46 loc) · 2.2 KB
/
coffee-discord-bash-bot.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
51
52
53
54
55
56
import discord
import subprocess
import datetime
client = discord.Client()
def process_message(message):
args = message.content.split(" ")
return args
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('`Hello! ITguy is online`')
if message.content.startswith('$help'):
await message.channel.send('```rust\nOptions are:\n$check\n$reboot <server> (where <server> can be: "plex, jf")\n$help```')
if message.content.startswith('$check'):
result1 = subprocess.run(['/opt/utils/cdbb/coffee-discord-bash-bot.sh', 'plex', 'check'])
if (result1.returncode == 0):
result1msg = 'Plex server is "down" with code 502. Please run "$reboot plex"'
else:
result1msg = 'Plex server is ok'
result2 = subprocess.run(['/opt/utils/cdbb/coffee-discord-bash-bot.sh', 'jf', 'check'])
if (result2.returncode == 0):
result2msg = 'Jellyfin server is "down" with code 502. Please run "$reboot jf"'
else:
result2msg = 'Jellyfin server is ok'
now = datetime.datetime.now()
datenow = now.strftime("%H:%M %p")
await message.channel.send( '```rust\n"{}" ran a check at {}:\n- {} \n- {}```'.format(message.author.display_name, datenow, result1msg, result2msg))
if message.content.startswith('$reboot'):
args = process_message(message)
server = args[1]
# link = args[2]
result = subprocess.run(['/opt/utils/cdbb/coffee-discord-bash-bot.sh', server])
return_code = result.returncode
if (return_code == 0):
result2 = 'Server was "down" and was rebooted "successfully"'
else:
result2 = 'Server was fine and was left alone'
now = datetime.datetime.now()
datenow = now.strftime("%H:%M %p")
await message.channel.send( '```rust\n"{}" server was rebooted by "{}" at {} with result: \n- {}```'.format(server, message.author.display_name, datenow, result2))
client.run('<insert-bot-token>')