Skip to content

Commit f87514a

Browse files
authored
Merge pull request #7 from shahsad-klr/Beta
Main Changes * Added an Inline Button when posting on DB Channel to Share Link * Added /genlink Command to get Link of Already added Post * Added Force Subscribe 1. To Enable add your Force Sub Channel ID in FORCE_SUB_CHANNEL var 2. To Disable Keep it 0 3. If enabled make bot admin in your Force Sub Channel with Invite Users via Link Permission * Now admins can send Post Link instead of Forwarding when using /batch or /genlink * Increased Posts limit 1. Previously only got up to 200 posts with one link due to Telegram/Pyrogram Limitation 2. Now we added another method to get whole Posts with one link * Added a Simple Encryption method for Posts security 1. Just Multiplying Channel ID with message id for encryption 2. Doing reverse for decryption 3. This will not give higher security, but no one can access posts without link or the combination of channel id and message id * Some Bugs Fixed * Some Bugs Added 😌
2 parents 8d09f5c + 7216261 commit f87514a

File tree

10 files changed

+360
-168
lines changed

10 files changed

+360
-168
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ I Guess This Will Be Usefull For Many People.....😇.
3838

3939
### Setup
4040

41-
- Add the bot to channels with admin permission, and thats it!
41+
- Add the bot to Database Channel with all permission
42+
- Add bot to ForceSub channel as Admin with Invite Users via Link Permission if you enabled ForceSub
4243

4344
##
4445
### Installation
@@ -51,7 +52,7 @@ I Guess This Will Be Usefull For Many People.....😇.
5152
**Thanks to [Erich](https://t.me/ErichDaniken) and his [InFoTel](https://t.me/InFoTel_Group) for this Video**
5253

5354
#### Deploy in your VPS
54-
```
55+
```bash
5556
git clone https://github.com/CodeXBotz/File-Sharing-Bot
5657
cd File-Sharing-Bot
5758
pip3 install -r requirements.txt
@@ -63,9 +64,11 @@ python3 main.py
6364
### Admin Commands
6465

6566
```
66-
start -start the bot or get posts
67+
/start - start the bot or get posts
68+
69+
/batch - create link for more than one posts
6770
68-
batch -create link for more than one posts
71+
/genlink - create link for one post
6972
7073
```
7174

@@ -76,9 +79,9 @@ batch -create link for more than one posts
7679
* `TG_BOT_TOKEN` Your bot token from @BotFather
7780
* `OWNER_ID` Must enter Your Telegram Id
7881
* `CHANNEL_ID` Your Channel ID eg:- -100xxxxxxxx
79-
* `ADMINS` A space separated list of user_ids of Admins, they can only create links
80-
* `START_MESSAGE ` Optional: start message of bot, use HTML parsemode format
81-
82+
* `ADMINS` Optional: A space separated list of user_ids of Admins, they can only create links
83+
* `START_MESSAGE` Optional: start message of bot, use HTML parsemode format
84+
* `FORCE_SUB_CHANNEL` Optional: ForceSub Channel ID, leave 0 if you want disable force sub
8285

8386
## Support
8487
Join Our [Telegram Group](https://www.telegram.dog/codexbotzsupport) For Support/Assistance And Our [Channel](https://www.telegram.dog/codexbotz) For Updates.
@@ -88,7 +91,8 @@ Report Bugs, Give Feature Requests There..
8891
### Credits
8992

9093
- Thanks To Dan For His Awsome [Libary](https://github.com/pyrogram/pyrogram)
91-
- [codeXbotz™️](t.me/codexbotz)
94+
- Our Support Group Members
95+
9296
### Licence
9397
[![GNU GPLv3 Image](https://www.gnu.org/graphics/gplv3-127x51.png)](http://www.gnu.org/licenses/gpl-3.0.en.html)
9498

app.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
"value": ""
2828
},
2929
"CHANNEL_ID":{
30-
"description": "make a channel, then make the bot as admin in channel, and it's id",
30+
"description": "make a channel (database channel), then make the bot as admin in channel, and it's id",
3131
"value": "-100"
3232
},
33+
"FORCE_SUB_CHANNEL":{
34+
"description": "id of the channel or group, if you want enable force sub feature else put 0",
35+
"value": "0"
36+
},
3337
"START_MESSAGE": {
3438
"description": "Optional: start message of bot, use HTML parsemode format",
3539
"value": "Hello {firstname}\n\nI can store private files in Specified Channel and other users can access it from special link."

bot.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#(©)Codexbotz
2+
13
import pyromod.listen
24
from pyrogram import Client
5+
import sys
36

4-
from config import API_HASH, APP_ID, LOGGER, TG_BOT_TOKEN, TG_BOT_WORKERS
7+
from config import API_HASH, APP_ID, LOGGER, TG_BOT_TOKEN, TG_BOT_WORKERS, FORCE_SUB_CHANNEL, CHANNEL_ID
58

69
class Bot(Client):
710
def __init__(self):
@@ -20,6 +23,27 @@ def __init__(self):
2023
async def start(self):
2124
await super().start()
2225
usr_bot_me = await self.get_me()
26+
27+
if FORCE_SUB_CHANNEL:
28+
try:
29+
link = await self.export_chat_invite_link(FORCE_SUB_CHANNEL)
30+
self.invitelink = link
31+
except:
32+
self.LOGGER(__name__).warning("Bot can't Export Invite link from Force Sub Channel!")
33+
self.LOGGER(__name__).warning("Please Double check the FORCE_SUB_CHANNEL value and Make sure Bot is Admin in channel with Invite Users via Link Permission")
34+
self.LOGGER(__name__).info("\nBot Stopped. Join https://t.me/CodeXBotzSupport for support")
35+
sys.exit()
36+
try:
37+
db_channel = await self.get_chat(CHANNEL_ID)
38+
self.db_channel = db_channel
39+
test = await self.send_message(chat_id = db_channel.id, text = "Test Message")
40+
await test.delete()
41+
except Exception as e:
42+
self.LOGGER(__name__).warning(e)
43+
self.LOGGER(__name__).warning("Make Sure bot is Admin in DB Channel, and Double check the CHANNEL_ID Value")
44+
self.LOGGER(__name__).info("\nBot Stopped. Join https://t.me/CodeXBotzSupport for support")
45+
sys.exit()
46+
2347
self.set_parse_mode("html")
2448
self.LOGGER(__name__).info(f"Bot Running..!\n\nCreated by 𝘾𝙤𝙙𝙚 𝕏 𝘽𝙤𝙩𝙯\nhttps://t.me/CodeXBotz")
2549
self.username = usr_bot_me.username

config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import os
22
import logging
33
from logging.handlers import RotatingFileHandler
4+
45
#Bot token @Botfather
56
TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "")
7+
68
#Your API ID from my.telegram.org
79
APP_ID = int(os.environ.get("APP_ID", ""))
10+
811
#Your API Hash from my.telegram.org
912
API_HASH = os.environ.get("API_HASH", "")
10-
#Your channel Id
13+
14+
#Your db channel Id
1115
CHANNEL_ID = int(os.environ.get("CHANNEL_ID", ""))
16+
1217
#OWNER ID
1318
OWNER_ID = int(os.environ.get("OWNER_ID", ""))
1419

20+
#force sub channel id, if you want enable force sub
21+
FORCE_SUB_CHANNEL = int(os.environ.get("FORCE_SUB_CHANNEL", "0"))
22+
1523
TG_BOT_WORKERS = int(os.environ.get("TG_BOT_WORKERS", "4"))
24+
1625
#start message
1726
START_MSG = os.environ.get("START_MESSAGE", "Hello {firstname}\n\nI can store private files in Specified Channel and other users can access it from special link.")
1827
try:

helper_func.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#(©)Codexbotz
2+
3+
import base64
4+
import re
5+
import asyncio
6+
from pyrogram import filters
7+
from config import FORCE_SUB_CHANNEL, ADMINS
8+
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
9+
from pyrogram.errors import FloodWait
10+
11+
async def is_subscribed(filter, client, message):
12+
if not FORCE_SUB_CHANNEL:
13+
return True
14+
user_id = message.from_user.id
15+
if user_id in ADMINS:
16+
return True
17+
try:
18+
member = await client.get_chat_member(chat_id = FORCE_SUB_CHANNEL, user_id = user_id)
19+
except UserNotParticipant:
20+
return False
21+
22+
if not member.status in ["creator", "administrator", "member"]:
23+
return False
24+
else:
25+
return True
26+
27+
async def encode(string):
28+
string_bytes = string.encode("ascii")
29+
base64_bytes = base64.b64encode(string_bytes)
30+
base64_string = base64_bytes.decode("ascii")
31+
return base64_string
32+
33+
async def decode(base64_string):
34+
base64_bytes = base64_string.encode("ascii")
35+
string_bytes = base64.b64decode(base64_bytes)
36+
string = string_bytes.decode("ascii")
37+
return string
38+
39+
async def get_messages(client, message_ids):
40+
messages = []
41+
total_messages = 0
42+
while total_messages != len(message_ids):
43+
temb_ids = message_ids[total_messages:total_messages+200]
44+
try:
45+
msgs = await client.get_messages(
46+
chat_id=client.db_channel.id,
47+
message_ids=temb_ids
48+
)
49+
except FloodWait as e:
50+
await asyncio.sleep(e.x)
51+
msgs = await client.get_messages(
52+
chat_id=client.db_channel.id,
53+
message_ids=temb_ids
54+
)
55+
except:
56+
pass
57+
total_messages += len(temb_ids)
58+
messages.extend(msgs)
59+
return messages
60+
61+
async def get_message_id(client, message):
62+
if message.forward_from_chat:
63+
if first_message.forward_from_chat.id == client.db_channel.id:
64+
return first_message.forward_from_message_id
65+
else:
66+
return 0
67+
elif message.forward_sender_name:
68+
return 0
69+
elif message.text:
70+
pattern = "https://t.me/(?:c/)?(.*)/(\d+)"
71+
matches = re.match(pattern,message.text)
72+
if not matches:
73+
return 0
74+
channel_id = matches.group(1)
75+
msg_id = int(matches.group(2))
76+
if channel_id.isdigit():
77+
if f"-100{channel_id}" == str(client.db_channel.id):
78+
return msg_id
79+
else:
80+
if channel_id == client.db_channel.username:
81+
return msg_id
82+
else:
83+
return 0
84+
85+
subscribed = filters.create(is_subscribed)

plugins/cbb.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#(©)Codexbotz
2+
3+
from pyrogram import __version__
4+
from bot import Bot
5+
from config import OWNER_ID
6+
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
7+
8+
@Bot.on_callback_query()
9+
async def cb_handler(client: Bot, query: CallbackQuery):
10+
data = query.data
11+
if data == "about":
12+
await query.message.edit_text(
13+
text = f"<b>○ Creator : <a href='tg://user?id={OWNER_ID}'>This Person</a>\n○ Language : <code>Python3</code>\n○ Library : <a href='https://docs.pyrogram.org/'>Pyrogram asyncio {__version__}</a>\n○ Source Code : <a href='https://github.com/CodeXBotz/File-Sharing-Bot'>Click here</a>\n○ Channel : @CodeXBotz\n○ Support Group : @CodeXBotzSupport</b>",
14+
disable_web_page_preview = True,
15+
reply_markup = InlineKeyboardMarkup(
16+
[
17+
[
18+
InlineKeyboardButton("🔒 Close", callback_data = "close")
19+
]
20+
]
21+
)
22+
)
23+
elif data == "close":
24+
await query.message.delete()
25+
try:
26+
await query.message.reply_to_message.delete()
27+
except:
28+
pass

plugins/channel_post.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#(©)Codexbotz
2+
3+
import asyncio
4+
from pyrogram import filters, Client
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, CHANNEL_ID
10+
from helper_func import encode
11+
12+
@Bot.on_message(filters.private & filters.user(ADMINS) & ~filters.command(['start','batch','genlink']))
13+
async def channel_post(client: Client, message: Message):
14+
reply_text = await message.reply_text("Please Wait...!", quote = True)
15+
try:
16+
post_message = await message.copy(chat_id = client.db_channel.id, disable_notification=True)
17+
except FloodWait as e:
18+
await asyncio.sleep(e.x)
19+
post_message = await message.copy(chat_id = client.db_channel.id, disable_notification=True)
20+
except Exception as e:
21+
print(e)
22+
await reply_text.edit_text("Something went Wrong..!")
23+
return
24+
converted_id = post_message.message_id * abs(client.db_channel.id)
25+
string = f"get-{converted_id}"
26+
base64_string = await encode(string)
27+
link = f"https://t.me/{client.username}?start={base64_string}"
28+
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("🔁 Share URL", url=f'https://telegram.me/share/url?url={link}')]])
29+
await reply_text.edit(f"<b>Here is your link</b>\n\n{link}", reply_markup=reply_markup, disable_web_page_preview = True)
30+
await post_message.edit_reply_markup(reply_markup)
31+
32+
@Bot.on_message(filters.channel & filters.incoming & filters.chat(CHANNEL_ID) & ~filters.edited)
33+
async def new_post(client: Client, message: Message):
34+
converted_id = message.message_id * abs(client.db_channel.id)
35+
string = f"get-{converted_id}"
36+
base64_string = await encode(string)
37+
link = f"https://t.me/{client.username}?start={base64_string}"
38+
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("🔁 Share URL", url=f'https://telegram.me/share/url?url={link}')]])
39+
try:
40+
await message.edit_reply_markup(reply_markup)
41+
except Exception as e:
42+
print(e)
43+
pass

0 commit comments

Comments
 (0)