Last active
March 4, 2023 14:19
-
-
Save dolohow/1fb72c317ead1a93e6da6f60946c7887 to your computer and use it in GitHub Desktop.
Delete old telegram bot messages from group chat and user commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Prerequisities | |
# pip install pyrogram tgcrypto | |
from datetime import datetime | |
from pyrogram import Client | |
# Configure here | |
api_id = | |
api_hash = '' | |
delete_older_than_days = 1 | |
chat_id = '' | |
app = Client("my_account", api_id, api_hash) | |
async def main(): | |
now = datetime.now() | |
i = 0 | |
async with app: | |
async for message in app.get_chat_history(chat_id): | |
message_age = (now - message.date).days | |
if not message.service and message_age >= delete_older_than_days: | |
if message.from_user.is_bot or (message.text and message.text.startswith('/')): | |
i += 1 | |
await message.delete() | |
print(f'Deleted {i}') | |
app.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WHERE ARE THE TESTS???111??!!!