Skip to content

Commit

Permalink
Merge pull request #37 from SHABIN-K/main
Browse files Browse the repository at this point in the history
📂✅️
  • Loading branch information
SHABIN-K authored Sep 6, 2021
2 parents 7c68ed6 + c18f532 commit 41f34b0
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"description": "Optional: start message of bot, use HTML parsemode format",
"value": "Hello {first}\n\nI can store private files in Specified Channel and other users can access it from special link."
},
"FORCE_SUB_MESSAGE": {
"description": "Optional: Force Sub message of bot, use HTML parsemode format",
"value": "Hello {first}\n\n<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>"
},
"ADMINS": {
"description": "A space separated list of user_ids of Admins, they can only create links",
"value": "",
Expand Down
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
except ValueError:
raise Exception("Your Admins list does not contain valid integers.")

#Force sub message
FORCE_MSG = os.environ.get("FORCE_SUB_MESSAGE", "Hello {first}\n\n<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>")

#set your Custom Caption here, Keep None for Disable Custom Caption
CUSTOM_CAPTION = os.environ.get("CUSTOM_CAPTION", None)

Expand Down
27 changes: 20 additions & 7 deletions plugins/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyrogram.errors import FloodWait

from bot import Bot
from config import ADMINS, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON
from config import ADMINS, FORCE_MSG, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON
from helper_func import subscribed, encode, decode, get_messages
from database.support import users_info
from database.sql import add_user, query_msg
Expand Down Expand Up @@ -112,16 +112,29 @@ async def start_command(client: Client, message: Message):

@Bot.on_message(filters.command('start') & filters.private)
async def not_joined(client: Client, message: Message):
text = "<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>"
message_text = message.text
try_url = message.text
try:
command, argument = message_text.split()
text = text + f" <b>and <a href='https://t.me/{client.username}?start={argument}'>try again</a></b>"
command, argument = try_url.split()
text = f"https://t.me/{client.username}?start={argument}"
except ValueError:
pass
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Join Channel", url = client.invitelink)]])
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("Join Channel", url =client.invitelink),
InlineKeyboardButton("🔃Try Again", url =try_url)
]
]
)

await message.reply(
text = text,
text = FORCE_MSG.format(
first = message.from_user.first_name,
last = message.from_user.last_name,
username = None if not message.from_user.username else '@' + message.from_user.username,
mention = message.from_user.mention,
id = message.from_user.id
),
reply_markup = reply_markup,
quote = True,
disable_web_page_preview = True
Expand Down
167 changes: 167 additions & 0 deletions start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#(©)Codexbotz
import os
import asyncio
from pyrogram import Client, filters, __version__
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.errors import FloodWait

from bot import Bot
from config import ADMINS, FORCE_MSG, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON
from helper_func import subscribed, encode, decode, get_messages
from database.support import users_info
from database.sql import add_user, query_msg


#=====================================================================================##

USERS_LIST = """<b>⭕️Total:</b>\n\n⭕️Subscribers - {}\n⭕️Blocked- {}"""

WAIT_MSG = """"<b>Processing ...</b>"""

REPLY_ERROR = """<code>Use this command as a replay to any telegram message with out any spaces.</code>"""


#=====================================================================================##


@Bot.on_message(filters.command('start') & filters.private & subscribed)
async def start_command(client: Client, message: Message):
id = message.from_user.id
user_name = '@' + message.from_user.username if message.from_user.username else None
await add_user(id, user_name)
text = message.text
if len(text)>7:
try:
base64_string = text.split(" ", 1)[1]
except:
return
string = await decode(base64_string)
argument = string.split("-")
if len(argument) == 3:
try:
start = int(int(argument[1]) / abs(client.db_channel.id))
end = int(int(argument[2]) / abs(client.db_channel.id))
except:
return
if start <= end:
ids = range(start,end+1)
else:
ids = []
i = start
while True:
ids.append(i)
i -= 1
if i < end:
break
elif len(argument) == 2:
try:
ids = [int(int(argument[1]) / abs(client.db_channel.id))]
except:
return
temp_msg = await message.reply("Please wait...")
try:
messages = await get_messages(client, ids)
except:
await message.reply_text("Something went wrong..!")
return
await temp_msg.delete()

for msg in messages:

if bool(CUSTOM_CAPTION) & bool(msg.document):
caption = CUSTOM_CAPTION.format(previouscaption = "" if not msg.caption else msg.caption.html, filename = msg.document.file_name)
else:
caption = "" if not msg.caption else msg.caption.html

if DISABLE_CHANNEL_BUTTON:
reply_markup = msg.reply_markup
else:
reply_markup = None

try:
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = 'html', reply_markup = reply_markup)
await asyncio.sleep(0.5)
except FloodWait as e:
await asyncio.sleep(e.x)
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = 'html', reply_markup = reply_markup)
except:
pass
return
else:
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("😊 About Me", callback_data = "about"),
InlineKeyboardButton("🔒 Close", callback_data = "close")
]
]
)
await message.reply_text(
text = START_MSG.format(
first = message.from_user.first_name,
last = message.from_user.last_name,
username = None if not message.from_user.username else '@' + message.from_user.username,
mention = message.from_user.mention,
id = message.from_user.id
),
reply_markup = reply_markup,
disable_web_page_preview = True,
quote = True
)
return

@Bot.on_message(filters.command('start') & filters.private)
async def not_joined(client: Client, message: Message):
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Join Channel", url = client.invitelink)]])
await message.reply(
text = FORCE_MSG.format(
first = message.from_user.first_name,
last = message.from_user.last_name,
username = None if not message.from_user.username else '@' + message.from_user.username,
mention = message.from_user.mention,
id = message.from_user.id
),
reply_markup = reply_markup,
quote = True,
disable_web_page_preview = True
)

@Bot.on_message(filters.private & filters.command('users'))
async def subscribers_count(bot, m: Message):
id = m.from_user.id
if id not in ADMINS:
return
msg = await m.reply_text(WAIT_MSG)
messages = await users_info(bot)
active = messages[0]
blocked = messages[1]
await m.delete()
await msg.edit(USERS_LIST.format(active, blocked))



@Bot.on_message(filters.private & filters.command('broadcast'))
async def send_text(bot, m: Message):
id = m.from_user.id
if id not in ADMINS:
return
if (" " not in m.text) and ("broadcast" in m.text) and (m.reply_to_message is not None):
query = await query_msg()
for row in query:
chat_id = int(row[0])
try:
await bot.copy_message(
chat_id=chat_id,
from_chat_id=m.chat.id,
message_id=m.reply_to_message.message_id,
caption=m.caption,
reply_markup=m.reply_markup
)
except FloodWait as e:
await asyncio.sleep(e.x)
except Exception:
pass
else:
msg = await m.reply_text(REPLY_ERROR, m.message_id)
await asyncio.sleep(8)
await msg.delete()

0 comments on commit 41f34b0

Please sign in to comment.