-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdockerbot.py
86 lines (76 loc) · 2.78 KB
/
dockerbot.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import time
import re
import random
from datetime import date
from datetime import time
from datetime import datetime
import time
import telepot
from subprocess import call
import subprocess
import os
import sys
import docker
from telepot.loop import MessageLoop
#Vars for Selenium covid kids approval
v_UserId = os.getenv('USER_ID')
v_UserKey = os.getenv('USER_KEY')
#Auto Commmand List
def search_string_in_file(file_name, string_to_search):
"""Search for the given string in file and return lines containing that string,
along with line numbers"""
list_of_results = []
new_line = "\n"
# Open the file in read only mode
with open(file_name, 'r') as read_obj:
# Read all lines in the file one by one
for line in read_obj:
# For each line, check if line contains the string
if string_to_search in line:
if ("/?" not in line and not "o/" in line and not "," in line):
command = line
number = command.rfind("/")
command = command[number:]
number = command.rfind("'")
command = command[:number]
command = command + new_line
# If yes, then add the line number & line as a tuple in the list
list_of_results.append(command)
# Return list of tuples containing line numbers and lines where string is found
return list_of_results
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
if str(chat_id) not in os.getenv('ALLOWED_IDS'):
bot.sendPhoto(chat_id,"https://github.com/t0mer/dockerbot/raw/master/No-Trespassing.gif")
return ""
now = datetime.now()
PicDate = now.strftime("%m/%d/%Y")
print ('Got command: %s')%command
if command == '/sign':
v_Kid = "sign"
try:
x = "Task Started (will take 10s+-)"
bot.sendMessage(chat_id,x)
subprocess.check_output(['python', '/etc/Health_Staytments.py', '-u', v_UserId, '-p', v_UserKey, '-k', v_Kid])
for file in os.listdir("/opt"):
if file.endswith(".png"):
Image = os.path.join("/opt", file)
bot.sendPhoto(chat_id=chat_id, photo=open(str(Image)), caption=PicDate)
os.remove(str(Image))
except:
x = "Error"
bot.sendMessage(chat_id,x)
elif command == '/?':
array = search_string_in_file('/opt/dockerbot/dockerbot.py', "/")
s = "Command List:\n"
for val in array:
if ")" not in val:
s+=str(val)
x = s
bot.sendMessage(chat_id,x)
bot = telepot.Bot(os.getenv('API_KEY'))
MessageLoop(bot, handle).run_as_thread()
print('I am listening ...')
while 1:
time.sleep(10)