Skip to content

Commit

Permalink
added user confirmation for searches
Browse files Browse the repository at this point in the history
  • Loading branch information
prgofficial committed Mar 10, 2021
1 parent 934a662 commit f57d8ba
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 57 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ python3 main.py

* DATABASE_NAME - Your database name from mongoDB. Default will be 'Cluster0'

* DOC_SEARCH - Should bot search for document files ( Give 'yes' or 'no' )

* VID_SEARCH - Should bot search for video files ( Give 'yes' or 'no' )

* MUSIC_SEARCH - Should bot search for music files ( Give 'yes' or 'no' )

## Credits

[![TroJanz](https://img.shields.io/badge/Pyrogram%20-%23F37626.svg?&style=for-the-badge&logo=telegram&logoColor=white)](https://github.com/pyrogram/pyrogram)
Expand Down
12 changes: 12 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
"DATABASE_NAME": {
"description": "Your database name from mongoDB. ( Default will 'Cluster0' )",
"value": "Cluster0"
},
"DOC_SEARCH": {
"description": "Should bot search for document files in channels ( Give 'yes' or 'no' )",
"value": "yes"
},
"VID_SEARCH": {
"description": "Should bot search for video files in channels ( Give 'yes' or 'no' )",
"value": "no"
},
"MUSIC_SEARCH": {
"description": "Should bot search for music files in channels ( Give 'yes' or 'no' )",
"value": "no"
}
},
"buildpacks": [
Expand Down
9 changes: 9 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
# ID of users that can use the bot commands
AUTH_USERS = set(int(x) for x in os.environ.get("AUTH_USERS", "").split())

# Should bot search for document files in channels
DOC_SEARCH = os.environ.get("DOC_SEARCH", "yes").lower()

# Should bot search for video files in channels
VID_SEARCH = os.environ.get("VID_SEARCH", "no").lower()

# Should bot search for music files in channels
MUSIC_SEARCH = os.environ.get("MUSIC_SEARCH", "no").lower()




Expand Down
118 changes: 61 additions & 57 deletions plugins/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pyrogram.errors import UserAlreadyParticipant

from bot import Bot
from config import AUTH_USERS
from config import AUTH_USERS, DOC_SEARCH, VID_SEARCH, MUSIC_SEARCH
from database.mdb import (
savefiles,
deletefiles,
Expand Down Expand Up @@ -112,63 +112,67 @@ async def addchannel(client: Bot, message: Message):
return

docs = []
try:
async for msg in client.USER.search_messages(channel_id,filter='document'):
try:
file_name = msg.document.file_name
file_id = msg.document.file_id
link = msg.link
data = {
'_id': file_id,
'channel_id' : channel_id,
'file_name': file_name,
'link': link
}
docs.append(data)
except:
pass
except:
pass

await asyncio.sleep(5)

try:
async for msg in client.USER.search_messages(channel_id,filter='video'):
try:
file_name = msg.video.file_name
file_id = msg.video.file_id
link = msg.link
data = {
'_id': file_id,
'channel_id' : channel_id,
'file_name': file_name,
'link': link
}
docs.append(data)
except:
pass
except:
pass

await asyncio.sleep(5)

try:
async for msg in client.USER.search_messages(channel_id,filter='audio'):
try:
file_name = msg.audio.file_name
file_id = msg.audio.file_id
link = msg.link
data = {
'_id': file_id,
'channel_id' : channel_id,
'file_name': file_name,
'link': link
}
docs.append(data)
except:
pass
except:
pass
if DOC_SEARCH == "yes":
try:
async for msg in client.USER.search_messages(channel_id,filter='document'):
try:
file_name = msg.document.file_name
file_id = msg.document.file_id
link = msg.link
data = {
'_id': file_id,
'channel_id' : channel_id,
'file_name': file_name,
'link': link
}
docs.append(data)
except:
pass
except:
pass

await asyncio.sleep(5)

if VID_SEARCH == "yes":
try:
async for msg in client.USER.search_messages(channel_id,filter='video'):
try:
file_name = msg.video.file_name
file_id = msg.video.file_id
link = msg.link
data = {
'_id': file_id,
'channel_id' : channel_id,
'file_name': file_name,
'link': link
}
docs.append(data)
except:
pass
except:
pass

await asyncio.sleep(5)

if MUSIC_SEARCH == "yes":
try:
async for msg in client.USER.search_messages(channel_id,filter='audio'):
try:
file_name = msg.audio.file_name
file_id = msg.audio.file_id
link = msg.link
data = {
'_id': file_id,
'channel_id' : channel_id,
'file_name': file_name,
'link': link
}
docs.append(data)
except:
pass
except:
pass

if docs:
await savefiles(docs, group_id)
Expand Down

0 comments on commit f57d8ba

Please sign in to comment.