Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

Commit a3cdb76

Browse files
committed
Initial Commit
1 parent c313ddc commit a3cdb76

16 files changed

+1144
-49
lines changed

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: python -m WebStreamer

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<h1 align="center">Telegram File Stream Bot</h3>
22
<p align="center">
3-
<a href="https://github.com/EverythingSuckz/TG-FileStreamBot">
4-
<img src="https://socialify.git.ci/EverythingSuckz/TG-FileStreamBot/image?description=1&font=Source%20Code%20Pro&forks=1&issues=1&logo=https%3A%2F%2Fwww.flaticon.com%2Fpremium-icon%2Ficons%2Fsvg%2F2321%2F2321089.svg&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Dark" alt="Cover Image" width="650">
3+
<a href="https://github.com/DeekshithSH/FileStreamBot">
4+
<img src="https://socialify.git.ci/DeekshithSH/FileStreamBot/image?description=1&font=Source%20Code%20Pro&forks=1&issues=1&pattern=Charlie%20Brown&pulls=1&stargazers=1&theme=Dark" alt="FileStreamBot" width="640" height="320" />
55
</a>
66
<p align="center">
77
A Telegram bot to stream files to web
88
<br />
99
<a href="https://telegram.dog/TG_FileStreamBot"><strong>Demo Bot »</strong></a>
1010
<br />
11-
<a href="https://github.com/EverythingSuckz/TG-FileStreamBot/issues">Report a Bug</a>
11+
<a href="https://github.com/DeekshithSH/FileStreamBot/issues">Report a Bug</a>
1212
|
13-
<a href="https://github.com/EverythingSuckz/TG-FileStreamBot/issues">Request Feature</a>
13+
<a href="https://github.com/DeekshithSH/FileStreamBot/issues">Request Feature</a>
1414
</p>
1515
</p>
1616

@@ -47,7 +47,7 @@
4747
## About This Bot
4848

4949
<p align="center">
50-
<a herf="https://github.com/EverythingSuckz/TG-FileStreamBot">
50+
<a herf="https://github.com/DeekshithSH/FileStreamBot">
5151
<img src="https://www.flaticon.com/premium-icon/icons/svg/2626/2626281.svg" height="100" width="100" alt="Telegram Logo">
5252
</a>
5353
</p>
@@ -67,15 +67,15 @@ Either you could locally host or deploy on [Heroku](https://heroku.com)
6767

6868
Press the below button to fast deploy to Heroku
6969

70-
- [![Deploy To Heroku](https://www.herokucdn.com/deploy/button.svg)](https://github.com/eyMarv/ultraMarv-roku)
70+
- [![Deploy To Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
7171

7272
then goto the <a href="#mandatory-vars">variables tab</a> for more info on setting up environmental variables.
7373

7474
### Host it on VPS or Locally
7575

7676
```sh
77-
git clone https://github.com/EverythingSuckz/TG-FileStreamBot
78-
cd TG-FileStreamBot
77+
git clone https://github.com/DeekshithSH/FileStreamBot
78+
cd FileStreamBot
7979
virtualenv -p /usr/bin/python3 venv
8080
. ./venv/bin/activate
8181
pip install -r requirements.txt
@@ -163,12 +163,13 @@ Feel free to contribute to this project if you have any further ideas
163163
[![Telegram Channel](https://img.shields.io/static/v1?label=Join&message=Telegram%20Channel&color=blueviolet&style=for-the-badge&logo=telegram&logoColor=violet)](https://xn--r1a.click/WhySooSerious)
164164
[![Telegram Group](https://img.shields.io/static/v1?label=Join&message=Telegram%20Group&color=blueviolet&style=for-the-badge&logo=telegram&logoColor=violet)](https://xn--r1a.click/WhyThisUsername)
165165

166-
You can contact either via my [Telegram Group](https://xn--r1a.click/WhyThisUsername) ~~or you can PM me on [@EverythingSuckz](https://xn--r1a.click/EverythingSuckz)~~
166+
You can contact either via my [Telegram Group](https://xn--r1a.click/WhyThisUsername) ~~or you can PM me on [@DeekshithSH](https://xn--r1a.click/DeekshithSH)~~
167+
167168

168169
## Credits
169170

170171
- Me
171172
- [eyaadh](https://github.com/eyaadh) for his awesome [Megatron Bot](https://github.com/eyaadh/megadlbot_oss).
172173
- [BlackStone](https://github.com/eyMarv) for adding multi-client support.
173174
- [Dan Tès](https://telegram.dog/haskell) for his [Pyrogram Library](https://github.com/pyrogram/pyrogram)
174-
- [TheHamkerCat](https://github.com/TheHamkerCat) for helping me with my common doubts.
175+
- [TheHamkerCat](https://github.com/TheHamkerCat) for helping me with my common doubts.

WebStreamer/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
logging.basicConfig(
1717
level=logging.INFO,
1818
datefmt="%d/%m/%Y %H:%M:%S",
19-
format="[%(asctime)s][%(levelname)s] => %(message)s",
19+
format='[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
2020
handlers=[logging.StreamHandler(stream=sys.stdout),
2121
logging.FileHandler("streambot.log", mode="a", encoding="utf-8")],)
2222

WebStreamer/bot/clients.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ async def start_client(client_id, token):
2424
await asyncio.sleep(2)
2525
print("This will take some time, please wait...")
2626
client = await Client(
27-
session_name=":memory:",
27+
session_name=token,
2828
api_id=Var.API_ID,
2929
api_hash=Var.API_HASH,
30-
bot_token=token,
30+
# bot_token=token,
3131
sleep_threshold=Var.SLEEP_THRESHOLD,
3232
no_updates=True,
3333
).start()

WebStreamer/bot/plugins/admin.py

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# (c) @Avishkarpatil
2+
3+
import os
4+
import time
5+
import string
6+
import random
7+
import asyncio
8+
import aiofiles
9+
import datetime
10+
from WebStreamer.utils.broadcast_helper import send_msg
11+
from WebStreamer.utils.database import Database
12+
from WebStreamer.bot import StreamBot
13+
from WebStreamer.vars import Var
14+
from pyrogram import filters, Client
15+
from pyrogram.types import Message
16+
db = Database(Var.DATABASE_URL, Var.SESSION_NAME)
17+
broadcast_ids = {}
18+
19+
20+
@StreamBot.on_message(filters.command("status") & filters.private & filters.user(Var.OWNER_ID) & ~filters.edited)
21+
async def sts(c: Client, m: Message):
22+
total_users = await db.total_users_count()
23+
banned_users = await db.total_banned_users_count()
24+
await m.reply_text(text=f"**Total Users in DB:** `{total_users}` \n**Banned Users in DB:** `{banned_users}`", parse_mode="Markdown", quote=True)
25+
26+
@StreamBot.on_message(filters.command("ban") & filters.private & filters.user(Var.OWNER_ID) & ~filters.edited)
27+
async def sts(b, m: Message):
28+
id = m.text.split("/ban ")[-1]
29+
if not await db.is_user_banned(int(id)):
30+
await db.ban_user(int(id))
31+
if await db.is_user_banned(int(id)):
32+
await m.reply_text(text=f"`{id}`** is Banned** ", parse_mode="Markdown", quote=True)
33+
await b.send_message(
34+
chat_id=id,
35+
text="**Your Banned to Use The Bot**",
36+
parse_mode="markdown",
37+
disable_web_page_preview=True
38+
)
39+
else:
40+
await m.reply_text(text=f"**can't ban **`{id}`** something went wrong** ", parse_mode="Markdown", quote=True)
41+
else:
42+
await m.reply_text(text=f"`{id}`** is Already Banned** ", parse_mode="Markdown", quote=True)
43+
44+
@StreamBot.on_message(filters.command("unban") & filters.private & filters.user(Var.OWNER_ID) & ~filters.edited)
45+
async def sts(b, m: Message):
46+
47+
id = m.text.split("/unban ")[-1]
48+
if await db.is_user_banned(int(id)):
49+
await db.unban_user(int(id))
50+
if not await db.is_user_banned(int(id)):
51+
await m.reply_text(text=f"`{id}`** is Unbanned** ", parse_mode="Markdown", quote=True)
52+
await b.send_message(
53+
chat_id=id,
54+
text="**Your Unbanned now Use can use The Bot**",
55+
parse_mode="markdown",
56+
disable_web_page_preview=True
57+
)
58+
else:
59+
await m.reply_text(text=f"**can't unban **`{id}`** something went wrong** ", parse_mode="Markdown", quote=True)
60+
else:
61+
await m.reply_text(text=f"`{id}`** is not Banned** ", parse_mode="Markdown", quote=True)
62+
63+
@StreamBot.on_message(filters.command("broadcast") & filters.private & filters.user(Var.OWNER_ID) & filters.reply & ~filters.edited)
64+
async def broadcast_(c, m):
65+
all_users = await db.get_all_users()
66+
broadcast_msg = m.reply_to_message
67+
while True:
68+
broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)])
69+
if not broadcast_ids.get(broadcast_id):
70+
break
71+
out = await m.reply_text(
72+
text=f"Broadcast initiated! You will be notified with log file when all the users are notified."
73+
)
74+
start_time = time.time()
75+
total_users = await db.total_users_count()
76+
done = 0
77+
failed = 0
78+
success = 0
79+
broadcast_ids[broadcast_id] = dict(
80+
total=total_users,
81+
current=done,
82+
failed=failed,
83+
success=success
84+
)
85+
async with aiofiles.open('broadcast.txt', 'w') as broadcast_log_file:
86+
async for user in all_users:
87+
sts, msg = await send_msg(
88+
user_id=int(user['id']),
89+
message=broadcast_msg
90+
)
91+
if msg is not None:
92+
await broadcast_log_file.write(msg)
93+
if sts == 200:
94+
success += 1
95+
else:
96+
failed += 1
97+
if sts == 400:
98+
await db.delete_user(user['id'])
99+
done += 1
100+
if broadcast_ids.get(broadcast_id) is None:
101+
break
102+
else:
103+
broadcast_ids[broadcast_id].update(
104+
dict(
105+
current=done,
106+
failed=failed,
107+
success=success
108+
)
109+
)
110+
if broadcast_ids.get(broadcast_id):
111+
broadcast_ids.pop(broadcast_id)
112+
completed_in = datetime.timedelta(seconds=int(time.time() - start_time))
113+
await asyncio.sleep(3)
114+
await out.delete()
115+
if failed == 0:
116+
await m.reply_text(
117+
text=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
118+
quote=True
119+
)
120+
else:
121+
await m.reply_document(
122+
document='broadcast.txt',
123+
caption=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
124+
quote=True
125+
)
126+
os.remove('broadcast.txt')

0 commit comments

Comments
 (0)