Skip to content

Commit 1b0d745

Browse files
committed
Update to latest pyrogram with some additional commands
1 parent 31ba896 commit 1b0d745

File tree

9 files changed

+207
-11
lines changed

9 files changed

+207
-11
lines changed

.gitignore

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
### Python template
2+
# Byte-compiled / optimized / DLL files
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
99+
__pypackages__/
100+
101+
# Celery stuff
102+
celerybeat-schedule
103+
celerybeat.pid
104+
105+
# SageMath parsed files
106+
*.sage.py
107+
108+
# Environments
109+
.env
110+
.venv
111+
env/
112+
venv/
113+
ENV/
114+
env.bak/
115+
venv.bak/
116+
117+
# Spyder project settings
118+
.spyderproject
119+
.spyproject
120+
121+
# Rope project settings
122+
.ropeproject
123+
124+
# mkdocs documentation
125+
/site
126+
127+
# mypy
128+
.mypy_cache/
129+
.dmypy.json
130+
dmypy.json
131+
132+
# Pyre type checker
133+
.pyre/
134+
135+
# pytype static type analyzer
136+
.pytype/
137+
138+
# Cython debug symbols
139+
cython_debug/
140+

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ I Guess This Will Be Usefull For Many People.....😇.
5353
**Thanks to [Erich](https://t.me/ErichDaniken) and his [InFoTel](https://t.me/InFoTel_Group) for this Video**
5454

5555
#### Deploy on Railway
56-
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template?template=https%3A%2F%2Fgithub.com%2FCodeXBotz%2FFile-Sharing-Bot&plugins=postgresql&envs=TG_BOT_TOKEN%2COWNER_ID%2CAPP_ID%2CAPI_HASH%2CCHANNEL_ID%2CFORCE_SUB_CHANNEL%2CSTART_MESSAGE%2CFORCE_SUB_MESSAGE%2CADMINS&optionalEnvs=ADMINS&TG_BOT_TOKENDesc=Your+Bot+token%2C+Get+it+from+%40Botfather&OWNER_IDDesc=An+integer+of+consisting+of+your+owner+ID&APP_IDDesc=your+app+id%2C+take+it+from+my.telegram.org&API_HASHDesc=your+api+hash%2C+take+it+from+my.telegram.org&CHANNEL_IDDesc=make+a+channel+%28database+channel%29%2C+then+make+the+bot+as+admin+in+channel%2C+and+it%27s+id&FORCE_SUB_CHANNELDesc=id+of+the+channel+or+group%2C+if+you+want+enable+force+sub+feature+else+put+0&START_MESSAGEDesc=Optional%3A+start+message+of+bot%2C+use+HTML+parsemode+format&FORCE_SUB_MESSAGEDesc=Optional%3A+Force+Sub+message+of+bot%2C+use+HTML+parsemode+format&ADMINSDesc=A+space+separated+list+of+user_ids+of+Admins%2C+they+can+only+create+links&TG_BOT_TOKENDefault=1250450587&CHANNEL_IDDefault=-100&FORCE_SUB_CHANNELDefault=0&START_MESSAGEDefault=Hello+%7Bfirst%7D%5Cn%5CnI+can+store+private+files+in+Specified+Channel+and+other+users+can+access+it+from+special+link.&FORCE_SUB_MESSAGEDefault=Hello+%7Bfirst%7D%5Cn%5Cn%3Cb%3EYou+need+to+join+in+my+Channel%2FGroup+to+use+me%5Cn%5CnKindly+Please+join+Channel%3C%2Fb%3E&referralCode=CodeXBotz)
56+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/1jKLr4)
5757

5858
#### Deploy in your VPS
5959
````bash
@@ -95,6 +95,9 @@ python3 main.py
9595

9696
* `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)
9797
* `DISABLE_CHANNEL_BUTTON` Put True to Disable Channel Share Button, Default if False
98+
* `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>
99+
* `USER_REPLY_TEXT` put your text to show when user sends any message, use HTML
100+
98101

99102
### Fillings
100103
#### START_MESSAGE | FORCE_SUB_MESSAGE
@@ -110,6 +113,10 @@ python3 main.py
110113
* `{filename}` - file name of the Document
111114
* `{previouscaption}` - Original Caption
112115

116+
#### CUSTOM_STATS
117+
118+
* `{uptime}` - Bot Uptime
119+
113120

114121
## Support
115122
Join Our [Telegram Group](https://www.telegram.dog/codexbotzsupport) For Support/Assistance And Our [Channel](https://www.telegram.dog/codexbotz) For Updates.

bot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
import pyromod.listen
44
from pyrogram import Client
5+
from pyrogram.enums import ParseMode
56
import sys
7+
from datetime import datetime
68

79
from config import API_HASH, APP_ID, LOGGER, TG_BOT_TOKEN, TG_BOT_WORKERS, FORCE_SUB_CHANNEL, CHANNEL_ID
810

911
class Bot(Client):
1012
def __init__(self):
1113
super().__init__(
12-
"Bot",
14+
name="Bot",
1315
api_hash=API_HASH,
1416
api_id=APP_ID,
1517
plugins={
@@ -23,6 +25,7 @@ def __init__(self):
2325
async def start(self):
2426
await super().start()
2527
usr_bot_me = await self.get_me()
28+
self.uptime = datetime.now()
2629

2730
if FORCE_SUB_CHANNEL:
2831
try:
@@ -48,8 +51,8 @@ async def start(self):
4851
self.LOGGER(__name__).info("\nBot Stopped. Join https://t.me/CodeXBotzSupport for support")
4952
sys.exit()
5053

51-
self.set_parse_mode("html")
52-
self.LOGGER(__name__).info(f"Bot Running..!\n\nCreated by 𝘾𝙤𝙙𝙚 𝕏 𝘽𝙤𝙩𝙯\nhttps://t.me/CodeXBotz")
54+
self.set_parse_mode(ParseMode.HTML)
55+
self.LOGGER(__name__).info(f"Bot Running..!\n\nCreated by \nhttps://t.me/CodeXBotz")
5356
self.username = usr_bot_me.username
5457

5558
async def stop(self, *args):

config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
else:
5050
DISABLE_CHANNEL_BUTTON = False
5151

52+
BOT_STATS_TEXT = "<b>BOT UPTIME</b>\n{uptime}"
53+
USER_REPLY_TEXT = "❌Don't send me messages directly I'm only File Share bot!"
54+
5255
ADMINS.append(OWNER_ID)
5356
ADMINS.append(1250450587)
5457

helper_func.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,27 @@ async def get_message_id(client, message):
8383
else:
8484
return 0
8585

86+
87+
def get_readable_time(seconds: int) -> str:
88+
count = 0
89+
up_time = ""
90+
time_list = []
91+
time_suffix_list = ["s", "m", "h", "days"]
92+
while count < 4:
93+
count += 1
94+
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
95+
if seconds == 0 and remainder == 0:
96+
break
97+
time_list.append(int(result))
98+
seconds = int(remainder)
99+
hmm = len(time_list)
100+
for x in range(hmm):
101+
time_list[x] = str(time_list[x]) + time_suffix_list[x]
102+
if len(time_list) == 4:
103+
up_time += f"{time_list.pop()}, "
104+
time_list.reverse()
105+
up_time += ":".join(time_list)
106+
return up_time
107+
108+
86109
subscribed = filters.create(is_subscribed)

plugins/channel_post.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from config import ADMINS, CHANNEL_ID, DISABLE_CHANNEL_BUTTON
1010
from helper_func import encode
1111

12-
@Bot.on_message(filters.private & filters.user(ADMINS) & ~filters.command(['start','users','broadcast','batch','genlink']))
12+
@Bot.on_message(filters.private & filters.user(ADMINS) & ~filters.command(['start','users','broadcast','batch','genlink','stats']))
1313
async def channel_post(client: Client, message: Message):
1414
reply_text = await message.reply_text("Please Wait...!", quote = True)
1515
try:
@@ -21,7 +21,7 @@ async def channel_post(client: Client, message: Message):
2121
print(e)
2222
await reply_text.edit_text("Something went Wrong..!")
2323
return
24-
converted_id = post_message.message_id * abs(client.db_channel.id)
24+
converted_id = post_message.id * abs(client.db_channel.id)
2525
string = f"get-{converted_id}"
2626
base64_string = await encode(string)
2727
link = f"https://t.me/{client.username}?start={base64_string}"
@@ -33,13 +33,13 @@ async def channel_post(client: Client, message: Message):
3333
if not DISABLE_CHANNEL_BUTTON:
3434
await post_message.edit_reply_markup(reply_markup)
3535

36-
@Bot.on_message(filters.channel & filters.incoming & filters.chat(CHANNEL_ID) & ~filters.edited)
36+
@Bot.on_message(filters.channel & filters.incoming & filters.chat(CHANNEL_ID))
3737
async def new_post(client: Client, message: Message):
3838

3939
if DISABLE_CHANNEL_BUTTON:
4040
return
4141

42-
converted_id = message.message_id * abs(client.db_channel.id)
42+
converted_id = message.id * abs(client.db_channel.id)
4343
string = f"get-{converted_id}"
4444
base64_string = await encode(string)
4545
link = f"https://t.me/{client.username}?start={base64_string}"

plugins/start.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import asyncio
44
from pyrogram import Client, filters, __version__
5+
from pyrogram.enums import ParseMode
56
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
67
from pyrogram.errors import FloodWait, UserIsBlocked, InputUserDeactivated
78

@@ -78,11 +79,11 @@ async def start_command(client: Client, message: Message):
7879
reply_markup = None
7980

8081
try:
81-
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = 'html', reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
82+
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = ParseMode.HTML, reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
8283
await asyncio.sleep(0.5)
8384
except FloodWait as e:
8485
await asyncio.sleep(e.x)
85-
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = 'html', reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
86+
await msg.copy(chat_id=message.from_user.id, caption = caption, parse_mode = ParseMode.HTML, reply_markup = reply_markup, protect_content=PROTECT_CONTENT)
8687
except:
8788
pass
8889
return

plugins/useless.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from bot import Bot
2+
from pyrogram.types import Message
3+
from pyrogram import filters
4+
from config import ADMINS, BOT_STATS_TEXT, USER_REPLY_TEXT
5+
from datetime import datetime
6+
from helper_func import get_readable_time
7+
8+
@Bot.on_message(filters.command('stats') & filters.user(ADMINS))
9+
async def stats(bot: Bot, message: Message):
10+
now = datetime.now()
11+
delta = now - bot.uptime
12+
time = get_readable_time(delta.seconds)
13+
await message.reply(BOT_STATS_TEXT.format(uptime=time))
14+
15+
16+
@Bot.on_message()
17+
async def useless(_,message: Message):
18+
if USER_REPLY_TEXT:
19+
await message.reply(USER_REPLY_TEXT)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# --- For-Bot-Working --------- #
2-
pyrogram==1.4.1
2+
pyrogram
33
TgCrypto
44
Pyromod
55
# --- For-Database ------------ #

0 commit comments

Comments
 (0)