Skip to content
6 changes: 4 additions & 2 deletions bot/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async def get_filters(self, group_id: int, keyword: str):
filters = []

pipeline= {
'$text':{'$search': keyword}
'group_id': int(group_id), '$text':{'$search': keyword}
}


Expand Down Expand Up @@ -477,12 +477,14 @@ async def get_file(self, unique_id: str):
file = await self.fcol.find_one({"unique_id": unique_id})
file_id = None
file_type = None
file_name = None
file_caption = None

if file:
file_id = file.get("file_id")
file_name = file.get("file_name")
file_type = file.get("file_type")
file_caption = file.get("caption")
file_caption = file.get("file_caption")
return file_id, file_name, file_caption, file_type


Expand Down
23 changes: 21 additions & 2 deletions bot/plugins/auto_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ACTIVE_CHATS = {}
db = Database()

@Bot.on_message(filters.text & filters.group, group=0)
@Bot.on_message(filters.text & filters.group & ~filters.bot, group=0)
async def auto_filter(bot, update):
"""
A Funtion To Handle Incoming Text And Reply With Appropriate Results
Expand Down Expand Up @@ -64,7 +64,26 @@ async def auto_filter(bot, update):
file_name = filter.get("file_name")
file_type = filter.get("file_type")
file_link = filter.get("file_link")
file_size = int(filter.get("file_size", "0"))

# from B to MiB

if file_size < 1024:
file_size = f"[{file_size} B]"
elif file_size < (1024**2):
file_size = f"[{str(round(file_size/1024, 2))} KiB] "
elif file_size < (1024**3):
file_size = f"[{str(round(file_size/(1024**2), 2))} MiB] "
elif file_size < (1024**4):
file_size = f"[{str(round(file_size/(1024**3), 2))} GiB] "


file_size = "" if file_size == ("[0 B]") else file_size

# add emoji down below inside " " if you want..
button_text = f"{file_size}{file_name}"


if file_type == "video":
if allow_video:
pass
Expand Down Expand Up @@ -102,7 +121,7 @@ async def auto_filter(bot, update):

results.append(
[
InlineKeyboardButton(file_name, url=file_link)
InlineKeyboardButton(button_text, url=file_link)
]
)

Expand Down
2 changes: 1 addition & 1 deletion bot/plugins/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ async def cb_config(bot, update: CallbackQuery):
mf_count = settings["configs"]["max_results"]
mr_count = settings["configs"]["max_per_page"]
show_invite = settings["configs"]["show_invite_link"]
pm_file_chat = settings["configs"]["pm_fchat"]
pm_file_chat = settings["configs"].get("pm_fchat", False)
accuracy_point = settings["configs"].get("accuracy", 0.80)

text=f"<i><b>Configure Your <u><code>{chat_name}</code></u> Group's Filter Settings...</b></i>\n"
Expand Down
12 changes: 10 additions & 2 deletions bot/plugins/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ async def connect(bot: Bot, update):
file_id = file_id.video.file_id
file_name = msgs.video.file_name[0:-4]
file_caption = msgs.caption if msgs.caption else ""
file_size = msgs.video.file_size
file_type = "video"

elif msgs.audio:
Expand All @@ -127,6 +128,7 @@ async def connect(bot: Bot, update):
file_id = file_id.audio.file_id
file_name = msgs.audio.file_name[0:-4]
file_caption = msgs.caption if msgs.caption else ""
file_size = msgs.audio.file_size
file_type = "audio"

elif msgs.document:
Expand All @@ -141,6 +143,7 @@ async def connect(bot: Bot, update):
file_id = file_id.document.file_id
file_name = msgs.document.file_name[0:-4]
file_caption = msgs.caption if msgs.caption else ""
file_size = msgs.document.file_size
file_type = "document"

for i in ["_", "|", "-", "."]: # Work Around
Expand All @@ -164,6 +167,7 @@ async def connect(bot: Bot, update):
unique_id=unique_id,
file_name=file_name,
file_caption=file_caption,
file_size=file_size,
file_type=file_type,
file_link=file_link,
chat_id=channel_id,
Expand Down Expand Up @@ -280,7 +284,7 @@ async def delall(bot: Bot, update):
await update.reply_text("Sucessfully Deleted All Connected Chats From This Group....")


@Client.on_message(filters.channel & (filters.video | filters.audio | filters.document), group=0)
@Client.on_message(filters.channel & (filters.video | filters.audio | filters.document) & ~filters.edited, group=0)
async def new_files(bot: Bot, update):
"""
A Funtion To Handle Incoming New Files In A Channel ANd Add Them To Respective Channels..
Expand All @@ -296,19 +300,22 @@ async def new_files(bot: Bot, update):
file_id = update.video.file_id
file_name = update.video.file_name[0:-4]
file_caption = update.caption if update.caption else ""
file_size = update.video.file_size

elif update.audio:
file_type = "audio"
file_id = update.audio.file_id
file_name = update.audio.file_name[0:-4]
file_caption = update.caption if update.caption else ""
file_size = update.audio.file_size

elif update.document:
file_type = "document"
file_id = update.document.file_id
file_name = update.document.file_name[0:-4]
file_caption = update.caption if update.caption else ""

file_size = update.document.file_size

for i in ["_", "|", "-", "."]: # Work Around
try:
file_name = file_name.replace(i, " ")
Expand Down Expand Up @@ -338,6 +345,7 @@ async def new_files(bot: Bot, update):
unique_id=unique_id,
file_name=file_name,
file_caption=file_caption,
file_size = file_size,
file_type=file_type,
file_link=file_link,
chat_id=channel_id,
Expand Down
4 changes: 2 additions & 2 deletions bot/plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def start(bot, update):

elif file_type == "video":

await update.bot.send_video(
await bot.send_video(
chat_id=update.chat.id,
video = file_id,
caption = caption,
Expand All @@ -66,7 +66,7 @@ async def start(bot, update):

elif file_type == "audio":

await update.bot.send_audio(
await bot.send_audio(
chat_id=update.chat.id,
audio = file_id,
caption = caption,
Expand Down
32 changes: 2 additions & 30 deletions bot/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,8 @@ class Translation(object):
</i>"""

HELP_TEXT = """
<b><i><u>How To Use Me!?</u></i></b>

<i>
-> Add Me To Any Group And Make Me Admin
-> Add Me To Your Desired Channel
</i>

<b>Bot Commands (Works Only In Groups) :</b>

-> <code>/add chat_id</code>
OR - To Connect A Group With A Channel (Bot Should Be Admin With Full Previlages In Both Group And Channel)
<code>/add @Username</code>

-> <code>/del chat_id</code>
OR - To disconnect A Group With A Channel
<code>/del @Username</code>

-> <code>/delall</code> - This Command Will Disconnect All Connected Channel With The Group And Deletes All Its File From DB

-> <code>/settings</code> - This Command Will Display You A Settings Pannel Instance Which Can Be Used To Tweek Bot's Settings Accordingly

-> <code>Channel</code> - Button Will Show You All The Connected Chats With The Group And Will Show Buttons Correspnding To There Order For Furthur Controls

-> <code>Filter Types</code> - Button Will Show You The 3 Filter Option Available In Bot... Pressing Each Buttons Will Either Enable or Disable Them And This Will Take Into Action As Soon As You Use Them Without The Need Of A Restart

-> <code>Configure</code> - Button Will Helps You To Change No. of Pages/ Buttons Per Page/ Total Result Without Acutally Editing The Repo... Also It Provide Option To Enable/Disable For Showing Invite Link In Each Results

-> <code>Status</code> - Button Will Shows The Stats Of Your Channel

@CrazyBotsz
@m_oviezUP4
"""

ABOUT_TEXT = """<b>➥ Name</b> : <code> Auto Filter Bot</code>
Expand All @@ -55,4 +27,4 @@ class Translation(object):
<b>➥ Library</b> : <i><a href="https://docs.pyrogram.org">Pyrogram Asyncio 1.13.0 </a></i>

<b>➥ Source Code</b> : <i><a href="https://github.com/AlbertEinsteinTG/Adv-Auto-Filter-Bot">Click Me</a></i>
"""
"""