-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
57 lines (43 loc) · 2.21 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
54
55
56
57
# Ts-Bots
import os
import pytz
import time
import datetime
from pyrogram import Client
user_session_string = os.environ.get("user_session_string")
bots = [i.strip() for i in os.environ.get("bots").split(' ')]
update_channel = os.environ.get("update_channel")
status_message_ids = [int(i.strip()) for i in os.environ.get("status_message_id").split(' ')]
api_id = int(os.environ.get("api_id"))
api_hash = os.environ.get("api_hash")
user_client = Client(session_name=str(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"𝐁𝐨𝐭𝐬 𝐒𝐭𝐚𝐭𝐮𝐬🔰\n\n__( All bots are checked automatically if any correction report it )__\n\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} \n𝚄𝚂𝙴𝚁𝙽𝙰𝙼𝙴 @{bot}\n𝚂𝚃𝙰𝚃𝚄𝚂 ❌\n\n"
#user_client.send_message("me",
#f"@{bot} was down")
else:
print(f"[INFO] all good with @{bot}")
edit_text += f"𝙱𝙾𝚃 𝙽𝙰𝙼𝙴 {bot} \n𝚄𝚂𝙴𝚁𝙽𝙰𝙼𝙴 @{bot}\n𝚂𝚃𝙰𝚃𝚄𝚂 ✅\n\n"
user_client.read_history(bot)
time_now = datetime.datetime.now(pytz.timezone('Asia/Kolkata'))
formatted_time = time_now.strftime("%d %B %Y %I:%M %p")
edit_text += f"**Updated on {formatted_time} (IST)**"
for status_message_id in status_message_ids:
user_client.edit_message_text(int(update_channel), status_message_id,
edit_text)
time.sleep(5)
print(f"[INFO] everything done! sleeping for 10 minutes...")
time.sleep(600)
if __name__ == "__main__":
main()