Skip to content

Commit a83c0e6

Browse files
committed
Published the app to marketplace.
0 parents  commit a83c0e6

File tree

6 files changed

+890
-0
lines changed

6 files changed

+890
-0
lines changed

Diff for: LICENSE

+674
Large diffs are not rendered by default.

Diff for: ReadMe.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[![Issues](https://img.shields.io/github/issues/jainamoswal/BotStatus?style=for-the-badge&color=green)](https://github.com/jainamoswal/BotStatus/issues)
2+
[![Forks](https://img.shields.io/github/forks/jainamoswal/BotStatus?style=for-the-badge&color=green)](https://github.com/jainamoswal/BotStatus/fork)
3+
[![Stars](https://img.shields.io/github/stars/jainamoswal/BotStatus?style=for-the-badge&color=green)](https://github.com/jainamoswal/BotStatus)
4+
[![LICENSE](https://img.shields.io/github/license/jainamoswal/BotStatus?color=green&style=for-the-badge)](https://github.com/jainamoswal/BotStatus)
5+
[![Size](https://img.shields.io/github/repo-size/jainamoswal/BotStatus?style=for-the-badge&color=green)](https://github.com/jainamoswal/BotStatus)
6+
[![Contributors](https://img.shields.io/github/contributors/jainamoswal/BotStatus?style=for-the-badge&color=green)](https://github.com/jainamoswal/BotStatus)
7+
8+
9+
10+
## BotStatus ~
11+
12+
A simple & short repository to show your bot's status in your GitHub README.md file as well as in you channel.
13+
14+
---
15+
### How to use this ?
16+
17+
- **Star** this repo. ⭐
18+
- Go to the repository where you want to display the status of the bots. 🤖
19+
- Go to environment variables ([Settings ⇢ Secrets ⇢ New Repository Secret.](https://docs.github.com/en/actions/reference/encrypted-secrets)) 🚶
20+
- Fill all Environment variables there. 🤭
21+
- Copy [this](./example.yml) snippet in `./github/workflows/main.yml` in your repository. 📁
22+
- The workflow will automatically run at interval of 3 hours. 🏃
23+
24+
_⚠️ You'll need a bots.json file and list all bots in the JSON format.
25+
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._
26+
27+
<details>
28+
<summary><b>🤫&nbsp;Environment variables</b></summary>
29+
<br/>
30+
31+
| 🔒 Secret 🔒 | ✍️ Description ✍️ |
32+
| :-: | :-: |
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+
</details>
40+
41+
42+
<details>
43+
<summary><b>:v: &nbsp;Support me</b></summary>
44+
<br/>
45+
<p align="center">
46+
<a href="https://paypal.com/paypalme/JOswal105">
47+
<img height="40px" src="https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png" />
48+
</a> &nbsp;
49+
<a href="https://buymeacoffee.com/jainamoswal">
50+
<img height="40px" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" />
51+
</a> &nbsp;
52+
<a href="https://ko-fi.com/O5O64S9GG">
53+
<img height="40px" src="https://cdn.ko-fi.com/cdn/kofi3.png?v=2" />
54+
</a> &nbsp;
55+
<a href="https://upier.org/pay?vpa=jainamoswal@sbi&amount=250">
56+
<img height="40px" src="https://upload.wikimedia.org/wikipedia/commons/archive/e/e1/20200901100646%21UPI-Logo-vector.svg" />
57+
</a>
58+
</p>
59+
60+
</details>
61+
62+
<details>
63+
<summary><b>💻&nbsp;Credits</b></summary>
64+
<br/>
65+
66+
- [xditya](https://github.com/xditya) for inspiration from [his repo.](https://github.com/xditya/BotStatus)
67+
- [Lonami](https://github.com/LonamiWebs) for telethon.
68+
- [Google](https://google.com) and [Telethon docs](https://docs.telethon.dev/en/latest) 😅
69+
</details>
70+
71+
<hr/>
72+
73+
## License
74+
### [BotStatus](https://github.com/jainamoswal/BotStatus) is licensed under [GNU Affero General Public License v3](https://www.gnu.org/) or later.
75+
76+
[![License](https://www.gnu.org/graphics/gplv3-or-later.png)](LICENSE)
77+
78+
`The GNU General Public License (GNU GPL or simply GPL) is a series of widely-used free software licenses that guarantee end users the freedom to run, study, share, and modify the software.[8] The licenses were originally written by Richard Stallman, founder of the Free Software Foundation (FSF), for the GNU Project, and grant the recipients of a computer program the rights of the Free Software Definition.[9] The GPL series are all copyleft licenses, which means that any derivative work must be distributed under the same or equivalent license terms. This is in distinction to permissive software licenses, of which the BSD licenses and the MIT License are widely used, less restrictive examples. GPL was the first copyleft license for general use.`

Diff for: action.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: 'Bot Status'
2+
author: 'Jainam Oswal'
3+
description: 'An action to automatically update bot status in GitHub Readme.md as well as in Telegram chat. (Channel/Group/Chat)'
4+
5+
runs:
6+
using: "composite"
7+
steps:
8+
- name: 📀 Install dependency. 📀
9+
run: |
10+
pip install --upgrade pytz telethon pygithub pip > ignoreme.txt 2>&1
11+
shell: bash
12+
- name: Run the action.
13+
run: python ${{ github.action_path }}/main.py
14+
shell: bash
15+
16+
17+
branding:
18+
icon: 'send'
19+
color: 'white'

Diff for: example.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"pypi_dlbot": {
3+
"start": "start",
4+
"sleep": 2
5+
},
6+
"ixail_bot": {
7+
"start": "start",
8+
"sleep": 2
9+
},
10+
"secure_me_robot": {
11+
"start": "start",
12+
"sleep": 2
13+
},
14+
"medium_free_robot": {
15+
"start": "start",
16+
"sleep": 2
17+
}
18+
}

Diff for: example.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: ⚡️ Update Status. ⚡️
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: "0 */3 * * *"
6+
jobs:
7+
update-readme-with-projects:
8+
name: 🏃‍♂️ run the bot 🏃‍♂️
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: jainamoswal/botstatus@main
12+
env: # all the six environment variables are must, else the action will raise errors.
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # automatically fetched. none of business.
14+
BOTS: ${{ secrets.BOTS }} # link of raw file of bots in JSON format. (eg :~ https://gist.githubusercontent.com/jainamoswal/cc331a3d2a4169ab76885c5a1e076d68/raw#file-bots-json)
15+
SESSION: ${{ secrets.SESSION }} # telethon session string
16+
APP_ID: ${{ secrets.APP_ID }} # APP ID from my.telegram.org
17+
API_HASH: ${{ secrets.API_HASH }} # API ID from my.telegram.org
18+
CHANNEL_ID: ${{ secrets.CHANNEL_ID }} # channel ID of the channel you want to edit the message in.
19+
MESSAGE_ID: ${{ secrets.MESSAGE_ID }} # message id of the message to edit

Diff for: main.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# This file is part of https://github.com/jainamoswal/BotStatus.
2+
# Usage covered in < GPL-3.0 License >
3+
# Jainam Oswal. <jainam.me>
4+
5+
# import modules
6+
import os, logging, asyncio, re, github, requests, platform
7+
from pytz import timezone
8+
from datetime import datetime
9+
import telethon
10+
11+
print(':::::::::::::::::::::: ⏲️ Action started successfully ⏲️ ::::::::::::::::::::::')
12+
print()
13+
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', level=logging.CRITICAL)
14+
15+
# define configs
16+
bots = requests.get(os.getenv('BOTS')).json() # the raw link of the gist file having config data in JSON format
17+
api_id = os.getenv('APP_ID') # API ID from my.telegram.org
18+
api_hash = os.getenv('API_HASH') # APP hash from my.telegram.org
19+
session = os.getenv('SESSION') # session string via telethon
20+
client = telethon.TelegramClient(telethon.sessions.StringSession(session), api_id, api_hash) # none of your bussiness
21+
22+
# print some information
23+
def display():
24+
print()
25+
print(f"◻️ Telethon version : {telethon.__version__}") # telethon version
26+
print(f"◻️ Platform : {platform.system()}") # system
27+
print(f"◻️ Platform release : {platform.release()}") # system version
28+
print(f"◻️ OS version : {platform.version().split()[0]}") # OS version
29+
print()
30+
31+
# updates in ReadMe file at github
32+
def updateme(old, json_data, first_match, second_match):
33+
new = '''\n| 🤖 Bot 🤖 | ⭐️ Status ⭐️ |\n| :-: | :-: |\n'''
34+
for i in json_data:
35+
new += f"| [{i}](https://t.me/{i}) | {'✔️' if json_data[i] else '❌'} |\n"
36+
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+
new_string += f"**Made with ❤️ via [BotStatus](https://github.com/jainamoswal/botstatus)**. \n{second_match}"
38+
return re.sub(f'\n{first_match}.*?{second_match}', new_string, old, flags=re.DOTALL)
39+
40+
# fetch status of all bots listed in the raw gist file
41+
async def main():
42+
async with client:
43+
bot_status = {}
44+
for each_bot in bots:
45+
async with client.conversation(each_bot, exclusive=False) as conv:
46+
try:
47+
sent = await conv.send_message('/' + bots[each_bot]['start'])
48+
received = await conv.get_response(timeout=bots[each_bot]['sleep'])
49+
await received.delete()
50+
bot_status.update({each_bot:True})
51+
await sent.delete()
52+
except Exception as e:
53+
if type(e).__name__ == "YouBlockedUserError":
54+
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 :(
56+
return bot_status
57+
58+
# edit the message with status at telegram
59+
async def edit_message(data):
60+
async with client:
61+
text = 'Live status of my bots goes following ~\n'
62+
for i in data:
63+
text += f"🔅 [{i}](https://t.me/{i}) ~ {'🚀' if data[i] else '❌'}\n"
64+
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+
await client.edit_message(int(os.getenv('CHANNEL_ID')), int(os.getenv('MESSAGE_ID')), text, link_preview=False)
66+
67+
# run the script via __main__ style
68+
if __name__ == '__main__':
69+
json_data = client.loop.run_until_complete(main())
70+
display()
71+
for each in json_data:
72+
print(f"🔸 @{each} is {'🟢' if json_data[each] else '🔴'}")
73+
client.loop.run_until_complete(edit_message(json_data))
74+
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)
77+
78+
print()
79+
print('::::::::::::::::::::: 🎉 Action completed successfully 🎉 :::::::::::::::::::::')
80+
print('Mind joining @j_projects at Telegram and do follow me on github.com <jainamoswal>')
81+
82+

0 commit comments

Comments
 (0)