├── runtime.txt ├── Procfile ├── requirements.txt ├── bot ├── __main__.py ├── user.py ├── __init__.py ├── bot.py ├── translation.py └── plugins │ ├── database.py │ ├── commands.py │ └── auto_filter.py ├── app.json ├── Readme.md ├── .gitignore └── LICENSE /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.9.1 -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 -m bot -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Dnspython 2 | Motor 3 | Pyrogram 4 | Pymongo 5 | TgCrypto 6 | -------------------------------------------------------------------------------- /bot/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) @AlbertEinsteinTG 4 | 5 | from .bot import Bot 6 | 7 | app = Bot() 8 | app.run() -------------------------------------------------------------------------------- /bot/user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) @AlbertEinsteinTG 4 | 5 | from pyrogram import Client, __version__ 6 | 7 | from . import API_HASH, APP_ID, LOGGER, \ 8 | USER_SESSION 9 | 10 | 11 | class User(Client): 12 | def __init__(self): 13 | super().__init__( 14 | USER_SESSION, 15 | api_hash=API_HASH, 16 | api_id=APP_ID, 17 | workers=4 18 | ) 19 | self.LOGGER = LOGGER 20 | 21 | async def start(self): 22 | await super().start() 23 | usr_bot_me = await self.get_me() 24 | return (self, usr_bot_me.id) 25 | 26 | async def stop(self, *args): 27 | await super().stop() 28 | self.LOGGER(__name__).info("Bot stopped. Bye.") 29 | -------------------------------------------------------------------------------- /bot/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) @AlbertEinsteinTG 4 | 5 | import os 6 | import logging 7 | from logging.handlers import RotatingFileHandler 8 | 9 | APP_ID = int(os.environ.get("APP_ID")) 10 | 11 | API_HASH = os.environ.get("API_HASH") 12 | 13 | BOT_TOKEN = os.environ.get("BOT_TOKEN") 14 | 15 | BOT_SESSION = os.environ.get("BOT_SESSION", "bot") 16 | 17 | DB_URI = os.environ.get("DB_URI") 18 | 19 | USER_SESSION = os.environ.get("USER_SESSION") 20 | 21 | LOG_FILE_NAME = "autofilterbot.txt" 22 | 23 | logging.basicConfig( 24 | level=logging.INFO, 25 | format="[%(asctime)s - %(levelname)s] - %(name)s - %(message)s", 26 | datefmt='%d-%b-%y %H:%M:%S', 27 | handlers=[ 28 | RotatingFileHandler( 29 | LOG_FILE_NAME, 30 | maxBytes=50000000, 31 | backupCount=10 32 | ), 33 | logging.StreamHandler() 34 | ] 35 | ) 36 | logging.getLogger("pyrogram").setLevel(logging.WARNING) 37 | 38 | def LOGGER(name: str) -> logging.Logger: 39 | return logging.getLogger(name) 40 | -------------------------------------------------------------------------------- /bot/bot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) @AlbertEinsteinTG 4 | 5 | from pyrogram import Client, __version__ 6 | 7 | from . import API_HASH, APP_ID, LOGGER, \ 8 | BOT_SESSION, BOT_TOKEN 9 | 10 | from .user import User 11 | 12 | 13 | 14 | class Bot(Client): 15 | USER: User = None 16 | USER_ID: int = None 17 | 18 | def __init__(self): 19 | super().__init__( 20 | BOT_SESSION, 21 | api_hash=API_HASH, 22 | api_id=APP_ID, 23 | plugins={ 24 | "root": "bot/plugins" 25 | }, 26 | workers=4, 27 | bot_token=BOT_TOKEN 28 | ) 29 | self.LOGGER = LOGGER 30 | 31 | async def start(self): 32 | await super().start() 33 | usr_bot_me = await self.get_me() 34 | self.set_parse_mode("html") 35 | self.LOGGER(__name__).info( 36 | f"@{usr_bot_me.username} started! " 37 | ) 38 | self.USER, self.USER_ID = await User().start() 39 | 40 | async def stop(self, *args): 41 | await super().stop() 42 | self.LOGGER(__name__).info("Bot stopped. Bye.") 43 | -------------------------------------------------------------------------------- /bot/translation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) @AlbertEinsteinTG 4 | 5 | class Translation(object): 6 | 7 | START_TEXT = """Hai {}!! 8 | Am Just A Simple Hand Auto Filter Bot_ Bot For Searching Files From Channel... 9 | 10 | Just Sent Any Text I Will Search In All Connected Chat And Reply You With The Message link 11 | 12 | You Can Even Connected To 3 Channels At A Time...""" 13 | 14 | HELP_TEXT = """Usage Guide 15 | 16 | => Add Bot To Any Channel As Admin With Add Members/ Invite Users Via Link 17 | 18 | => Copy Channel ID 19 | 20 | => Use /connect {channel id} In Your Group To Connect With The Group 21 | 22 | => Use /disconnect {channel id} In Your Group To Disconnect From Your Group 23 | 24 | => Use /delall In Your Group To Clear All Your Group Connections (Owner Only) 25 | 26 | Now You Are All Set And Ready To Go... 27 | 28 | Just Send Any Text Will Try To Lookup In Channel And Provide You The Link 29 | """ 30 | 31 | ABOUT_TEXT = """➥ Name : Adv Auto Filter Bot 32 | 33 | ➥ Creator : AlbertEinstein_TG 34 | 35 | ➥ Language : Python3 36 | 37 | ➥ Library : Pyrogram Asyncio 1.13.0 38 | 39 | ➥ Source Code : GitHub 40 | """ 41 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Auto Filter Bot", 3 | "description": "A Filter Bot Which Doesnt Need Manuall Filter Adding", 4 | "logo": "https://telegra.ph/file/667e15c821117633d07bd.png", 5 | "keywords": [ 6 | "Auto", 7 | "Filter", 8 | "Mongo DB" 9 | ], 10 | "website": "https://github.com/AlbertEinsteinTG", 11 | "repository": "https://github.com/AlbertEinsteinTG/Adv-Auto-Filter-Bot", 12 | "success_url": "https://telegram.dog/CrazyBotsz", 13 | "env": { 14 | "APP_ID": { 15 | "description": "Your APP ID From my.telegram.org or @UseTGXBot", 16 | "value": "" 17 | }, 18 | "API_HASH": { 19 | "description": "Your API Hash From my.telegram.org or @UseTGXBot", 20 | "value": "" 21 | }, 22 | "BOT_TOKEN": { 23 | "description": "Your Bot Token From @BotFather", 24 | "value": "" 25 | }, 26 | "DB_URI": { 27 | "description": "Your Mongo DB URL Obtained From mongodb.com", 28 | "value": "" 29 | }, 30 | "USER_SESSION": { 31 | "description": "A Pyrogram User Session String. Generated From @PyrogramStringBot", 32 | "value": "" 33 | } 34 | }, 35 | "buildpacks": [ 36 | { 37 | "url": "heroku/python" 38 | } 39 | ], 40 | "formation": { 41 | "worker": { 42 | "quantity": 1, 43 | "size": "free" 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Adv Auto Filter Bot 2 | 3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | 15 | _This Just A Simple Hand Auto Filter Bot For Searching Files From Channel..._ 16 | 17 | _Just Sent Any Text I Will Search In All Connected Chat And Reply You With The Message link_ 18 | 19 | _You Can Even Connected To 3 Channels At A Time..._ 20 | 21 | ## Usage 22 | 23 | _=> Add Bot To Any Channel As Admin With Add Members/ Invite Users Via Link_ 24 | 25 | _=> Copy Channel ID_ 26 | 27 | _=> Use `/connect {channel id}` In Your Group To Connect With The Group_ 28 | 29 | _=> Use `/disconnect {channel id}` In Your Group To Disconnect From Your Group_ 30 | 31 | _=> Use `/delall` In Your Group To Clear All Your Group Connections (Owner Only)_ 32 | 33 | _Now You Are All Set And Ready To Go..._ 34 | 35 | _Just Send Any Text Will Try To Lookup In Channel And Provide You The Link_ 36 | 37 | ### Pre Requisites 38 | 39 | _Your Bot Token From @BotFather_ 40 | 41 | _Your APP ID And API Harsh From [Telegram](http://www.my.telegram.org) or [@UseTGXBot](http://www.telegram.dog/UseTGXBot)_ 42 | 43 | _Your User Session String Obtained From [@PyrogramStringBot](http://www.telegram.dog/PyrogramStringBot)_ 44 | 45 | _Mongo DB URL Obtained From [Mongo DB](http://www.mongodb.com)_ 46 | 47 | ### Deploy: 48 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/AlbertEinsteinTG/Adv-Auto-Filter-Bot) 49 | 50 | ### TODO : 51 | 52 | - [ ] - Brodcast 53 | - [ ] - Better Codes 54 | - [x] - Rewrite To Motor Asyncious Driver 55 | 56 | PR's Are Very Welcome And If Found Any Bug Feel Free To Open A Issue... 57 | If YOu Found This Repo As Usefull A Star And Fork Would Be Amazing..😋 58 | 59 | ## Credits 60 | 61 | - Thanks To Dan For His Awsome [Libary](https://github.com/pyrogram/pyrogram) 62 | -------------------------------------------------------------------------------- /bot/plugins/database.py: -------------------------------------------------------------------------------- 1 | import motor.motor_asyncio 2 | from bot import DB_URI 3 | 4 | class Singleton(type): 5 | __instances__ = {} 6 | 7 | def __call__(cls, *args, **kwargs): 8 | if cls not in cls.__instances__: 9 | cls.__instances__[cls] = super(Singleton, cls).__call__(*args, **kwargs) 10 | 11 | return cls.__instances__[cls] 12 | 13 | 14 | class Database(metaclass=Singleton): 15 | 16 | def __init__(self): 17 | self._client = motor.motor_asyncio.AsyncIOMotorClient(DB_URI) 18 | self.db = self._client["Auto_Filter"] 19 | self.col = self.db["Chats"] 20 | 21 | self.cache = {} 22 | 23 | 24 | def new_connection(self, group_id, channel1, channel2, channel3): 25 | return dict( 26 | _id = group_id, 27 | channel_ids = dict( 28 | channel1=channel1, 29 | channel2=channel2, 30 | channel3=channel3 31 | ) 32 | ) 33 | 34 | async def find_connections(self, group_id): 35 | 36 | connections = self.cache.get(group_id) 37 | 38 | if connections is not None: 39 | return connections 40 | 41 | connections = await self.col.find_one({'_id':int(group_id)}) 42 | 43 | if connections: 44 | self.cache[group_id] = connections 45 | return connections 46 | return False 47 | 48 | 49 | async def add_connections(self, group_id, channel1, channel2, channel3): 50 | 51 | group = self.new_connection(group_id, channel1, channel2, channel3) 52 | 53 | prev = await self.col.find_one({'_id':int(group_id)}) 54 | 55 | if prev: 56 | await self.col.delete_one(prev) 57 | 58 | await self.col.insert_one(group) 59 | return True 60 | 61 | async def delete_connections(self, group_id): 62 | 63 | group_id = int(group_id) 64 | 65 | if self.cache.get(group_id): 66 | self.cache.pop(group_id) 67 | 68 | prev = self.col.find_one({"_id": int(group_id)}) 69 | 70 | if prev: 71 | await self.col.delete_one({"_id": int(group_id)}) 72 | return True 73 | return False 74 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 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 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /bot/plugins/commands.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) @AlbertEinsteinTG 4 | 5 | from pyrogram import filters, Client 6 | from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery 7 | from bot.translation import Translation # pylint: disable=import-error 8 | 9 | @Client.on_message(filters.command("start") & filters.private) 10 | async def start(bot, update): 11 | 12 | buttons = [[ 13 | InlineKeyboardButton('My Dev 👨‍🔬', url='https://t.me/AlbertEinstein_TG'), 14 | InlineKeyboardButton('Source Code 🧾', url ='https://github.com/AlbertEinsteinTG/Adv-Auto-Filter-Bot') 15 | ],[ 16 | InlineKeyboardButton('Support 🛠', url='https://t.me/CrazyBotszGrp') 17 | ],[ 18 | InlineKeyboardButton('Help ⚙', callback_data="help") 19 | ]] 20 | 21 | reply_markup = InlineKeyboardMarkup(buttons) 22 | 23 | await bot.send_message( 24 | chat_id=update.chat.id, 25 | text=Translation.START_TEXT.format( 26 | update.from_user.first_name), 27 | reply_markup=reply_markup, 28 | parse_mode="html", 29 | reply_to_message_id=update.message_id 30 | ) 31 | 32 | @Client.on_message(filters.command("help") & filters.private) 33 | async def help(bot, update): 34 | buttons = [[ 35 | InlineKeyboardButton('Home ⚡', callback_data='start'), 36 | InlineKeyboardButton('About 🚩', callback_data='about') 37 | ],[ 38 | InlineKeyboardButton('Close 🔐', callback_data='close') 39 | ]] 40 | 41 | reply_markup = InlineKeyboardMarkup(buttons) 42 | 43 | await bot.send_message( 44 | chat_id=update.chat.id, 45 | text=Translation.HELP_TEXT, 46 | reply_markup=reply_markup, 47 | parse_mode="html", 48 | reply_to_message_id=update.message_id 49 | ) 50 | 51 | @Client.on_message(filters.command("about") & filters.private) 52 | async def about(bot, update): 53 | buttons = [[ 54 | InlineKeyboardButton('Home ⚡', callback_data='start'), 55 | InlineKeyboardButton('Close 🔐', callback_data='close') 56 | ]] 57 | reply_markup = InlineKeyboardMarkup(buttons) 58 | await bot.send_message( 59 | chat_id=update.chat.id, 60 | text=Translation.ABOUT_TEXT, 61 | reply_markup=reply_markup, 62 | disable_web_page_preview=True, 63 | parse_mode="html", 64 | reply_to_message_id=update.message_id 65 | ) 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /bot/plugins/auto_filter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) @AlbertEinsteinTG 4 | 5 | import re 6 | import time 7 | import asyncio 8 | import pyrogram 9 | 10 | from pyrogram import Client, filters 11 | from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery 12 | from pyrogram.errors import UserAlreadyParticipant, FloodWait 13 | 14 | 15 | from bot.bot import Bot 16 | from bot.translation import Translation 17 | from bot.plugins.database import Database 18 | 19 | db = Database () 20 | result = [] 21 | 22 | @Client.on_message(filters.command("connect") & filters.group) 23 | async def connect(bot: Bot, update): 24 | 25 | group_id = update.chat.id 26 | text = update.text.split(None, 1) 27 | 28 | x = await bot.get_chat_member(group_id, update.from_user.id) 29 | 30 | if x.status == "member": 31 | return 32 | 33 | if len(text) != 2: 34 | return 35 | 36 | channel_id = int(text[1]) 37 | 38 | conn_hist = await db.find_connections(group_id) 39 | 40 | if conn_hist: #TODO: Better Way!? 41 | 42 | channel1 = int(conn_hist["channel_ids"]["channel1"]) if conn_hist["channel_ids"]["channel1"] else None 43 | channel2 = int(conn_hist["channel_ids"]["channel2"]) if conn_hist["channel_ids"]["channel2"] else None 44 | channel3 = int(conn_hist["channel_ids"]["channel3"]) if conn_hist["channel_ids"]["channel3"] else None 45 | 46 | else: 47 | channel1 = None 48 | channel2 = None 49 | channel3 = None 50 | 51 | if channel_id in (channel1, channel2, channel3): 52 | await bot.send_message( 53 | chat_id=group_id, 54 | text="Group Is Aldready Connected With This Channel", 55 | reply_to_message_id=update.message_id 56 | ) 57 | return 58 | 59 | if None not in (channel1, channel2, channel3): 60 | await bot.send_message( 61 | chat_id=group_id, 62 | text="Group Reached Its Connection Limit...\nDisconnect From Any Channel To Continue", 63 | reply_to_message_id=update.message_id 64 | ) 65 | return 66 | 67 | if channel1 is None: 68 | channel1 = channel_id 69 | 70 | elif channel2 is None: 71 | channel2 = channel_id 72 | 73 | elif channel3 is None: 74 | channel3 = channel_id 75 | 76 | # Export Invite Link For Userbot 77 | try: 78 | join_link = await bot.export_chat_invite_link(channel_id) 79 | except Exception as e: 80 | print(e) 81 | await bot.send_message( 82 | chat_id=group_id, 83 | text=f"Make Sure I'm Admin In {channel_id} And Have Permission - `Invite Users via Link`", 84 | parse_mode="html", 85 | reply_to_message_id=update.message_id 86 | ) 87 | return 88 | 89 | user = await bot.USER.get_me() 90 | user_id = user.id 91 | 92 | # Tries To Unban The UserBot 93 | try: 94 | await bot.unban_chat_member( 95 | chat_id=channel_id, 96 | user_id=user_id 97 | ) 98 | except Exception as e: 99 | pass 100 | 101 | # Userbot Joins The Channel 102 | try: 103 | await bot.USER.join_chat(join_link) 104 | except UserAlreadyParticipant: 105 | pass 106 | except Exception as e: 107 | print (e) 108 | 109 | await bot.send_message( 110 | chat_id=group_id, 111 | text=f"My Userbot `@{user.username}` Cant join Your Channel Make Sure He Is Not Banned There..", 112 | reply_to_message_id=update.message_id 113 | ) 114 | return 115 | 116 | chat_name = await bot.get_chat(channel_id) 117 | responce = await db.add_connections(group_id, channel1, channel2, channel3) 118 | 119 | if responce: 120 | await bot.send_message( 121 | chat_id=group_id, 122 | text=f"Sucessfully Connected To {chat_name.title}", 123 | parse_mode="html", 124 | reply_to_message_id=update.message_id 125 | ) 126 | return 127 | 128 | else: 129 | await bot.send_message( 130 | chat_id=group_id, 131 | text=f"Having Problem While Connecting...Report @CrazyBotsz", 132 | reply_to_message_id=update.message_id 133 | ) 134 | return 135 | 136 | 137 | @Client.on_message(filters.command("disconnect") & filters.group) 138 | async def disconnect(bot, update): 139 | group_id = update.chat.id 140 | text = update.text.split(None, 1) 141 | 142 | x = await bot.get_chat_member(group_id, update.from_user.id) 143 | 144 | if x.status == "member": 145 | return 146 | 147 | if len(text) != 2: 148 | return 149 | 150 | channel_id = int(text[1]) 151 | 152 | conn_hist = await db.find_connections(group_id) 153 | 154 | if conn_hist: 155 | channel1 = int(conn_hist["channel_ids"]["channel1"]) if conn_hist["channel_ids"]["channel1"] else None 156 | channel2 = int(conn_hist["channel_ids"]["channel2"]) if conn_hist["channel_ids"]["channel2"] else None 157 | channel3 = int(conn_hist["channel_ids"]["channel3"]) if conn_hist["channel_ids"]["channel3"] else None 158 | 159 | else: 160 | await bot.send_message( 161 | chat_id=group_id, 162 | text="Group Is Not Connected With Any Channel", 163 | reply_to_message_id=update.message_id 164 | ) 165 | return 166 | 167 | if channel_id not in (channel1, channel2, channel3): 168 | await bot.send_message( 169 | chat_id=group_id, 170 | text=f"Group Is Not Connected With This Chat : {channel_id}", 171 | parse_mode="html", 172 | reply_to_message_id=update.message_id 173 | ) 174 | return 175 | 176 | if channel1 == channel_id: 177 | channel1 = None 178 | 179 | elif channel2 == channel_id: 180 | channel2 = None 181 | 182 | elif channel3 == channel_id: 183 | channel3 = None 184 | 185 | try: 186 | await bot.USER.leave_chat(channel_id) 187 | except: 188 | pass 189 | 190 | chat_name = await bot.get_chat(channel_id) 191 | 192 | try: 193 | await bot.leave_chat(channel_id) 194 | except: 195 | pass 196 | 197 | responce = await db.add_connections(group_id, channel1, channel2, channel3) 198 | 199 | if responce: 200 | await bot.send_message( 201 | chat_id=group_id, 202 | text=f"Sucessfully Disconnected From {chat_name.title}", 203 | parse_mode="html", 204 | reply_to_message_id=update.message_id 205 | ) 206 | return 207 | 208 | else: 209 | await bot.send_message( 210 | chat_id=group_id, 211 | text=f"Having Problem While Disconnecting...Report @CrazyBotsz", 212 | reply_to_message_id=update.message_id 213 | ) 214 | return 215 | 216 | 217 | @Client.on_message(filters.command("delall") & filters.group) 218 | async def delall(bot, update): 219 | group_id = update.chat.id 220 | 221 | x = await bot.get_chat_member(group_id, update.from_user.id) 222 | 223 | if x.status == "creator": 224 | pass 225 | else: 226 | print(x.status) 227 | return 228 | print("Ok") 229 | conn_hist = await db.find_connections(group_id) 230 | print(conn_hist) 231 | if conn_hist: 232 | channel1 = int(conn_hist["channel_ids"]["channel1"]) if conn_hist["channel_ids"]["channel1"] else None 233 | channel2 = int(conn_hist["channel_ids"]["channel2"]) if conn_hist["channel_ids"]["channel2"] else None 234 | channel3 = int(conn_hist["channel_ids"]["channel3"]) if conn_hist["channel_ids"]["channel3"] else None 235 | channels = [channel1, channel2, channel3] 236 | else: 237 | return 238 | 239 | for channel in channels: 240 | if channel == None: 241 | continue 242 | try: 243 | await bot.USER.leave_chat(channel) 244 | except: 245 | pass 246 | try: 247 | await bot.leave_chat(channel) 248 | except: 249 | pass 250 | 251 | responce = await db.delete_connections(group_id) 252 | 253 | if responce: 254 | await bot.send_message( 255 | chat_id=group_id, 256 | text=f"Sucessfully Disconnected From All Chats", 257 | reply_to_message_id=update.message_id 258 | ) 259 | return 260 | 261 | 262 | @Client.on_message(filters.text & filters.group) 263 | async def auto_filter (bot, update): 264 | 265 | group_id = update.chat.id 266 | 267 | if re.findall("((^\/|^,|^\.|^[\U0001F600-\U000E007F]).*)", update.text): 268 | return 269 | 270 | query = update.text 271 | 272 | if len(query) < 3: 273 | return 274 | 275 | results = [] 276 | 277 | conn_hist = await db.find_connections(group_id) 278 | 279 | if conn_hist: # TODO: Better Way!? 😕 280 | channel1 = int(conn_hist["channel_ids"]["channel1"]) if conn_hist["channel_ids"]["channel1"] else None 281 | channel2 = int(conn_hist["channel_ids"]["channel2"]) if conn_hist["channel_ids"]["channel2"] else None 282 | channel3 = int(conn_hist["channel_ids"]["channel3"]) if conn_hist["channel_ids"]["channel3"] else None 283 | channels = [channel1, channel2, channel3] 284 | else: 285 | return 286 | 287 | for channel in channels: 288 | if channel == None: 289 | continue 290 | 291 | async for msgs in bot.USER.search_messages(chat_id=channel, query=query, filter="document", limit=150): 292 | 293 | if msgs.video: 294 | name = msgs.video.file_name 295 | elif msgs.document: 296 | name = msgs.document.file_name 297 | elif msgs.audio: 298 | name = msgs.audio.file_name 299 | else: 300 | name = None 301 | 302 | link = msgs.link 303 | 304 | if name is not None: 305 | results.append([InlineKeyboardButton(name, url=link)]) 306 | 307 | 308 | async for msgs in bot.USER.search_messages(chat_id=channel, query=query, filter="video", limit=150): 309 | 310 | if msgs.video: 311 | name = msgs.video.file_name 312 | elif msgs.document: 313 | name = msgs.document.file_name 314 | elif msgs.audio: 315 | name = msgs.audio.file_name 316 | else: 317 | name = None 318 | 319 | link = msgs.link 320 | 321 | if name is not None: 322 | results.append([InlineKeyboardButton(name, url=link)]) 323 | 324 | if len(results) == 0: 325 | # await bot.send_message( 326 | # chat_id = update.chat.id, 327 | # text=f"Couldn't Find A Matching Result", 328 | # reply_to_message_id=update.message_id 329 | # ) 330 | return 331 | 332 | else: 333 | global result 334 | result = [] 335 | result += [results[i * 30 :(i + 1) * 30 ] for i in range((len(results) + 30 - 1) // 30 )] 336 | 337 | if len(results) >30: 338 | result[0].append([InlineKeyboardButton("Next ⏩", callback_data=f"0 | {update.from_user.id} | next_btn")]) 339 | 340 | reply_markup = InlineKeyboardMarkup(result[0]) 341 | 342 | await bot.send_message( 343 | chat_id = update.chat.id, 344 | text=f"Found {(len(results))} Results For Query: {query}", 345 | reply_markup=reply_markup, 346 | parse_mode="html", 347 | reply_to_message_id=update.message_id 348 | ) 349 | 350 | @Client.on_callback_query() 351 | async def cb_handler(bot, query:CallbackQuery, group=1): 352 | cb_data = query.data 353 | 354 | if cb_data == "start": 355 | buttons = [[ 356 | InlineKeyboardButton('My Dev 👨‍🔬', url='https://t.me/AlbertEinstein_TG'), 357 | InlineKeyboardButton('Source Code 🧾', url ='https://github.com/AlbertEinsteinTG/Adv-Auto-Filter-Bot') 358 | ],[ 359 | InlineKeyboardButton('Support 🛠', url='https://t.me/CrazyBotszGrp') 360 | ],[ 361 | InlineKeyboardButton('Help ⚙', callback_data="help") 362 | ]] 363 | 364 | reply_markup = InlineKeyboardMarkup(buttons) 365 | 366 | await query.message.edit_text( 367 | Translation.START_TEXT.format(query.from_user.mention), 368 | reply_markup=reply_markup, 369 | parse_mode="html", 370 | disable_web_page_preview=True 371 | ) 372 | 373 | elif cb_data == "help": 374 | buttons = [[ 375 | InlineKeyboardButton('Home ⚡', callback_data='start'), 376 | InlineKeyboardButton('About 🚩', callback_data='about') 377 | ],[ 378 | InlineKeyboardButton('Close 🔐', callback_data='close') 379 | ]] 380 | 381 | reply_markup = InlineKeyboardMarkup(buttons) 382 | 383 | await query.message.edit_text( 384 | Translation.HELP_TEXT, 385 | reply_markup=reply_markup, 386 | parse_mode="html", 387 | disable_web_page_preview=True 388 | ) 389 | 390 | elif cb_data == "about": 391 | buttons = [[ 392 | InlineKeyboardButton('Home ⚡', callback_data='start'), 393 | InlineKeyboardButton('Close 🔐', callback_data='close') 394 | ]] 395 | 396 | reply_markup = InlineKeyboardMarkup(buttons) 397 | 398 | await query.message.edit_text( 399 | Translation.ABOUT_TEXT, 400 | reply_markup=reply_markup, 401 | parse_mode="html", 402 | disable_web_page_preview=True 403 | ) 404 | 405 | elif cb_data == "close": 406 | await query.message.delete() 407 | 408 | 409 | elif "btn" in cb_data : 410 | cb_data = cb_data.split("|") 411 | 412 | index_val = cb_data[0] 413 | user_id = cb_data[1] 414 | data = cb_data[2].strip() 415 | 416 | if int(query.from_user.id) != int(user_id): 417 | await query.answer("You Arent Worth To Do That!!",show_alert=True) # Lol😆 418 | return 419 | else: 420 | pass 421 | 422 | 423 | if data == "next_btn": 424 | index_val = int(index_val) + 1 425 | elif data == "back_btn": 426 | index_val = int(index_val) - 1 427 | 428 | try: 429 | temp_results = result[index_val].copy() 430 | except IndexError: 431 | return # Quick Fix🏃🏃 432 | except Exception as e: 433 | print(e) 434 | return 435 | 436 | if int(index_val) == (len(result) -1) or int(index_val) == 10: # Max 10 Page 437 | temp_results.append([ 438 | InlineKeyboardButton("⏪ Back", callback_data=f"{index_val} | {query.from_user.id} | back_btn") 439 | ]) 440 | 441 | elif int(index_val) == 0: 442 | pass 443 | 444 | else: 445 | temp_results.append([ 446 | InlineKeyboardButton("⏪ Back", callback_data=f"{index_val} | {query.from_user.id} | back_btn"), 447 | InlineKeyboardButton("Next ⏩", callback_data=f"{index_val} | {query.from_user.id} | next_btn") 448 | ]) 449 | 450 | reply_markup = InlineKeyboardMarkup(temp_results) 451 | 452 | if index_val == 0: 453 | text=f"Found {(len(result)*30 - (30 - len(result [-1])))} Results For Query" 454 | else: 455 | text=f"Page `{index_val}` For Your Query....." 456 | 457 | time.sleep(1) # Just A Mesure To Prevent Flood Wait🙁 458 | try: 459 | await query.message.edit( 460 | text, 461 | reply_markup=reply_markup, 462 | parse_mode="md" 463 | ) 464 | except FloodWait as f: 465 | await asyncio.sleep(f.x) 466 | await query.message.edit( 467 | text, 468 | reply_markup=reply_markup, 469 | parse_mode="md" 470 | ) 471 | --------------------------------------------------------------------------------