-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmain.py
53 lines (40 loc) · 1.82 KB
/
main.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
import os
import time
import datetime
import pyrogram
user_session_string = os.environ.get("user_session_string")
bots = [i.strip() for i in os.environ.get("bots").split(' ')]
bot_owner = os.environ.get("bot_owner")
update_channel = os.environ.get("update_channel")
status_message_id = int(os.environ.get("status_message_id"))
api_id = int(os.environ.get("api_id"))
api_hash = os.environ.get("api_hash")
user_client = pyrogram.Client(
user_session_string, api_id=api_id, api_hash=api_hash)
def main():
with user_client:
while True:
print("[INFO] starting to check uptime..")
edit_text = f"@{update_channel} Bot's Uptime Status.(Updated every 15 mins)\n\n"
for bot in bots:
print(f"[INFO] checking @{bot}")
snt = user_client.send_message(bot, '/start')
time.sleep(15)
msg = user_client.get_history(bot, 1)[0]
if snt.message_id == msg.message_id:
print(f"[WARNING] @{bot} is down")
edit_text += f"@{bot} status: `Down`\n\n"
user_client.send_message(bot_owner,
f"@{bot} status: `Down`")
else:
print(f"[INFO] all good with @{bot}")
edit_text += f"@{bot} status: `Up`\n\n"
user_client.read_history(bot)
utc_now = datetime.datetime.utcnow()
ist_now = utc_now + datetime.timedelta(minutes=30, hours=5)
edit_text += f"__last checked on \n{str(utc_now)} UTC\n{ist_now} IST__"
user_client.edit_message_text(update_channel, status_message_id,
edit_text)
print(f"[INFO] everything done! sleeping for 15 mins...")
time.sleep(15 * 60)
main()