Skip to content

Commit

Permalink
Pyrogram v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DeekshithSH committed May 28, 2022
1 parent 58fe5ac commit 87e0fc1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
2 changes: 1 addition & 1 deletion WebStreamer/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ..vars import Var

StreamBot = Client(
session_name='Web Streamer',
name='Web Streamer',
api_id=Var.API_ID,
api_hash=Var.API_HASH,
bot_token=Var.BOT_TOKEN,
Expand Down
7 changes: 4 additions & 3 deletions WebStreamer/bot/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
from WebStreamer.vars import Var
from pyrogram import filters, Client
from pyrogram.types import Message
from pyrogram.enums.parse_mode import ParseMode
db = Database(Var.DATABASE_URL, Var.SESSION_NAME)
broadcast_ids = {}


@StreamBot.on_message(filters.command("status") & filters.private & filters.user(Var.OWNER_ID) & ~filters.edited)
@StreamBot.on_message(filters.command("status") & filters.private & filters.user(Var.OWNER_ID))
async def sts(c: Client, m: Message):
total_users = await db.total_users_count()
await m.reply_text(text=f"**Total Users in DB:** `{total_users}`", parse_mode="Markdown", quote=True)
await m.reply_text(text=f"**Total Users in DB:** `{total_users}`", parse_mode=ParseMode.MARKDOWN, quote=True)


@StreamBot.on_message(filters.command("broadcast") & filters.private & filters.user(Var.OWNER_ID) & filters.reply & ~filters.edited)
@StreamBot.on_message(filters.command("broadcast") & filters.private & filters.user(Var.OWNER_ID) & filters.reply)
async def broadcast_(c, m):
all_users = await db.get_all_users()
broadcast_msg = m.reply_to_message
Expand Down
33 changes: 17 additions & 16 deletions WebStreamer/bot/plugins/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pyrogram import filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.errors import UserNotParticipant
from pyrogram.enums.parse_mode import ParseMode

db = Database(Var.DATABASE_URL, Var.SESSION_NAME)

Expand Down Expand Up @@ -95,7 +96,7 @@ def get_media_file_name(m):
return None


@StreamBot.on_message(filters.command('start') & filters.private & ~filters.edited)
@StreamBot.on_message(filters.command('start') & filters.private)
async def start(b, m):
if not await db.is_user_exist(m.from_user.id):
await db.add_user(m.from_user.id)
Expand All @@ -112,7 +113,7 @@ async def start(b, m):
await b.send_message(
chat_id=m.chat.id,
text="__Sᴏʀʀʏ Sɪʀ, Yᴏᴜ ᴀʀᴇ Bᴀɴɴᴇᴅ ᴛᴏ ᴜsᴇ ᴍᴇ. Cᴏɴᴛᴀᴄᴛ ᴛʜᴇ Dᴇᴠᴇʟᴏᴘᴇʀ__\n\n @AvishkarPatil **Tʜᴇʏ Wɪʟʟ Hᴇʟᴘ Yᴏᴜ**",
parse_mode="markdown",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True
)
return
Expand All @@ -125,19 +126,19 @@ async def start(b, m):
InlineKeyboardButton("Jᴏɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Var.UPDATES_CHANNEL}")
]]
),
parse_mode="HTML"
parse_mode=ParseMode.HTML
)
return
except Exception:
await b.send_message(
chat_id=m.chat.id,
text="<i>Sᴏᴍᴇᴛʜɪɴɢ ᴡʀᴏɴɢ ᴄᴏɴᴛᴀᴄᴛ ᴍʏ ᴅᴇᴠᴇʟᴏᴘᴇʀ</i> <b><a href='http://t.me/Avishkarpatil'>[ ᴄʟɪᴄᴋ ʜᴇʀᴇ ]</a></b>",
parse_mode="HTML",
parse_mode=ParseMode.HTML,
disable_web_page_preview=True)
return
await m.reply_text(
text=START_TEXT.format(m.from_user.mention),
parse_mode="HTML",
parse_mode=ParseMode.HTML,
disable_web_page_preview=True,
reply_markup=START_BUTTONS
)
Expand All @@ -151,7 +152,7 @@ async def start(b, m):
await b.send_message(
chat_id=m.chat.id,
text="**Sᴏʀʀʏ Sɪʀ, Yᴏᴜ ᴀʀᴇ Bᴀɴɴᴇᴅ ᴛᴏ ᴜsᴇ ᴍᴇ. Qᴜɪᴄᴋʟʏ ᴄᴏɴᴛᴀᴄᴛ** @Avishkarpatil",
parse_mode="markdown",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True
)
return
Expand All @@ -166,25 +167,25 @@ async def start(b, m):

]]
),
parse_mode="markdown"
parse_mode=ParseMode.MARKDOWN
)
return
except Exception:
await b.send_message(
chat_id=m.chat.id,
text="**Sᴏᴍᴇᴛʜɪɴɢ ᴡᴇɴᴛ Wʀᴏɴɢ. Cᴏɴᴛᴀᴄᴛ ᴍᴇ** [Aᴠɪsʜᴋᴀʀ Pᴀᴛɪʟ](https://t.me/Avishkarpatil).",
parse_mode="markdown",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True)
return

get_msg = await b.get_messages(chat_id=Var.BIN_CHANNEL, message_ids=int(usr_cmd))
file_name = get_media_file_name(get_msg)
file_size = humanbytes(get_media_file_size(get_msg))

stream_link = "https://{}/{}/{}".format(Var.FQDN, get_msg.message_id, file_name) if Var.ON_HEROKU or Var.NO_PORT else \
stream_link = "https://{}/{}/{}".format(Var.FQDN, get_msg.id, file_name) if Var.ON_HEROKU or Var.NO_PORT else \
"http://{}:{}/{}/{}".format(Var.FQDN,
Var.PORT,
get_msg.message_id,
get_msg.id,
file_name)

msg_text ="""
Expand All @@ -198,7 +199,7 @@ async def start(b, m):

await m.reply_text(
text=msg_text.format(file_name, file_size, stream_link),
parse_mode="HTML",
parse_mode=ParseMode.HTML,
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ɴᴏᴡ 📥", url=stream_link)]])
)

Expand All @@ -213,7 +214,7 @@ async def start(bot, update):
)


@StreamBot.on_message(filters.command('help') & filters.private & ~filters.edited)
@StreamBot.on_message(filters.command('help') & filters.private)
async def help_handler(bot, message):
if not await db.is_user_exist(message.from_user.id):
await db.add_user(message.from_user.id)
Expand All @@ -228,7 +229,7 @@ async def help_handler(bot, message):
await bot.send_message(
chat_id=message.chat.id,
text="<i>Sᴏʀʀʏ Sɪʀ, Yᴏᴜ ᴀʀᴇ Bᴀɴɴᴇᴅ ᴛᴏ ᴜsᴇ ᴍᴇ. Cᴏɴᴛᴀᴄᴛ ᴛʜᴇ Dᴇᴠᴇʟᴏᴘᴇʀ</i>",
parse_mode="HTML",
parse_mode=ParseMode.HTML,
disable_web_page_preview=True
)
return
Expand All @@ -241,19 +242,19 @@ async def help_handler(bot, message):
InlineKeyboardButton("🤖 Jᴏɪɴ Uᴘᴅᴀᴛᴇs Cʜᴀɴɴᴇʟ", url=f"https://t.me/{Var.UPDATES_CHANNEL}")
]]
),
parse_mode="markdown"
parse_mode=ParseMode.MARKDOWN
)
return
except Exception:
await bot.send_message(
chat_id=message.chat.id,
text="__Sᴏᴍᴇᴛʜɪɴɢ ᴡᴇɴᴛ Wʀᴏɴɢ. Cᴏɴᴛᴀᴄᴛ ᴍᴇ__ [Aᴠɪsʜᴋᴀʀ Pᴀᴛɪʟ](https://t.me/Avishkarpatil).",
parse_mode="markdown",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True)
return
await message.reply_text(
text=HELP_TEXT,
parse_mode="HTML",
parse_mode=ParseMode.HTML,
disable_web_page_preview=True,
reply_markup=HELP_BUTTONS
)
Expand Down
41 changes: 21 additions & 20 deletions WebStreamer/bot/plugins/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pyrogram import filters, Client
from pyrogram.errors import FloodWait, UserNotParticipant
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.enums.parse_mode import ParseMode
db = Database(Var.DATABASE_URL, Var.SESSION_NAME)


Expand All @@ -30,7 +31,7 @@ def get_media_file_name(m):
return None


@StreamBot.on_message(filters.private & (filters.document | filters.video | filters.audio) & ~filters.edited, group=4)
@StreamBot.on_message(filters.private & (filters.document | filters.video | filters.audio), group=4)
async def private_receive_handler(c: Client, m: Message):
if not await db.is_user_exist(m.from_user.id):
await db.add_user(m.from_user.id)
Expand All @@ -45,7 +46,7 @@ async def private_receive_handler(c: Client, m: Message):
await c.send_message(
chat_id=m.chat.id,
text="__Sᴏʀʀʏ Sɪʀ, Yᴏᴜ ᴀʀᴇ Bᴀɴɴᴇᴅ ᴛᴏ ᴜsᴇ ᴍᴇ.__\n\n **Cᴏɴᴛᴀᴄᴛ Dᴇᴠᴇʟᴏᴘᴇʀ @Avishkarpatil Tʜᴇʏ Wɪʟʟ Hᴇʟᴘ Yᴏᴜ**",
parse_mode="markdown",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True
)
return
Expand All @@ -56,24 +57,24 @@ async def private_receive_handler(c: Client, m: Message):
reply_markup=InlineKeyboardMarkup(
[[ InlineKeyboardButton("Jᴏɪɴ ɴᴏᴡ 🔓", url=f"https://t.me/{Var.UPDATES_CHANNEL}") ]]
),
parse_mode="HTML"
parse_mode=ParseMode.HTML
)
return
except Exception:
await c.send_message(
chat_id=m.chat.id,
text="**Sᴏᴍᴇᴛʜɪɴɢ ᴡᴇɴᴛ Wʀᴏɴɢ. Cᴏɴᴛᴀᴄᴛ ᴍʏ ʙᴏss** @Avishkarpatil",
parse_mode="markdown",
parse_mode=ParseMode.MARKDOWN,
disable_web_page_preview=True)
return
try:
log_msg = await m.forward(chat_id=Var.BIN_CHANNEL)
file_name = get_media_file_name(m)
file_size = humanbytes(get_media_file_size(m))
stream_link = "https://{}/{}/{}".format(Var.FQDN, log_msg.message_id, file_name) if Var.ON_HEROKU or Var.NO_PORT else \
stream_link = "https://{}/{}/{}".format(Var.FQDN, log_msg.id, file_name) if Var.ON_HEROKU or Var.NO_PORT else \
"http://{}:{}/{}/{}".format(Var.FQDN,
Var.PORT,
log_msg.message_id,
log_msg.id,
file_name)

msg_text ="""
Expand All @@ -84,50 +85,50 @@ async def private_receive_handler(c: Client, m: Message):
<b>🚸 Nᴏᴛᴇ : Tʜɪs ᴘᴇʀᴍᴀɴᴇɴᴛ Lɪɴᴋ, Nᴏᴛ Exᴘɪʀᴇᴅ</b>\n
<i>© @AvishkarPatil </i>"""

await log_msg.reply_text(text=f"**RᴇQᴜᴇꜱᴛᴇᴅ ʙʏ :** [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n**Uꜱᴇʀ ɪᴅ :** `{m.from_user.id}`\n**Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ :** {stream_link}", disable_web_page_preview=True, parse_mode="Markdown", quote=True)
await log_msg.reply_text(text=f"**RᴇQᴜᴇꜱᴛᴇᴅ ʙʏ :** [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n**Uꜱᴇʀ ɪᴅ :** `{m.from_user.id}`\n**Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ :** {stream_link}", disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN, quote=True)
await m.reply_text(
text=msg_text.format(file_name, file_size, stream_link),
parse_mode="HTML",
parse_mode=ParseMode.HTML,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ɴᴏᴡ 📥", url=stream_link)]]),
quote=True
)
except FloodWait as e:
print(f"Sleeping for {str(e.x)}s")
await asyncio.sleep(e.x)
await c.send_message(chat_id=Var.BIN_CHANNEL, text=f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(e.x)}s from [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n\n**𝚄𝚜𝚎𝚛 𝙸𝙳 :** `{str(m.from_user.id)}`", disable_web_page_preview=True, parse_mode="Markdown")
await c.send_message(chat_id=Var.BIN_CHANNEL, text=f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(e.x)}s from [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n\n**𝚄𝚜𝚎𝚛 𝙸𝙳 :** `{str(m.from_user.id)}`", disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)


@StreamBot.on_message(filters.channel & (filters.document | filters.video) & ~filters.edited, group=-1)
@StreamBot.on_message(filters.channel & (filters.document | filters.video), group=-1)
async def channel_receive_handler(bot, broadcast):
if int(broadcast.chat.id) in Var.BANNED_CHANNELS:
await bot.leave_chat(broadcast.chat.id)
return
try:
log_msg = await broadcast.forward(chat_id=Var.BIN_CHANNEL)
stream_link = "https://{}/{}".format(Var.FQDN, log_msg.message_id) if Var.ON_HEROKU or Var.NO_PORT else \
stream_link = "https://{}/{}".format(Var.FQDN, log_msg.id) if Var.ON_HEROKU or Var.NO_PORT else \
"http://{}:{}/{}".format(Var.FQDN,
Var.PORT,
log_msg.message_id)
log_msg.id)
await log_msg.reply_text(
text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.message_id)}",
# text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}",
text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.id)}",
# text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.id)}",
quote=True,
parse_mode="Markdown"
parse_mode=ParseMode.MARKDOWN
)
await bot.edit_message_reply_markup(
chat_id=broadcast.chat.id,
message_id=broadcast.message_id,
message_id=broadcast.id,
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.message_id)}")]])
# [[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}")]])
[[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.id)}")]])
# [[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.id)}")]])
)
except FloodWait as w:
print(f"Sleeping for {str(w.x)}s")
await asyncio.sleep(w.x)
await bot.send_message(chat_id=Var.BIN_CHANNEL,
text=f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(w.x)}s from {broadcast.chat.title}\n\n**Cʜᴀɴɴᴇʟ ID:** `{str(broadcast.chat.id)}`",
disable_web_page_preview=True, parse_mode="Markdown")
disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)
except Exception as e:
await bot.send_message(chat_id=Var.BIN_CHANNEL, text=f"**#ᴇʀʀᴏʀ_ᴛʀᴀᴄᴇʙᴀᴄᴋ:** `{e}`", disable_web_page_preview=True, parse_mode="Markdown")
await bot.send_message(chat_id=Var.BIN_CHANNEL, text=f"**#ᴇʀʀᴏʀ_ᴛʀᴀᴄᴇʙᴀᴄᴋ:** `{e}`", disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)
print(f"Cᴀɴ'ᴛ Eᴅɪᴛ Bʀᴏᴀᴅᴄᴀsᴛ Mᴇssᴀɢᴇ!\nEʀʀᴏʀ: {e}")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pyrogram<=1.4.16
pyrogram>=2.0.0,<=2.0.26
tgcrypto<=1.2.3
aiohttp<=3.8.1
python-dotenv<=0.20.0
Expand Down

0 comments on commit 87e0fc1

Please sign in to comment.