Skip to content

Commit e20b972

Browse files
authored
Merge branch 'main' into main
2 parents bbf3024 + 487afd7 commit e20b972

File tree

14 files changed

+170
-86
lines changed

14 files changed

+170
-86
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,7 @@ dmypy.json
137137

138138
# Cython debug symbols
139139
cython_debug/
140-
140+
.idea
141+
Bot.session
142+
filesharingbot.txt
143+
Bot.session-journal

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,31 @@
2626
Telegram Bot to store Posts and Documents and it can Access by Special Links.
2727
I Guess This Will Be Usefull For Many People.....😇.
2828

29-
##
30-
31-
**If you need any more modes in repo or If you find out any bugs, mention in [@codexbotzsupport ](https://www.telegram.dog/codexbotzsupport)**
32-
33-
**Make sure to see [contributing.md](https://github.com/CodeXBotz/File-Sharing-Bot/blob/main/CONTRIBUTING.md) for instructions on contributing to the project!**
34-
35-
3629

3730
### Features
3831
- Fully customisable.
3932
- Customisable welcome & Forcesub messages.
4033
- More than one Posts in One Link.
4134
- Can be deployed on heroku directly.
35+
- Protect Content to Prevent Forwarding
36+
- Auto-Delete Files After a Configurable Time
37+
38+
## What’s Next
4239

40+
These features are in the pipeline, and contributions from the community are welcome!
41+
42+
- [x] **Channel Join Request**
43+
Implement a feature that prompts users to join a specified Telegram channel before accessing the bot's functionalities.
44+
45+
46+
### How to Contribute
47+
1. Check the [contribution guidelines](https://github.com/CodeXBotz/File-Sharing-Bot/blob/main/CONTRIBUTING.md) for detailed instructions.
48+
2. Pick any feature and create a new issue or comment on an existing one.
49+
3. Discuss your implementation plan with maintainers to align your contributions with project goals.
50+
51+
We encourage all developers to contribute ideas, report bugs, and share improvements. Together, we can make this project even better! 🚀
52+
53+
4354
### Setup
4455

4556
- Add the bot to Database Channel with all permission
@@ -100,19 +111,24 @@ python3 main.py
100111
* `OWNER_ID` Must enter Your Telegram Id
101112
* `CHANNEL_ID` Your Channel ID eg:- -100xxxxxxxx
102113
* `DATABASE_URL` Your mongo db url
103-
* `DATABASE_NAME` Your mongo db session name
104114
* `ADMINS` Optional: A space separated list of user_ids of Admins, they can only create links
105115
* `START_MESSAGE` Optional: start message of bot, use HTML and <a href='https://github.com/codexbotz/File-Sharing-Bot/blob/main/README.md#start_message'>fillings</a>
116+
* `START_PIC` Optional: URL or file path of the image to be sent as the start message
106117
* `FORCE_SUB_MESSAGE`Optional:Force sub message of bot, use HTML and Fillings
107118
* `FORCE_SUB_CHANNEL` Optional: ForceSub Channel ID, leave 0 if you want disable force sub
108119
* `PROTECT_CONTENT` Optional: True if you need to prevent files from forwarding
120+
* `AUTO_DELETE_TIME ` Set the time in seconds for automatic file deletion. Default is False, which disables auto-deletion.
121+
* `JOIN_REQUEST_ENABLED` Optional: Set to "True" to enable join request for the channel. Default is "False".
109122

110123
### Extra Variables
111124

125+
* `AUTO_DELETE_MSG` put your custom deletion text if you want Setup Custom deletion messaeg,
126+
* `AUTO_DEL_SUCCESS_MSG` Set your custom success message for when the file is successfully deleted
112127
* `CUSTOM_CAPTION` put your Custom caption text if you want Setup Custom Caption, you can use HTML and <a href='https://github.com/CodeXBotz/File-Sharing-Bot/blob/main/README.md#custom_caption'>fillings</a> for formatting (only for documents)
113128
* `DISABLE_CHANNEL_BUTTON` Put True to Disable Channel Share Button, Default if False
114129
* `BOT_STATS_TEXT` put your custom text for stats command, use HTML and <a href='https://github.com/codexbotz/File-Sharing-Bot/blob/main/README.md#custom_stats'>fillings</a>
115130
* `USER_REPLY_TEXT` put your text to show when user sends any message, use HTML
131+
* `DATABASE_NAME` Your mongo db session name
116132

117133

118134
### Fillings

app.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
"description": "Optional: start message of bot, use HTML parsemode format",
4646
"value": "Hello {first}\n\nI can store private files in Specified Channel and other users can access it from special link."
4747
},
48+
"START_PIC": {
49+
"description": "Optional: URL or file path of the image to be sent as the start message,",
50+
"value": " "
51+
},
4852
"FORCE_SUB_MESSAGE": {
4953
"description": "Optional: Force Sub message of bot, use HTML parsemode format",
5054
"value": "Hello {first}\n\n<b>You need to join in my Channel/Group to use me\n\nKindly Please join Channel</b>"
@@ -58,6 +62,18 @@
5862
"description": "Protect contents from getting forwarded",
5963
"value": "False",
6064
"required": false
65+
},
66+
"AUTO_DELETE_TIME": {
67+
"description": "Set the time in seconds for the automatic deletion of the file. Default is 0, meaning auto-deletion is disabled unless specified.",
68+
"value": "0"
69+
},
70+
"AUTO_DELETE_MSG": {
71+
"description": "The custom message shown to the user before the file is automatically deleted. You can include a countdown with {time}.",
72+
"value": "This file will be automatically deleted in {time} seconds. Please ensure you have saved any necessary content before this time."
73+
},
74+
"AUTO_DEL_SUCCESS_MSG": {
75+
"description": "The custom message shown to the user once the file is successfully deleted.",
76+
"value": "Your file has been successfully deleted. Thank you for using our service. ✅"
6177
}
6278
},
6379
"buildpacks": [
@@ -68,8 +84,3 @@
6884
"formation": {
6985
"worker": {
7086
"quantity": 1,
71-
"size": "basic"
72-
}
73-
}
74-
}
75-

bot.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from config import API_HASH, APP_ID, LOGGER, TG_BOT_TOKEN, TG_BOT_WORKERS, FORCE_SUB_CHANNEL, CHANNEL_ID, PORT
1313

1414

15-
name ="""
15+
ascii_art = """
1616
░█████╗░░█████╗░██████╗░███████╗██╗░░██╗██████╗░░█████╗░████████╗███████╗
1717
██╔══██╗██╔══██╗██╔══██╗██╔════╝╚██╗██╔╝██╔══██╗██╔══██╗╚══██╔══╝╚════██║
1818
██║░░╚═╝██║░░██║██║░░██║█████╗░░░╚███╔╝░██████╦╝██║░░██║░░░██║░░░░░███╔═╝
@@ -21,7 +21,6 @@
2121
░╚════╝░░╚════╝░╚═════╝░╚══════╝╚═╝░░╚═╝╚═════╝░░╚════╝░░░░╚═╝░░░╚══════╝
2222
"""
2323

24-
2524
class Bot(Client):
2625
def __init__(self):
2726
super().__init__(
@@ -67,14 +66,8 @@ async def start(self):
6766

6867
self.set_parse_mode(ParseMode.HTML)
6968
self.LOGGER(__name__).info(f"Bot Running..!\n\nCreated by \nhttps://t.me/CodeXBotz")
70-
self.LOGGER(__name__).info(f""" \n\n
71-
░█████╗░░█████╗░██████╗░███████╗██╗░░██╗██████╗░░█████╗░████████╗███████╗
72-
██╔══██╗██╔══██╗██╔══██╗██╔════╝╚██╗██╔╝██╔══██╗██╔══██╗╚══██╔══╝╚════██║
73-
██║░░╚═╝██║░░██║██║░░██║█████╗░░░╚███╔╝░██████╦╝██║░░██║░░░██║░░░░░███╔═╝
74-
██║░░██╗██║░░██║██║░░██║██╔══╝░░░██╔██╗░██╔══██╗██║░░██║░░░██║░░░██╔══╝░░
75-
╚█████╔╝╚█████╔╝██████╔╝███████╗██╔╝╚██╗██████╦╝╚█████╔╝░░░██║░░░███████╗
76-
░╚════╝░░╚════╝░╚═════╝░╚══════╝╚═╝░░╚═╝╚═════╝░░╚════╝░░░░╚═╝░░░╚══════╝
77-
""")
69+
print(ascii_art)
70+
print("""Welcome to CodeXBotz File Sharing Bot""")
7871
self.username = usr_bot_me.username
7972
#web-response
8073
app = web.AppRunner(await web_server())

config.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#(©)CodeXBotz
22

3-
4-
5-
63
import os
74
import logging
5+
from dotenv import load_dotenv
86
from logging.handlers import RotatingFileHandler
97

10-
8+
load_dotenv()
119

1210
#Bot token @Botfather
1311
TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "")
@@ -33,10 +31,12 @@
3331

3432
#force sub channel id, if you want enable force sub
3533
FORCE_SUB_CHANNEL = int(os.environ.get("FORCE_SUB_CHANNEL", "0"))
34+
JOIN_REQUEST_ENABLE = os.environ.get("JOIN_REQUEST_ENABLED", None)
3635

3736
TG_BOT_WORKERS = int(os.environ.get("TG_BOT_WORKERS", "4"))
3837

3938
#start message
39+
START_PIC = os.environ.get("START_PIC","")
4040
START_MSG = os.environ.get("START_MESSAGE", "Hello {first}\n\nI can store private files in Specified Channel and other users can access it from special link.")
4141
try:
4242
ADMINS=[]
@@ -54,6 +54,11 @@
5454
#set True if you want to prevent users from forwarding files from bot
5555
PROTECT_CONTENT = True if os.environ.get('PROTECT_CONTENT', "False") == "True" else False
5656

57+
# Auto delete time in seconds.
58+
AUTO_DELETE_TIME = int(os.getenv("AUTO_DELETE_TIME", "0"))
59+
AUTO_DELETE_MSG = os.environ.get("AUTO_DELETE_MSG", "This file will be automatically deleted in {time} seconds. Please ensure you have saved any necessary content before this time.")
60+
AUTO_DEL_SUCCESS_MSG = os.environ.get("AUTO_DEL_SUCCESS_MSG", "Your file has been successfully deleted. Thank you for using our service. ✅")
61+
5762
#Set true if you want Disable your Channel Posts Share button
5863
DISABLE_CHANNEL_BUTTON = os.environ.get("DISABLE_CHANNEL_BUTTON", None) == 'True'
5964

@@ -80,6 +85,5 @@
8085
)
8186
logging.getLogger("pyrogram").setLevel(logging.WARNING)
8287

83-
8488
def LOGGER(name: str) -> logging.Logger:
8589
return logging.getLogger(name)

database/database.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
#(©)CodeXBotz
22

3-
4-
5-
63
import pymongo, os
74
from config import DB_URI, DB_NAME
85

9-
106
dbclient = pymongo.MongoClient(DB_URI)
117
database = dbclient[DB_NAME]
12-
13-
148
user_data = database['users']
159

16-
17-
1810
async def present_user(user_id : int):
1911
found = user_data.find_one({'_id': user_id})
2012
return bool(found)

helper_func.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import base64
44
import re
55
import asyncio
6+
import logging
67
from pyrogram import filters
78
from pyrogram.enums import ChatMemberStatus
8-
from config import FORCE_SUB_CHANNEL, ADMINS
9+
from config import FORCE_SUB_CHANNEL, ADMINS, AUTO_DELETE_TIME, AUTO_DEL_SUCCESS_MSG
910
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
1011
from pyrogram.errors import FloodWait
1112

@@ -84,7 +85,6 @@ async def get_message_id(client, message):
8485
else:
8586
return 0
8687

87-
8888
def get_readable_time(seconds: int) -> str:
8989
count = 0
9090
up_time = ""
@@ -106,5 +106,16 @@ def get_readable_time(seconds: int) -> str:
106106
up_time += ":".join(time_list)
107107
return up_time
108108

109+
async def delete_file(messages, client, process):
110+
await asyncio.sleep(AUTO_DELETE_TIME)
111+
for msg in messages:
112+
try:
113+
await client.delete_messages(chat_id=msg.chat.id, message_ids=[msg.id])
114+
except Exception as e:
115+
await asyncio.sleep(e.x)
116+
print(f"The attempt to delete the media {msg.id} was unsuccessful: {e}")
117+
118+
await process.edit_text(AUTO_DEL_SUCCESS_MSG)
119+
109120

110121
subscribed = filters.create(is_subscribed)

plugins/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#(©)Codexbotz
22
#@iryme
33

4-
5-
6-
7-
84
from aiohttp import web
95
from .route import routes
106

11-
127
async def web_server():
138
web_app = web.Application(client_max_size=30000000)
149
web_app.add_routes(routes)

plugins/cbb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pyrogram import __version__
44
from bot import Bot
55
from config import OWNER_ID
6-
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
6+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
77

88
@Bot.on_callback_query()
99
async def cb_handler(client: Bot, query: CallbackQuery):

plugins/channel_post.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def channel_post(client: Client, message: Message):
1515
try:
1616
post_message = await message.copy(chat_id = client.db_channel.id, disable_notification=True)
1717
except FloodWait as e:
18-
await asyncio.sleep(e.x)
18+
await asyncio.sleep(e.value)
1919
post_message = await message.copy(chat_id = client.db_channel.id, disable_notification=True)
2020
except Exception as e:
2121
print(e)
@@ -31,7 +31,13 @@ async def channel_post(client: Client, message: Message):
3131
await reply_text.edit(f"<b>Here is your link</b>\n\n{link}", reply_markup=reply_markup, disable_web_page_preview = True)
3232

3333
if not DISABLE_CHANNEL_BUTTON:
34-
await post_message.edit_reply_markup(reply_markup)
34+
try:
35+
await post_message.edit_reply_markup(reply_markup)
36+
except FloodWait as e:
37+
await asyncio.sleep(e.value)
38+
await post_message.edit_reply_markup(reply_markup)
39+
except Exception:
40+
pass
3541

3642
@Bot.on_message(filters.channel & filters.incoming & filters.chat(CHANNEL_ID))
3743
async def new_post(client: Client, message: Message):
@@ -46,6 +52,8 @@ async def new_post(client: Client, message: Message):
4652
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("🔁 Share URL", url=f'https://telegram.me/share/url?url={link}')]])
4753
try:
4854
await message.edit_reply_markup(reply_markup)
49-
except Exception as e:
50-
print(e)
55+
except FloodWait as e:
56+
await asyncio.sleep(e.value)
57+
await message.edit_reply_markup(reply_markup)
58+
except Exception:
5159
pass

0 commit comments

Comments
 (0)