Skip to content

Instantly share code, notes, and snippets.

@ggrandes
Forked from alexandernst/ninja.py
Last active November 2, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggrandes/80562dfa54072d22aecb2ac88ff4ef02 to your computer and use it in GitHub Desktop.
Save ggrandes/80562dfa54072d22aecb2ac88ff4ef02 to your computer and use it in GitHub Desktop.
Delete our Messages from Telegram

Instalacion y uso

Logueate en tu cuenta de Telegram desde https://my.telegram.org/

Ve a API Development toolsy de allí a Create new application, crea una con cualquier cosa, y modifica en el script API ID y API Hash

Dependencias

pip3 install telethon

O

pip3 install -U telethon --user

Dependencias

pip install -U --user setuptools
pip install -U --user telethon

Ejecucion:

python3 ninja.py

Enlaces de interes:

#!/usr/bin/python3
# ninja+
import datetime
from telethon import TelegramClient, sync, utils
# changeit
api_id = 123456789
api_hash = 'abcdef123456789'
client = TelegramClient('session_name', api_id, api_hash)
client.session.report_errors = True
client.start()
me = client.get_me()
print("IAM:", utils.get_display_name(me))
delete_me_from = [
"#BOFHers",
]
delta_time = 24 # Messages sent more than X hours ago
delta_time_tags = 24 * 300 # Preserve Taged messages X hours
delta_time_links = 24 * 30 # Preserve Links X hours
try:
chats = client.iter_dialogs()
for chat in chats:
if chat.name in delete_me_from:
delete_ids = []
messages = client.iter_messages(chat, 200, from_user = me, wait_time = 5, reverse = True)
now = datetime.datetime.now(tz=datetime.timezone.utc)
for message in messages:
delta = now - message.date
time = delta.total_seconds() / 60 / 60
if time > delta_time: # Expired
if "#" in message.text and time < delta_time_tags:
# Ignore Tags
print("ignored:", message.id, message.date, message.text)
elif "://" in message.text and time < delta_time_links:
# Ignore Tags
print("ignored:", message.id, message.date, message.text)
else:
print("delete:", message.id, message.date, message.text)
delete_ids.append(message.id)
else:
print("break:", message.id, message.date, message.text)
break
print("delete:", delete_ids)
client.delete_messages(chat, delete_ids) # Delete marked messages
except Exception as e:
print("exception:", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment