├── .idea ├── .gitignore ├── Message-Manager-Bot.iml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── jsonSchemas.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── Procfile ├── README.md ├── app.json ├── configs.py ├── database ├── access_database.py └── database_handlers.py ├── helpers ├── custom_filters_handler.py ├── message_deletor.py └── settings_msg.py ├── main.py ├── requirements.txt └── runtime.txt /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/Message-Manager-Bot.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 41 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/jsonSchemas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 main.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Messages-Manager-Bot 2 | 3 | A Telegram Message Manager Bot by [@AbirHasan2005](https://github.com/AbirHasan2005). This Bot can delete specific type of messages from Group. I specially use for [@linux_repo](https://t.me/linux_repo) for Automatically deleting Videos. 4 | 5 | ## Features: 6 | - Delete Specific Type of Messages. 7 | - Set Blocked Extensions. 8 | - If any Media message contains Blocked Extension than bot will automatically delete it. 9 | - Set Blocked Words. 10 | - If any Media or Text message contains Blocked Words than bot will automatically delete it. 11 | - Set Custom Block Filters. 12 | - You can set many filters. Such as Allow Text, Video, Document, Audio, Photo, Sticker, GIF & Forwarded Message. 13 | 14 | Just Deploy Bot & Check All Features! 15 | 16 | More features coming soon! 17 | 18 | ## Deploy Bot 19 | ### Configs: 20 | - `API_ID` Get this from [@TeleORG_Bot](https://t.me/TeleORG_Bot). 21 | - `API_HASH` Get this from [@TeleORG_Bot](https://t.me/TeleORG_Bot). 22 | - `BOT_TOKEN` Get this from [@BotFather](https://t.me/BotFather). 23 | - `MONGODB_URI` MongoDB URI for Saving Chat Settings. Video Tutorial [Here](https://www.youtube.com/watch?v=aXlF80Cn7iU). 24 | - `OWNER_ID` Your Telegram User ID. 25 | - `BOT_USERNAME` Your Bot's Username. Without `@`. 26 | - `USER_SESSION_STRING` User Client Session String: [@StringSessionGen_Bot](https://t.me/StringSessionGen_Bot) 27 | - `LOG_CHANNEL` A Telegram Logs Channel ID for some trace. 28 | 29 | ### Heroku Deploy: 30 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/AbirHasan2005/Message-Manager-Bot) 31 | 32 | ### Host Locally: 33 | ```shell 34 | git clone https://github.com/AbirHasan2005/Message-Manager-Bot 35 | cd Message-Manager-Bot 36 | pip3 install -r requirements.txt 37 | # Setup Configurations in configs.py file! 38 | python3 main.py 39 | ``` 40 | 41 | ### Support Group: 42 | 43 | 44 | ### Follow on: 45 |

46 | 47 |

48 |

49 | 50 |

51 |

52 | 53 |

54 |

55 | 56 |

57 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "A Telegram Message Manager Bot by @AbirHasan2005.", 3 | "description": "A Telegram Message Manager Bot by @AbirHasan2005. This Bot can delete specific type of messages from Group. I specially use for @linux_repo for Automatically deleting Videos.", 4 | "keywords": [ 5 | "telegram", 6 | "messages", 7 | "manager", 8 | "bot" 9 | ], 10 | "repository": "https://github.com/AbirHasan2005/Message-Manager-Bot", 11 | "website": "https://telegram.dog/AbirHasan2005", 12 | "success_url": "https://t.me/MessageManager_Bot", 13 | "env": { 14 | "API_ID": { 15 | "description": "Get this value from my.telegram.org or @TeleORG_Bot" 16 | }, 17 | "API_HASH": { 18 | "description": "Get this value from my.telegram.org or @TeleORG_Bot" 19 | }, 20 | "BOT_TOKEN": { 21 | "description": "Get this from @BotFather" 22 | }, 23 | "MONGODB_URI": { 24 | "description": "MongoDB URI for Saving Chat Settings. Video Tutorial Here: https://www.youtube.com/watch?v=aXlF80Cn7iU" 25 | }, 26 | "OWNER_ID": { 27 | "description": "Your Telegram User ID" 28 | }, 29 | "BOT_USERNAME": { 30 | "description": "Your Bot's Username. Without @" 31 | }, 32 | "USER_SESSION_STRING": { 33 | "description": "User Client Session String. Use @StringSessionGen_Bot" 34 | }, 35 | "LOG_CHANNEL": { 36 | "description": "A Telegram Logs Channel ID for some trace." 37 | } 38 | }, 39 | "buildpacks": [ 40 | { 41 | "url": "heroku/python" 42 | } 43 | ], 44 | "formation": { 45 | "worker": { 46 | "quantity": 1, 47 | "size": "free" 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /configs.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | import os 4 | 5 | 6 | class Config(object): 7 | API_ID = int(os.environ.get("API_ID", 123456)) 8 | API_HASH = os.environ.get("API_HASH") 9 | BOT_TOKEN = os.environ.get("BOT_TOKEN") 10 | USER_SESSION_STRING = os.environ.get("USER_SESSION_STRING", ":memory:") 11 | MONGODB_URI = os.environ.get("MONGODB_URI") 12 | OWNER_ID = int(os.environ.get("OWNER_ID", 1445283714)) 13 | BOT_USERNAME = os.environ.get("BOT_USERNAME") 14 | LOG_CHANNEL = int(os.environ.get("LOG_CHANNEL")) 15 | 16 | ASK_FOR_BLOCKED_WORDS_LIST = os.environ.get("ASK_FOR_BLOCKED_WORDS_LIST", 17 | "Reply to this message with a list of Blocked Words. If those in Message I will not Forward them!\n\nExample:\nhello\nhacker\ncracker\njoin\nabuse heroku\njoin my channel\nchutiyappa") 18 | ASK_FOR_BLOCKED_EXT_LIST = os.environ.get("ASK_FOR_BLOCKED_EXT_LIST", 19 | "Reply to this message with a list of Blocked Extensions. If any file with that extension I will not forward that file!\n\nExample:\nzip\nmkv\ntorrent\ntxt\npy\ncap\nmp4\nmp3\nrar\n\nExtensions should be in lower case!") 20 | START_TEXT = """ 21 | Hi, This is Massages Manager Bot! 22 | I can do many things with messages in a Group. 23 | 24 | Check /settings !! 25 | """ 26 | ABOUT_CUSTOM_FILTERS_TEXT = """ 27 | Custom Filters is for deleting only separate type Media Messages or Only Text Messages. 28 | Like you can set only delete `photo` or `video` or `document` or `audio` or `text` ... 29 | 30 | If Need More Help Ask in [Support Group](https://t.me/JoinOT)! 31 | """ -------------------------------------------------------------------------------- /database/access_database.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | from configs import Config 4 | from database.database_handlers import Database 5 | 6 | mongodb = Database(Config.MONGODB_URI, Config.BOT_USERNAME) 7 | -------------------------------------------------------------------------------- /database/database_handlers.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | import datetime 4 | import motor.motor_asyncio 5 | 6 | 7 | class Database: 8 | def __init__(self, uri, database_name): 9 | self._client = motor.motor_asyncio.AsyncIOMotorClient(uri) 10 | self.db = self._client[database_name] 11 | self.col = self.db.chats 12 | 13 | def new_chat(self, id): 14 | return dict( 15 | id=id, 16 | join_date=datetime.date.today().isoformat(), 17 | custom_filters=["video", "document", "photo", "audio", "text", "sticker", "gif", "forward"], 18 | blocked_exts=None, 19 | blocked_words=None, 20 | allow_service_message=False 21 | ) 22 | 23 | async def add_chat(self, id): 24 | chat = self.new_chat(id) 25 | await self.col.insert_one(chat) 26 | 27 | async def is_chat_exist(self, id): 28 | chat = await self.col.find_one({'id': int(id)}) 29 | return True if chat else False 30 | 31 | async def total_chat_count(self): 32 | count = await self.col.count_documents({}) 33 | return count 34 | 35 | async def get_all_chats(self): 36 | all_chats = self.col.find({}) 37 | return all_chats 38 | 39 | async def delete_chat(self, chat_id): 40 | await self.col.delete_many({'id': int(chat_id)}) 41 | 42 | async def set_custom_filters(self, id, custom_filters): 43 | await self.col.update_one({'id': id}, {'$set': {'custom_filters': custom_filters}}) 44 | 45 | async def get_custom_filters(self, id): 46 | user = await self.col.find_one({'id': int(id)}) 47 | return user.get('custom_filters', ["video", "document", "photo", "audio", "text", "sticker", "gifs", "forward"]) 48 | 49 | async def get_blocked_exts(self, id): 50 | user = await self.col.find_one({'id': int(id)}) 51 | return user.get('blocked_exts', None) 52 | 53 | async def set_blocked_exts(self, id, blocked_exts): 54 | await self.col.update_one({'id': id}, {'$set': {'blocked_exts': blocked_exts}}) 55 | 56 | async def get_blocked_words(self, id): 57 | user = await self.col.find_one({'id': int(id)}) 58 | return user.get('blocked_words', None) 59 | 60 | async def set_blocked_words(self, id, blocked_words): 61 | await self.col.update_one({'id': id}, {'$set': {'blocked_words': blocked_words}}) 62 | 63 | async def allowServiceMessageDelete(self, id): 64 | user = await self.col.find_one({'id': int(id)}) 65 | return user.get('allow_service_message', None) 66 | 67 | async def set_allowServiceMessageDelete(self, id, allow_service_message): 68 | await self.col.update_one({'id': int(id)}, {'$set': {'allow_service_message': allow_service_message}}) -------------------------------------------------------------------------------- /helpers/custom_filters_handler.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | import asyncio 4 | from configs import Config 5 | from database.access_database import mongodb as db 6 | from pyrogram.errors import MessageNotModified, FloodWait 7 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, Message 8 | 9 | 10 | async def setup_callbacks_for_custom_filters(cb: CallbackQuery): 11 | get_data = await db.get_custom_filters(cb.message.chat.id) 12 | markup = [ 13 | [InlineKeyboardButton(f"Allow Videos {'✅' if ('video' in get_data) else '❌'}", 14 | callback_data="set_custom_filter_video"), 15 | InlineKeyboardButton(f"Allow Documents {'✅' if ('document' in get_data) else '❌'}", 16 | callback_data="set_custom_filter_document")], 17 | [InlineKeyboardButton(f"Allow Photos {'✅' if ('photo' in get_data) else '❌'}", 18 | callback_data="set_custom_filter_photo"), 19 | InlineKeyboardButton(f"Allow Audios {'✅' if ('audio' in get_data) else '❌'}", 20 | callback_data="set_custom_filter_audio")], 21 | [InlineKeyboardButton(f"Allow Stickers {'✅' if ('sticker' in get_data) else '❌'}", 22 | callback_data="set_custom_filter_sticker"), 23 | InlineKeyboardButton(f"Allow GIFs {'✅' if ('gif' in get_data) else '❌'}", 24 | callback_data="set_custom_filter_gif")], 25 | [InlineKeyboardButton(f"Allow Forwarded Messages {'✅' if ('forward' in get_data) else '❌'}", 26 | callback_data="set_custom_filter_forward")], 27 | [InlineKeyboardButton(f"Allow Text Messages {'✅' if ('text' in get_data) else '❌'}", 28 | callback_data="set_custom_filter_text")] 29 | ] 30 | if get_data is not None: 31 | markup.append([InlineKeyboardButton("Keep Default Filters", callback_data="set_custom_filter_default")]) 32 | markup.append([InlineKeyboardButton("Go Back to Settings", callback_data="goToSettings")]) 33 | markup.append([InlineKeyboardButton("Close ❎", callback_data="closeMeh")]) 34 | 35 | try: 36 | await cb.message.edit( 37 | text=f"**What is Custom Filters?**\n{Config.ABOUT_CUSTOM_FILTERS_TEXT}\n\n**Here You Can Setup Your Custom Filters:**", 38 | disable_web_page_preview=True, 39 | parse_mode="Markdown", 40 | reply_markup=InlineKeyboardMarkup(markup) 41 | ) 42 | except FloodWait as e: 43 | await asyncio.sleep(e.x) 44 | pass 45 | except MessageNotModified: 46 | pass 47 | 48 | 49 | async def blocked_words_loop(blocked_words, update): 50 | if (update.text is None) and (update.caption is None): 51 | return 200 52 | for a in range(len(blocked_words)): 53 | if blocked_words[a].lower() in (update.text or update.caption).lower(): 54 | return 400 55 | 56 | 57 | async def blocked_ext_checker(message: Message, chat_id): 58 | blocked_exts = await db.get_blocked_exts(chat_id) 59 | media = message.document or message.video or message.audio or message.sticker 60 | if (media is not None) and (media.file_name is not None): 61 | _file = media.file_name.rsplit(".", 1) 62 | if (len(_file) == 2) and (_file[-1].lower() in blocked_exts): 63 | return 400 64 | else: 65 | return 200 66 | else: 67 | return 200 68 | -------------------------------------------------------------------------------- /helpers/message_deletor.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | async def delete_message(message): 4 | try: 5 | await message.delete(True) 6 | except: 7 | pass 8 | -------------------------------------------------------------------------------- /helpers/settings_msg.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | from database.access_database import mongodb 4 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message 5 | 6 | 7 | async def show_settings(message: Message): 8 | """ Pass a Editable Message by of Bot Client to Edit it with Settings Buttons & Message! """ 9 | # Primary Markup Button 10 | markup = [[InlineKeyboardButton("🔰 Setup Custom Filters 🔰", callback_data="setCustomFilters")]] 11 | # Setup for Blocked Words 12 | blocked_words = await mongodb.get_blocked_words(message.chat.id) 13 | block_specific_words_button = [InlineKeyboardButton("Block Specific Words", callback_data="blockWords")] 14 | if blocked_words is not None: 15 | block_specific_words_button.append(InlineKeyboardButton("Show 👀", callback_data="showBlockedWords")) 16 | # Setup for Blocked Extensions 17 | blocked_extensions = await mongodb.get_blocked_exts(message.chat.id) 18 | block_specific_extensions_button = [InlineKeyboardButton("Block File Extensions", callback_data="blockFileExtensions")] 19 | if blocked_extensions is not None: 20 | block_specific_extensions_button.append(InlineKeyboardButton("Show 👀", callback_data="showBlockedExtensions")) 21 | # Append All Buttons Together 22 | markup.append(block_specific_words_button) 23 | markup.append(block_specific_extensions_button) 24 | markup.append([InlineKeyboardButton(f"Delete Service Messages {'✅' if (await mongodb.allowServiceMessageDelete(message.chat.id)) is True else '❌'}", callback_data="allowServiceMessagesDelete")]) 25 | markup.append([InlineKeyboardButton("Close ❎", callback_data="closeMeh")]) 26 | # Show Via Message Markup Buttons 27 | await message.edit( 28 | text="Here You Can Set Settings for this Chat:", 29 | reply_markup=InlineKeyboardMarkup(markup) 30 | ) -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # (c) @AbirHasan2005 2 | 3 | from configs import Config 4 | from database.access_database import mongodb 5 | from helpers.settings_msg import show_settings 6 | from helpers.message_deletor import delete_message 7 | from helpers.custom_filters_handler import setup_callbacks_for_custom_filters, blocked_words_loop, blocked_ext_checker 8 | 9 | from pyrogram import Client, filters, idle 10 | from pyrogram.types import Message, ForceReply, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton 11 | 12 | AHBot = Client( 13 | session_name=Config.BOT_USERNAME, 14 | api_id=Config.API_ID, 15 | api_hash=Config.API_HASH, 16 | bot_token=Config.BOT_TOKEN 17 | ) 18 | UserBot = Client( 19 | session_name=Config.USER_SESSION_STRING, 20 | api_id=Config.API_ID, 21 | api_hash=Config.API_HASH 22 | ) 23 | 24 | 25 | @AHBot.on_message(filters.command(['start', f'start@{Config.BOT_USERNAME}'])) 26 | async def start_handler(bot: Client, message: Message): 27 | if (not await mongodb.is_chat_exist(message.chat.id)) and (message.chat.type != "private"): 28 | try: 29 | getChat = await bot.get_chat(chat_id=message.chat.id) 30 | except: 31 | await message.reply_text( 32 | text="Make me Admin in this Chat!\n\nElse I will not work properly!", 33 | quote=True 34 | ) 35 | return 36 | await mongodb.add_chat(message.chat.id) 37 | await bot.send_message( 38 | Config.LOG_CHANNEL, 39 | f"#NEW_CHAT: \n\nNew Chat [{getChat.title}]({getChat.invite_link}) Started !!", 40 | parse_mode="Markdown", 41 | disable_web_page_preview=True 42 | ) 43 | await message.reply_text( 44 | text=Config.START_TEXT, 45 | disable_web_page_preview=True, 46 | reply_markup=InlineKeyboardMarkup( 47 | [ 48 | [InlineKeyboardButton("Open Settings", callback_data="goToSettings")] 49 | ] 50 | ), 51 | quote=True 52 | ) 53 | 54 | 55 | @AHBot.on_message(filters.command(["settings", f"settings@{Config.BOT_USERNAME}"]) & ~filters.private & ~filters.edited) 56 | async def settings_handler(bot: Client, message: Message): 57 | user = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id) 58 | print(f"User Status: {user.status}\nCan Change Info: {user.can_change_info}") 59 | if not await mongodb.is_chat_exist(message.chat.id): 60 | try: 61 | getChat = await bot.get_chat(chat_id=message.chat.id) 62 | except: 63 | await message.reply_text( 64 | text="Make me Admin in this Chat!\n\nElse I will not work properly!", 65 | quote=True 66 | ) 67 | return 68 | await mongodb.add_chat(message.chat.id) 69 | await bot.send_message( 70 | Config.LOG_CHANNEL, 71 | f"#NEW_CHAT: \n\nNew Chat [{getChat.title}]({getChat.invite_link}) Started !!", 72 | parse_mode="Markdown", 73 | disable_web_page_preview=True 74 | ) 75 | if (user.status not in ["administrator", "creator"]) and ((user.can_change_info is False) or (user.can_change_info is None)): 76 | await message.delete(True) 77 | return 78 | editable = await message.reply_text( 79 | text="Please Wait ...", 80 | quote=True 81 | ) 82 | await show_settings(editable) 83 | 84 | 85 | @AHBot.on_message(filters.reply & filters.text & ~filters.private & ~filters.edited) 86 | async def reply_handler(bot: Client, message: Message): 87 | if not await mongodb.is_chat_exist(message.chat.id): 88 | return 89 | user = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id) 90 | if message.reply_to_message and (Config.ASK_FOR_BLOCKED_WORDS_LIST in (message.reply_to_message.text or message.reply_to_message.caption)) and (user.status in ["administrator", "creator"]) and (user.can_change_info is True): 91 | await message.reply_to_message.delete() 92 | fetch_data = message.text.splitlines() 93 | while ("" in fetch_data): 94 | fetch_data.remove("") 95 | await mongodb.set_blocked_words(message.chat.id, fetch_data) 96 | await message.reply_text( 97 | text=f"Successfully Added Blocked Words Filter!\n\n**Blocked Words:** `{fetch_data}`", 98 | quote=True, 99 | disable_web_page_preview=True, 100 | parse_mode="Markdown", 101 | reply_markup=InlineKeyboardMarkup( 102 | [ 103 | [InlineKeyboardButton("Go Back to Settings", callback_data="goToSettings")] 104 | ] 105 | ) 106 | ) 107 | elif message.reply_to_message and (Config.ASK_FOR_BLOCKED_EXT_LIST in message.reply_to_message.text) and (user.status in ["administrator", "creator"]) and (user.can_change_info is True): 108 | await message.reply_to_message.delete() 109 | fetch_data = message.text.splitlines() 110 | while ("" in fetch_data): 111 | fetch_data.remove("") 112 | await mongodb.set_blocked_exts(message.chat.id, fetch_data) 113 | await message.reply_text( 114 | text=f"Successfully Added Blocked Extensions Filter!\n\n**Blocked Extensions:** `{fetch_data}`", 115 | quote=True, 116 | disable_web_page_preview=True, 117 | parse_mode="Markdown", 118 | reply_markup=InlineKeyboardMarkup( 119 | [ 120 | [InlineKeyboardButton("Go Back to Settings", callback_data="goToSettings")] 121 | ] 122 | ) 123 | ) 124 | 125 | 126 | @UserBot.on_message((filters.text | filters.media) & ~filters.private & ~filters.edited, group=-1) 127 | async def main_handler(_, message: Message): 128 | if not await mongodb.is_chat_exist(message.chat.id): 129 | return 130 | check_data = await mongodb.get_custom_filters(message.chat.id) 131 | blocked_words = await mongodb.get_blocked_words(message.chat.id) 132 | if (await mongodb.get_blocked_exts(message.chat.id)) is not None: 133 | is_ext_blocked = await blocked_ext_checker(message, message.chat.id) 134 | if is_ext_blocked == 400: 135 | await delete_message(message) 136 | return 137 | if ((message.forward_from or message.forward_from_chat) is not None) and ("forward" not in check_data): 138 | await delete_message(message) 139 | return 140 | if (len(check_data) == 8) or (((message.video is not None) and ("video" in check_data)) or ((message.document is not None) and ("document" in check_data)) or ((message.photo is not None) and ("photo" in check_data)) or ((message.audio is not None) and ("audio" in check_data)) or ((message.text is not None) and ("text" in check_data)) or ((message.sticker is not None) and ("sticker" in check_data)) or ((message.animation is not None) and ("gif" in check_data))): 141 | pass 142 | else: 143 | await delete_message(message) 144 | return 145 | if blocked_words is not None: 146 | loop_data = await blocked_words_loop(blocked_words, message) 147 | if loop_data == 400: 148 | await delete_message(message) 149 | return 150 | load_blocked_words = await mongodb.get_blocked_words(message.chat.id) 151 | if load_blocked_words: 152 | is_word_blocked = await blocked_words_loop(load_blocked_words, message) 153 | if is_word_blocked == 400: 154 | await delete_message(message) 155 | return 156 | allow_server_messages = await mongodb.allowServiceMessageDelete(message.chat.id) 157 | if (allow_server_messages is False) and (message.service is True): 158 | await delete_message(message) 159 | return 160 | print("Message Not Deleted!") 161 | 162 | 163 | @AHBot.on_callback_query() 164 | async def callback_handlers(bot: Client, cb: CallbackQuery): 165 | user = await bot.get_chat_member(chat_id=cb.message.chat.id, user_id=cb.from_user.id) 166 | print(f"User Status: {user.status}\nCan Change Info: {user.can_change_info}") 167 | if (user.status not in ["administrator", "creator"]) and ((user.can_change_info is False) or (user.can_change_info is None)): 168 | await cb.answer("You are not allowed to do that!", show_alert=True) 169 | return 170 | print(f"{cb.from_user.mention} Sent Callback Data:\n`{cb.data}`") 171 | if "blockFileExtensions" in cb.data: 172 | await cb.message.reply_to_message.reply_text( 173 | text=Config.ASK_FOR_BLOCKED_EXT_LIST, 174 | disable_web_page_preview=True, 175 | quote=True, 176 | reply_markup=ForceReply(selective=True) 177 | ) 178 | await cb.message.delete(True) 179 | elif "blockWords" in cb.data: 180 | await cb.message.reply_to_message.reply_text( 181 | text=Config.ASK_FOR_BLOCKED_WORDS_LIST, 182 | disable_web_page_preview=True, 183 | quote=True, 184 | reply_markup=ForceReply(selective=True) 185 | ) 186 | elif "setCustomFilters" in cb.data: 187 | await setup_callbacks_for_custom_filters(cb) 188 | elif cb.data.startswith("set_custom_filter_"): 189 | data_load = await mongodb.get_custom_filters(cb.message.chat.id) 190 | get_cb_data = cb.data.split("_", 3)[3] 191 | if get_cb_data == "default": 192 | data_load = ["video", "document", "photo", "audio", "text", "sticker", "gif", "forward"] 193 | await mongodb.set_blocked_words(id=cb.message.chat.id, blocked_words=None) 194 | await mongodb.set_blocked_exts(id=cb.message.chat.id, blocked_exts=None) 195 | await cb.answer("Changed Every Filters to Default!\nAlso Changed Blocked Words & Blocked Extensions to None.", show_alert=True) 196 | else: 197 | if get_cb_data not in data_load: 198 | data_load.append(get_cb_data) 199 | elif get_cb_data in data_load: 200 | data_load.remove(get_cb_data) 201 | await mongodb.set_custom_filters(id=cb.message.chat.id, custom_filters=data_load) 202 | await setup_callbacks_for_custom_filters(cb) 203 | elif "allowServiceMessagesDelete" in cb.data: 204 | allowServiceMessagesDelete = await mongodb.allowServiceMessageDelete(cb.message.chat.id) 205 | if allowServiceMessagesDelete is True: 206 | await mongodb.set_allowServiceMessageDelete(cb.message.chat.id, allow_service_message=False) 207 | await cb.answer("Okay!\nFrom now I will Not Delete Service Messages!", show_alert=True) 208 | elif allowServiceMessagesDelete is False: 209 | await mongodb.set_allowServiceMessageDelete(cb.message.chat.id, allow_service_message=True) 210 | await cb.answer("Okay!\nFrom now I will Delete Service Messages!", show_alert=True) 211 | await show_settings(cb.message) 212 | elif "goToSettings" in cb.data: 213 | await show_settings(cb.message) 214 | elif "showBlockedWords" in cb.data: 215 | if (await mongodb.get_blocked_words(cb.message.chat.id)) is None: 216 | await cb.answer("No Words Blocked Yet!", show_alert=True) 217 | else: 218 | await cb.message.edit( 219 | text=f"**The Below Words are Blocked in this Chat:**\n\n{'`' + '`, `'.join(await mongodb.get_blocked_words(cb.message.chat.id)) + '`'}", 220 | disable_web_page_preview=True, 221 | parse_mode="Markdown", 222 | reply_markup=InlineKeyboardMarkup( 223 | [ 224 | [InlineKeyboardButton("Go To Settings", callback_data="goToSettings")], 225 | [InlineKeyboardButton("Close ❎", callback_data="closeMeh")] 226 | ] 227 | ) 228 | ) 229 | elif "showBlockedExtensions" in cb.data: 230 | if (await mongodb.get_blocked_exts(cb.message.chat.id)) is None: 231 | await cb.answer("No File Extensions Blocked Yet!", show_alert=True) 232 | else: 233 | await cb.message.edit( 234 | text=f"**The Below File Extensions are Blocked in this Chat:**\n\n{'`' + '`, `'.join(await mongodb.get_blocked_exts(cb.message.chat.id)) + '`'}", 235 | disable_web_page_preview=True, 236 | parse_mode="Markdown", 237 | reply_markup=InlineKeyboardMarkup( 238 | [ 239 | [InlineKeyboardButton("Go To Settings", callback_data="goToSettings")], 240 | [InlineKeyboardButton("Close ❎", callback_data="closeMeh")] 241 | ] 242 | ) 243 | ) 244 | elif "closeMeh" in cb.data: 245 | await cb.message.delete(True) 246 | 247 | 248 | AHBot.start() 249 | UserBot.start() 250 | idle() 251 | UserBot.stop() 252 | AHBot.stop() 253 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Pyrogram==1.4.16 2 | TgCrypto 3 | dnspython 4 | motor 5 | -------------------------------------------------------------------------------- /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.9.4 2 | --------------------------------------------------------------------------------