Skip to content

Commit 41f34b0

Browse files
authored
Merge pull request #37 from SHABIN-K/main
📂✅️
2 parents 7c68ed6 + c18f532 commit 41f34b0

File tree

4 files changed

+194
-7
lines changed

4 files changed

+194
-7
lines changed

app.json

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
"description": "Optional: start message of bot, use HTML parsemode format",
3838
"value": "Hello {first}\n\nI can store private files in Specified Channel and other users can access it from special link."
3939
},
40+
"FORCE_SUB_MESSAGE": {
41+
"description": "Optional: Force Sub message of bot, use HTML parsemode format",
42+
"value": "Hello {first}\n\n<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>"
43+
},
4044
"ADMINS": {
4145
"description": "A space separated list of user_ids of Admins, they can only create links",
4246
"value": "",

config.py

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
except ValueError:
3535
raise Exception("Your Admins list does not contain valid integers.")
3636

37+
#Force sub message
38+
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>")
39+
3740
#set your Custom Caption here, Keep None for Disable Custom Caption
3841
CUSTOM_CAPTION = os.environ.get("CUSTOM_CAPTION", None)
3942

plugins/start.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pyrogram.errors import FloodWait
77

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

113113
@Bot.on_message(filters.command('start') & filters.private)
114114
async def not_joined(client: Client, message: Message):
115-
text = "<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>"
116-
message_text = message.text
115+
try_url = message.text
117116
try:
118-
command, argument = message_text.split()
119-
text = text + f" <b>and <a href='https://t.me/{client.username}?start={argument}'>try again</a></b>"
117+
command, argument = try_url.split()
118+
text = f"https://t.me/{client.username}?start={argument}"
120119
except ValueError:
121120
pass
122-
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Join Channel", url = client.invitelink)]])
121+
reply_markup = InlineKeyboardMarkup(
122+
[
123+
[
124+
InlineKeyboardButton("Join Channel", url =client.invitelink),
125+
InlineKeyboardButton("🔃Try Again", url =try_url)
126+
]
127+
]
128+
)
129+
123130
await message.reply(
124-
text = text,
131+
text = FORCE_MSG.format(
132+
first = message.from_user.first_name,
133+
last = message.from_user.last_name,
134+
username = None if not message.from_user.username else '@' + message.from_user.username,
135+
mention = message.from_user.mention,
136+
id = message.from_user.id
137+
),
125138
reply_markup = reply_markup,
126139
quote = True,
127140
disable_web_page_preview = True

start.py

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#(©)Codexbotz
2+
import os
3+
import asyncio
4+
from pyrogram import Client, filters, __version__
5+
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
6+
from pyrogram.errors import FloodWait
7+
8+
from bot import Bot
9+
from config import ADMINS, FORCE_MSG, START_MSG, OWNER_ID, CUSTOM_CAPTION, DISABLE_CHANNEL_BUTTON
10+
from helper_func import subscribed, encode, decode, get_messages
11+
from database.support import users_info
12+
from database.sql import add_user, query_msg
13+
14+
15+
#=====================================================================================##
16+
17+
USERS_LIST = """<b>⭕️Total:</b>\n\n⭕️Subscribers - {}\n⭕️Blocked- {}"""
18+
19+
WAIT_MSG = """"<b>Processing ...</b>"""
20+
21+
REPLY_ERROR = """<code>Use this command as a replay to any telegram message with out any spaces.</code>"""
22+
23+
24+
#=====================================================================================##
25+
26+
27+
@Bot.on_message(filters.command('start') & filters.private & subscribed)
28+
async def start_command(client: Client, message: Message):
29+
id = message.from_user.id
30+
user_name = '@' + message.from_user.username if message.from_user.username else None
31+
await add_user(id, user_name)
32+
text = message.text
33+
if len(text)>7:
34+
try:
35+
base64_string = text.split(" ", 1)[1]
36+
except:
37+
return
38+
string = await decode(base64_string)
39+
argument = string.split("-")
40+
if len(argument) == 3:
41+
try:
42+
start = int(int(argument[1]) / abs(client.db_channel.id))
43+
end = int(int(argument[2]) / abs(client.db_channel.id))
44+
except:
45+
return
46+
if start <= end:
47+
ids = range(start,end+1)
48+
else:
49+
ids = []
50+
i = start
51+
while True:
52+
ids.append(i)
53+
i -= 1
54+
if i < end:
55+
break
56+
elif len(argument) == 2:
57+
try:
58+
ids = [int(int(argument[1]) / abs(client.db_channel.id))]
59+
except:
60+
return
61+
temp_msg = await message.reply("Please wait...")
62+
try:
63+
messages = await get_messages(client, ids)
64+
except:
65+
await message.reply_text("Something went wrong..!")
66+
return
67+
await temp_msg.delete()
68+
69+
for msg in messages:
70+
71+
if bool(CUSTOM_CAPTION) & bool(msg.document):
72+
caption = CUSTOM_CAPTION.format(previouscaption = "" if not msg.caption else msg.caption.html, filename = msg.document.file_name)
73+
else:
74+
caption = "" if not msg.caption else msg.caption.html
75+
76+
if DISABLE_CHANNEL_BUTTON:
77+
reply_markup = msg.reply_markup
78+
else:
79+
reply_markup = None
80+
81+
try:
82+
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = 'html', reply_markup = reply_markup)
83+
await asyncio.sleep(0.5)
84+
except FloodWait as e:
85+
await asyncio.sleep(e.x)
86+
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = 'html', reply_markup = reply_markup)
87+
except:
88+
pass
89+
return
90+
else:
91+
reply_markup = InlineKeyboardMarkup(
92+
[
93+
[
94+
InlineKeyboardButton("😊 About Me", callback_data = "about"),
95+
InlineKeyboardButton("🔒 Close", callback_data = "close")
96+
]
97+
]
98+
)
99+
await message.reply_text(
100+
text = START_MSG.format(
101+
first = message.from_user.first_name,
102+
last = message.from_user.last_name,
103+
username = None if not message.from_user.username else '@' + message.from_user.username,
104+
mention = message.from_user.mention,
105+
id = message.from_user.id
106+
),
107+
reply_markup = reply_markup,
108+
disable_web_page_preview = True,
109+
quote = True
110+
)
111+
return
112+
113+
@Bot.on_message(filters.command('start') & filters.private)
114+
async def not_joined(client: Client, message: Message):
115+
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Join Channel", url = client.invitelink)]])
116+
await message.reply(
117+
text = FORCE_MSG.format(
118+
first = message.from_user.first_name,
119+
last = message.from_user.last_name,
120+
username = None if not message.from_user.username else '@' + message.from_user.username,
121+
mention = message.from_user.mention,
122+
id = message.from_user.id
123+
),
124+
reply_markup = reply_markup,
125+
quote = True,
126+
disable_web_page_preview = True
127+
)
128+
129+
@Bot.on_message(filters.private & filters.command('users'))
130+
async def subscribers_count(bot, m: Message):
131+
id = m.from_user.id
132+
if id not in ADMINS:
133+
return
134+
msg = await m.reply_text(WAIT_MSG)
135+
messages = await users_info(bot)
136+
active = messages[0]
137+
blocked = messages[1]
138+
await m.delete()
139+
await msg.edit(USERS_LIST.format(active, blocked))
140+
141+
142+
143+
@Bot.on_message(filters.private & filters.command('broadcast'))
144+
async def send_text(bot, m: Message):
145+
id = m.from_user.id
146+
if id not in ADMINS:
147+
return
148+
if (" " not in m.text) and ("broadcast" in m.text) and (m.reply_to_message is not None):
149+
query = await query_msg()
150+
for row in query:
151+
chat_id = int(row[0])
152+
try:
153+
await bot.copy_message(
154+
chat_id=chat_id,
155+
from_chat_id=m.chat.id,
156+
message_id=m.reply_to_message.message_id,
157+
caption=m.caption,
158+
reply_markup=m.reply_markup
159+
)
160+
except FloodWait as e:
161+
await asyncio.sleep(e.x)
162+
except Exception:
163+
pass
164+
else:
165+
msg = await m.reply_text(REPLY_ERROR, m.message_id)
166+
await asyncio.sleep(8)
167+
await msg.delete()

0 commit comments

Comments
 (0)