Skip to content

Commit 80e002d

Browse files
committed
📝 Minor changes.
1 parent a83c0e6 commit 80e002d

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Diff for: ReadMe.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[![Contributors](https://img.shields.io/github/contributors/jainamoswal/BotStatus?style=for-the-badge&color=green)](https://github.com/jainamoswal/BotStatus)
77

88

9-
109
## BotStatus ~
1110

1211
A simple & short repository to show your bot's status in your GitHub README.md file as well as in you channel.
@@ -24,18 +23,22 @@ A simple & short repository to show your bot's status in your GitHub README.md f
2423
_⚠️ You'll need a bots.json file and list all bots in the JSON format.
2524
It can be raw link from `gist.github.com` or directly by the file itself like `https://github.com/<blabla>/raw/<branchname>/<filename>`. But it should point to the raw source._
2625

26+
2727
<details>
2828
<summary><b>🤫&nbsp;Environment variables</b></summary>
2929
<br/>
3030

3131
| 🔒 Secret 🔒 | ✍️ Description ✍️ |
3232
| :-: | :-: |
33-
| API_HASH | Get it from [my.telegram.org](https://my.telegram.org) |
34-
| APP_ID | Get it from [my.telegram.org](https://my.telegram.org) |
35-
| CHANNEL_ID | Channel ID eg. -10010254xxxxx |
36-
| MESSAGE_ID | Message ID of the message to edit. |
37-
| SESSION | [![Run on Repl.it](https://replit.com/badge/github/jainamoswal/SessionString)](https://replit.com/@jainamoswal/SessionString) |
38-
| BOTS | Raw link of JSON file of bots. [example](./example.json) |
33+
| `API_HASH` | Get it from [my.telegram.org](https://my.telegram.org) |
34+
| `APP_ID` | Get it from [my.telegram.org](https://my.telegram.org) |
35+
| `CHANNEL_ID` | Channel ID eg. -10010254xxxxx |
36+
| `MESSAGE_ID` | Message ID of the message to edit. |
37+
| `SESSION` | [![Run on Repl.it](https://replit.com/badge/github/jainamoswal/SessionString)](https://replit.com/@jainamoswal/SessionString) |
38+
| `BOTS` | Raw link of JSON file of bots. [example](./example.json) |
39+
40+
<b>Optional variables ~ </b>
41+
- `FILE_NAME` : Name of the MarkDown file, eg. `README.md`. This is case sensitive. Defaults to `README.md`.
3942
</details>
4043

4144

Diff for: main.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
api_hash = os.getenv('API_HASH') # APP hash from my.telegram.org
1919
session = os.getenv('SESSION') # session string via telethon
2020
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
2122

2223
# print some information
2324
def display():
@@ -32,51 +33,51 @@ def display():
3233
def updateme(old, json_data, first_match, second_match):
3334
new = '''\n| 🤖 Bot 🤖 | ⭐️ Status ⭐️ |\n| :-: | :-: |\n'''
3435
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"
3637
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"
3738
new_string += f"**Made with ❤️ via [BotStatus](https://github.com/jainamoswal/botstatus)**. \n{second_match}"
3839
return re.sub(f'\n{first_match}.*?{second_match}', new_string, old, flags=re.DOTALL)
3940

4041
# fetch status of all bots listed in the raw gist file
4142
async def main():
43+
bot_status = {}
4244
async with client:
43-
bot_status = {}
4445
for each_bot in bots:
4546
async with client.conversation(each_bot, exclusive=False) as conv:
47+
name = await client.get_entity(each_bot)
4648
try:
4749
sent = await conv.send_message('/' + bots[each_bot]['start'])
4850
received = await conv.get_response(timeout=bots[each_bot]['sleep'])
4951
await received.delete()
50-
bot_status.update({each_bot:True})
52+
bot_status.update({each_bot:{'name':name.first_name, 'status':True}})
5153
await sent.delete()
5254
except Exception as e:
5355
if type(e).__name__ == "YouBlockedUserError":
5456
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 :(
5658
return bot_status
5759

5860
# edit the message with status at telegram
5961
async def edit_message(data):
6062
async with client:
6163
text = 'Live status of my bots goes following ~\n'
6264
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"
6466
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)"
6567
await client.edit_message(int(os.getenv('CHANNEL_ID')), int(os.getenv('MESSAGE_ID')), text, link_preview=False)
6668

6769
# run the script via __main__ style
6870
if __name__ == '__main__':
6971
json_data = client.loop.run_until_complete(main())
7072
display()
73+
print(json_data)
7174
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 '🔴'}")
7376
client.loop.run_until_complete(edit_message(json_data))
7477
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)
7780

7881
print()
7982
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

Comments
 (0)