├── .env.sample ├── .gitignore ├── Procfile ├── README.md ├── app.json ├── bot.py ├── plugins └── main.py ├── requirements.txt ├── settings.py └── userbot.py /.env.sample: -------------------------------------------------------------------------------- 1 | API_ID= 2 | API_HASH= 3 | BOT_TOKEN= 4 | SESSION= 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | __pycache__/ 3 | .gitattributes 4 | .env -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 bot.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [Delete All Bot](https://t.me/StarkDeleteAllBot) 2 | 3 | > A star ⭐ from you means a lot to me ! 4 | 5 | #### Telegram bot to delete all messages in a group 6 | 7 | [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) 8 | 9 | ## Deployment 10 | 11 | ### Deploy to Heroku 12 | 13 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 14 | 15 | 1. Tap on above button and fill values for needed variables 16 | 2. Then tap "Deploy App" below it. Wait till deploying is complete (will take atmost 2 minutes). 17 | 3. After deploying is complete, tap on "Manage App" 18 | 4. Check the logs to see if your bot is ready! 19 | 20 | ### Local Deploying 21 | 22 | 1. Clone the repo 23 | ```markdown 24 | git clone https://github.com/StarkBotsIndustries/DeleteAllBot 25 | ``` 26 | 2. Rename `.env.sample` to `.env` and fill values 27 | 28 | 29 | 3. Enter the directory 30 | ```markdown 31 | cd DeleteAllBot 32 | ``` 33 | 4. Run the file 34 | ```markdown 35 | python3 bot.py 36 | ``` 37 | 38 | ## Environment Variables 39 | 40 | #### Mandatory Vars 41 | 42 | - `API_ID` - Get this from [my.telegram.org](https://my.telegram.org/auth) 43 | - `API_HASH` - Get this from [my.telegram.org](https://my.telegram.org/auth) 44 | - `BOT_TOKEN` - Get this from [@BotFather](https://t.me/BotFather) 45 | - `SESSION` - Pyrogram String Session. Can be generated using [String Session Generator](https://t.me/StarkStringGenBot) 46 | 47 | ## Credits 48 | 49 | - [Dan Tès](https://github.com/delivrance) for his [Pyrogram](https://docs.pyrogram.org) Library 50 | 51 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 52 | 53 | ## Support 54 | 55 | Channel :- [@StarkBots](https://t.me/StarkBots) 56 | 57 | Group Chat :- [@StarkBotsChat](https://t.me/StarkBotsChat) 58 | 59 | ## :) 60 | 61 | [![ForTheBadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/) 62 | 63 | [![ForTheBadge built-with-love](http://ForTheBadge.com/images/badges/built-with-love.svg)](https://github.com/StarkBotsIndustries) 64 | 65 | [![ForTheBadge makes-people-smile](http://ForTheBadge.com/images/badges/makes-people-smile.svg)](https://github.com/StarkBotsIndustries) 66 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Delete All Bot", 3 | "description": "Telegram bot to delete all messages", 4 | "logo": "https://telegra.ph/file/da5e146a42d1361958065.jpg", 5 | "keywords": [ 6 | "telegram", 7 | "bot", 8 | "python", 9 | "pyrogram" 10 | ], 11 | "buildpacks": [{ 12 | "url": "heroku/python" 13 | }], 14 | "formation": { 15 | "worker": { 16 | "quantity": 1, 17 | "size": "free" 18 | } 19 | }, 20 | "addons": [ 21 | { 22 | "options": { 23 | "version": "12" 24 | }, 25 | "plan": "heroku-postgresql" 26 | } 27 | ], 28 | "repository": "https://github.com/StarkBotsIndustries/DeleteAllBot", 29 | "env": { 30 | "API_ID": { 31 | "description": "Get this value from my.telegram.org.", 32 | "required": true, 33 | "value": "" 34 | }, 35 | "API_HASH": { 36 | "description": "Get this value from my.telegram.org.", 37 | "required": true, 38 | "value": "" 39 | }, 40 | "BOT_TOKEN": { 41 | "description": "Obtain a Telegram bot token by contacting @BotFather", 42 | "required": true, 43 | "value": "" 44 | }, 45 | "SESSION": { 46 | "description": "Pyrogram String Session using t.me/StarkStringGenBot", 47 | "required": true, 48 | "value": "" 49 | }, 50 | "OWNER_ID": { 51 | "description": "Your Telegram ID", 52 | "required": false, 53 | "value": "" 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | from pystark import Stark 2 | from userbot import userbot 3 | 4 | 5 | if __name__ == "__main__": 6 | bot = Stark() 7 | userbot.start() 8 | bot.activate() 9 | -------------------------------------------------------------------------------- /plugins/main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import logging 3 | from userbot import userbot 4 | from pystark import Stark, Message 5 | from pyrogram.errors import UserAlreadyParticipant, FloodWait 6 | 7 | 8 | @Stark.cmd('delall', description="Delete all messages in a group/channel") 9 | async def main_func(bot: Stark, msg: Message): 10 | if msg.chat.type == "private": 11 | return 12 | if msg.chat.type != "channel": 13 | user = await bot.get_chat_member(msg.chat.id, msg.from_user.id) 14 | if user.status not in ['creator', 'administrator']: 15 | return 16 | if not user.can_delete_messages: 17 | await msg.react("You don't have `CanDeleteMessages` right. Sorry!") 18 | return 19 | bot_id = (await bot.get_me()).id 20 | cm = await bot.get_chat_member(msg.chat.id, bot_id) 21 | if cm.status != "administrator": 22 | await msg.react("I'm not admin here!") 23 | return 24 | elif not cm.can_promote_members: 25 | await msg.react("I can't promote users here. I need that right to work.") 26 | return 27 | elif not cm.can_delete_messages: 28 | await msg.react("I can't delete messages here. I need that right to work.") 29 | return 30 | link = (await bot.get_chat(msg.chat.id)).invite_link 31 | try: 32 | await userbot.join_chat(link) 33 | except UserAlreadyParticipant: 34 | pass 35 | userbot_id = (await userbot.get_me()).id 36 | await bot.promote_chat_member( 37 | msg.chat.id, 38 | userbot_id, 39 | can_delete_messages=True 40 | ) 41 | numbers = [] 42 | while True: 43 | try: 44 | async for m in userbot.iter_history(msg.chat.id): 45 | numbers.append(m.message_id) 46 | break 47 | except FloodWait as e: 48 | await msg.react(f"You need to wait for: {e.x} seconds. \n\nTelegram Restrictions!") 49 | await asyncio.sleep(e.x) 50 | id_lists = [numbers[i*100:(i+1)*100] for i in range((len(numbers)+100-1) // 100)] 51 | status = await msg.reply("Trying to delete all messages...") 52 | for id_list in id_lists: 53 | while True: 54 | try: 55 | await userbot.delete_messages(msg.chat.id, id_list) 56 | break 57 | except FloodWait as e: 58 | await asyncio.sleep(e.x) 59 | Stark.log(str(e), logging.WARN) 60 | await msg.react("Successful! Deleted Everything. For more bots visit @StarkBots") 61 | await status.delete() 62 | await userbot.leave_chat(msg.chat.id) 63 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pystark==1.* 2 | -------------------------------------------------------------------------------- /settings.py: -------------------------------------------------------------------------------- 1 | START = "delete all messages in your group or channel." 2 | 3 | HELP = "/delall - Delete All Messages" 4 | 5 | ABOUT = "A telegram bot to delete all messages in a group or channel" 6 | 7 | REPO = "DeleteAllBot" 8 | 9 | DATABASE_TABLES = ["users"] 10 | 11 | STARKBOTS = True 12 | -------------------------------------------------------------------------------- /userbot.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pyrogram import Client 3 | 4 | SESSION = os.environ.get('SESSION') 5 | 6 | 7 | userbot = Client( 8 | SESSION, 9 | api_id=int(os.environ.get('API_ID')), 10 | api_hash=os.environ.get("API_HASH") 11 | ) 12 | --------------------------------------------------------------------------------