18
18
api_hash = os .getenv ('API_HASH' ) # APP hash from my.telegram.org
19
19
session = os .getenv ('SESSION' ) # session string via telethon
20
20
client = telethon .TelegramClient (telethon .sessions .StringSession (session ), api_id , api_hash ) # none of your bussiness
21
+ file_name = 'README.md' if os .getenv ('FILE_NAME' ) is None else os .getenv ('FILE_NAME' ) # filename is case sensitive
21
22
22
23
# print some information
23
24
def display ():
@@ -32,51 +33,51 @@ def display():
32
33
def updateme (old , json_data , first_match , second_match ):
33
34
new = '''\n | 🤖 Bot 🤖 | ⭐️ Status ⭐️ |\n | :-: | :-: |\n '''
34
35
for i in json_data :
35
- new += f"| [{ i } ](https://t.me/{ i } ) | { '✔️' if json_data [i ] else '❌' } |\n "
36
+ new += f"| [{ json_data [ i ][ 'name' ] } ](https://t.me/{ i } ) | { '✔️' if json_data [i ][ 'status' ] else '❌' } |\n "
36
37
new_string = f"\n { first_match } \n { new } \n `Updated last at ~ { datetime .now (timezone ('Asia/Kolkata' )).strftime ('%H:%M:%S on %Y-%m-%d ' )} INR` 🏳️🌈\n \n "
37
38
new_string += f"**Made with ❤️ via [BotStatus](https://github.com/jainamoswal/botstatus)**. \n { second_match } "
38
39
return re .sub (f'\n { first_match } .*?{ second_match } ' , new_string , old , flags = re .DOTALL )
39
40
40
41
# fetch status of all bots listed in the raw gist file
41
42
async def main ():
43
+ bot_status = {}
42
44
async with client :
43
- bot_status = {}
44
45
for each_bot in bots :
45
46
async with client .conversation (each_bot , exclusive = False ) as conv :
47
+ name = await client .get_entity (each_bot )
46
48
try :
47
49
sent = await conv .send_message ('/' + bots [each_bot ]['start' ])
48
50
received = await conv .get_response (timeout = bots [each_bot ]['sleep' ])
49
51
await received .delete ()
50
- bot_status .update ({each_bot :True })
52
+ bot_status .update ({each_bot :{ 'name' : name . first_name , 'status' : True } })
51
53
await sent .delete ()
52
54
except Exception as e :
53
55
if type (e ).__name__ == "YouBlockedUserError" :
54
56
print (f'🚧 You\' ve blocked @{ each_bot } . Please unblock it, until next run, I\' ll mark it as down. 🚧' ) # you blocked the bot :(
55
- bot_status .update ({each_bot :False }) # bot didn't replied back :(
57
+ bot_status .update ({each_bot :{ 'name' : name . first_name , 'status' : False } }) # bot didn't replied back :(
56
58
return bot_status
57
59
58
60
# edit the message with status at telegram
59
61
async def edit_message (data ):
60
62
async with client :
61
63
text = 'Live status of my bots goes following ~\n '
62
64
for i in data :
63
- text += f"🔅 [{ i } ](https://t.me/{ i } ) ~ { '🚀' if data [i ] else '❌' } \n "
65
+ text += f"🔅 [{ data [ i ][ 'name' ] } ](https://t.me/{ i } ) ~ { '🚀' if data [i ][ 'status' ] else '❌' } \n "
64
66
text += f"\n **Last Checked:** \n __{ datetime .now (timezone ('Asia/Kolkata' )).strftime ('%Y-%m-%d %H:%M:%S' )} IST__\n \n **Bots status are auto-updated every 3 hours at random frequency.**\n \n [J Projects](https://t.me/J_Projects)"
65
67
await client .edit_message (int (os .getenv ('CHANNEL_ID' )), int (os .getenv ('MESSAGE_ID' )), text , link_preview = False )
66
68
67
69
# run the script via __main__ style
68
70
if __name__ == '__main__' :
69
71
json_data = client .loop .run_until_complete (main ())
70
72
display ()
73
+ print (json_data )
71
74
for each in json_data :
72
- print (f"🔸 @{ each } is { '🟢' if json_data [each ] else '🔴' } " )
75
+ print (f"🔸 { json_data [ each ][ 'name' ] } [ @{ each } ] is { '🟢' if json_data [each ][ 'status' ] else '🔴' } " )
73
76
client .loop .run_until_complete (edit_message (json_data ))
74
77
repo = github .Github (os .getenv ('GITHUB_TOKEN' )).get_repo (os .getenv ('GITHUB_REPOSITORY' ))
75
- contents = repo .get_contents ("README.md" )
76
- repo .update_file ("README.md" , "✨ auto-updated bot status. ✨" , updateme (contents .decoded_content .decode (), json_data , '<start>' , '<end>' ), contents .sha )
78
+ contents = repo .get_contents (file_name )
79
+ repo .update_file (file_name , "✨ auto-updated bot status. ✨" , updateme (contents .decoded_content .decode (), json_data , '<start>' , '<end>' ), contents .sha )
77
80
78
81
print ()
79
82
print ('::::::::::::::::::::: 🎉 Action completed successfully 🎉 :::::::::::::::::::::' )
80
- print ('Mind joining @j_projects at Telegram and do follow me on github.com <jainamoswal>' )
81
-
82
-
83
+ print ('Mind joining @j_projects at Telegram and do follow me on github.com <jainamoswal>' )
0 commit comments