-
Notifications
You must be signed in to change notification settings - Fork 3
/
bot.py
55 lines (49 loc) · 1.74 KB
/
bot.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
import asyncio, os, requests, json
from pyrogram import Client
from pyrogram.errors import FloodWait
API_HASH = os.environ['API_HASH']
APP_ID = int(os.environ['APP_ID'])
CHANNELS = os.environ['CHANNELS']
STRING_SESSION = os.environ['STRING_SESSION']
CHANNELS = [i for i in CHANNELS.split(' ')]
MSG_ID = int(os.environ['MSG_ID'])
COUNTS_EDIT_CHANNEL = os.environ['COUNTS_EDIT_CHANNEL']
# Running bot
xbot = Client(api_id=APP_ID, api_hash=API_HASH, session_name=STRING_SESSION)
# Helper
def getdicks(channel):
url = f'https://tglivesubsapi.vercel.app/getsubs/{channel}'
try:
x = json.loads(requests.get(url).text)
except Exception:
return '0', f'Channel Not Found ({channel})'
if 'members' in x['subs']:
subs = x['subs'].split('members', 1)[0]
return subs, x['channel_name']
return x['subs'], x['channel_name']
# Main script
async def runbot():
async with xbot:
while True:
print("Checking")
toprint = '**Subsriber Count**\n\n'
for channel in CHANNELS:
ch = getdicks(channel)
CH_TITLE = ch[1]
CH_MCOUNT = str('{0:,}'.format(int(ch[0])))
CH_USERNAME = channel
toprint += f'<a href=https://t.me/{CH_USERNAME}>{CH_TITLE}</a>: `{CH_MCOUNT}`\n'
me = await xbot.get_me()
toprint += f'\nBy <a href=tg://user?id={str(me.id)}>{me.first_name}</a>'
f = await xbot.get_messages(COUNTS_EDIT_CHANNEL, MSG_ID)
if f.text.html == toprint:
print('Checked')
else:
try:
await xbot.edit_message_text(COUNTS_EDIT_CHANNEL, MSG_ID, toprint, disable_web_page_preview=True)
except FloodWait as e:
print(f'FloodWait: Sleeping for {str(e.x)} seconds')
await asyncio.sleep(e.x)
pass
print('Checked')
xbot.run(runbot())