Comments (25)
@erbanku @SiNaPsEr0x @xanoni
I think it apparently works if you edit your cleaner.py and replace this:
offset_date=dialogs[-1].top_message.date
by this
offset_date=dialogs[-1].top_message.date[-1]
Test and tell me if it works for you, I got the info from here:
https://githubmemory.com/repo/pyrogram/pyrogram/issues/749
from telegram-delete-all-messages.
@erbanku not sure if you did something wrong or I changed something more but if I did it's next to the option I changed, I will share all the text that worked for me, all my messages were deleted from the channel I chose.
from time import sleep from os import getenv from pyrogram import Client from pyrogram.raw.functions.messages import Search from pyrogram.raw.types import InputPeerSelf, InputMessagesFilterEmpty from pyrogram.raw.types.messages import ChannelMessages from pyrogram.errors import FloodWait, UnknownError API_ID = getenv('API_ID', None) or int(input('Enter your Telegram API id: ')) API_HASH = getenv('API_HASH', None) or input('Enter your Telegram API hash: ') app = Client("client", api_id=API_ID, api_hash=API_HASH) app.start() class Cleaner: def __init__(self, chats=None, search_chunk_size=100, delete_chunk_size=100): self.chats = chats or [] if search_chunk_size > 100: # https://github.com/gurland/telegram-delete-all-messages/issues/31 # # The issue is that pyrogram.raw.functions.messages.Search uses # pagination with chunks of 100 messages. Might consider switching # to search_messages, which handles pagination transparently. raise ValueError('search_chunk_size > 100 not supported') self.search_chunk_size = search_chunk_size self.delete_chunk_size = delete_chunk_size @staticmethod def chunks(l, n): """Yield successive n-sized chunks from l. https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks#answer-312464""" for i in range(0, len(l), n): yield l[i:i + n] @staticmethod def get_all_chats(): dialogs = app.get_dialogs(pinned_only=True) dialog_chunk = app.get_dialogs() while len(dialog_chunk) > 0: dialogs.extend(dialog_chunk) dialog_chunk = app.get_dialogs(offset_date=dialogs[-1].top_message.date-1) return [d.chat for d in dialogs] def select_groups(self): chats = self.get_all_chats() groups = [c for c in chats if c.type in ('group', 'supergroup')] print('Delete all your messages in') for i, group in enumerate(groups): print(f' {i+1}. {group.title}') print( f' {len(groups) + 1}. ' '(!) DELETE ALL YOUR MESSAGES IN ALL OF THOSE GROUPS (!)\n' ) n = int(input('Insert option number: ')) if not 1 <= n <= len(groups) + 1: print('Invalid option selected. Exiting...') exit(-1) if n == len(groups) + 1: print('\nTHIS WILL DELETE ALL YOUR MESSSAGES IN ALL GROUPS!') answer = input('Please type "I understand" to proceed: ') if answer.upper() != 'I UNDERSTAND': print('Better safe than sorry. Aborting...') exit(-1) self.chats = groups else: self.chats = [groups[n - 1]] groups_str = ', '.join(c.title for c in self.chats) print(f'\nSelected {groups_str}.\n') def run(self): for chat in self.chats: peer = app.resolve_peer(chat.id) message_ids = [] add_offset = 0 while True: q = self.search_messages(peer, add_offset) message_ids.extend(msg.id for msg in q['messages']) messages_count = len(q['messages']) print(f'Found {messages_count} of your messages in "{chat.title}"') if messages_count < self.search_chunk_size: break add_offset += self.search_chunk_size self.delete_messages(chat.id, message_ids) def delete_messages(self, chat_id, message_ids): print(f'Deleting {len(message_ids)} messages with message IDs:') print(message_ids) for chunk in self.chunks(message_ids, self.delete_chunk_size): try: app.delete_messages(chat_id=chat_id, message_ids=chunk) except FloodWait as flood_exception: sleep(flood_exception.x) def search_messages(self, peer, add_offset): print(f'Searching messages. OFFSET: {add_offset}') return app.send( Search( peer=peer, q='', filter=InputMessagesFilterEmpty(), min_date=0, max_date=0, offset_id=0, add_offset=add_offset, limit=self.search_chunk_size, max_id=0, min_id=0, hash=0, from_id=InputPeerSelf() ), sleep_threshold=60 ) if __name__ == '__main__': try: deleter = Cleaner() deleter.select_groups() deleter.run() except UnknownError as e: print(f'UnknownError occured: {e}') print('Probably API has changed, ask developers to update this utility') finally: app.stop()
This worked for me too now.
And I can normally run the original script without do any changes.
great, I was getting the sleeping error till I did the change, anyway I don't mind while it works.
from telegram-delete-all-messages.
This problem is occurring since about 21 days ago, below is my issue submission at that time.
It will show the error message as shown in most cases, but occasionally it works fine (fixes by itself😅), perhaps requiring the author to fix the issue & adapt to Telegram.
As far as I see, pyrogram received a hotfix about 6 days ago about this. I think maybe script need to be readapted
from telegram-delete-all-messages.
Suggest you delete config files, reinstall the Pyrogram & Tgcrypto as well and run the script again. Or Just re-clone the repo and run it in a new folder.
I did that, I think youre doing the tests wrong but I dit said nothing before because you said is working do I dont mind
Before I made the changed I reinstalled all
its and index in an array, that expression I changed the index is the one program is not using.
its an assigment so it doesnt matter pyrogram fixed it. Maybe it doesnt happen to all users, maybe it depends on the number of messages or channel you are in
from telegram-delete-all-messages.
Suggest you delete config files, reinstall the Pyrogram & Tgcrypto as well and run the script again. Or Just re-clone the repo and run it in a new folder.
I did that, I think youre doing the tests wrong but I dit said nothing before because you said is working do I dont mind
Before I made the changed I reinstalled all
its and index in an array, that expression I changed the index is the one program is not using.
its an assigment so it doesnt matter pyrogram fixed it. Maybe it doesnt happen to all users, maybe it depends on the number of messages or channel you are inSorry, there maybe some misunderstanding,this message should to be for @xanoni
No, the messages was address to you.
Because you said it works by default.
I already read that yesterday, but I'm glad it worked for you but I made sure it was failing to me before proposing the change. I deleted everything, I downloaded the script again and I checked pyrogram was up to date.
from telegram-delete-all-messages.
Fixed in #47
from telegram-delete-all-messages.
This problem is occurring since about 21 days ago, below is my issue submission at that time.
It will show the error message as shown in most cases, but occasionally it works fine (fixes by itself😅), perhaps requiring the author to fix the issue & adapt to Telegram.
from telegram-delete-all-messages.
This problem is occurring since about 21 days ago, below is my issue submission at that time.
It will show the error message as shown in most cases, but occasionally it works fine (fixes by itselfsweat_smile), perhaps requiring the author to fix the issue & adapt to Telegram.
you can push your fix..
from telegram-delete-all-messages.
This problem is occurring since about 21 days ago, below is my issue submission at that time.
It will show the error message as shown in most cases, but occasionally it works fine (fixes by itselfsweat_smile), perhaps requiring the author to fix the issue & adapt to Telegram.
you can push your fix..
Read again what I wrote, please, in order to make your answer makes sense.
from telegram-delete-all-messages.
Ack, same problem.
from telegram-delete-all-messages.
@erbanku @SiNaPsEr0x @xanoni I think it apparently works if you edit your cleaner.py and replace this:
offset_date=dialogs[-1].top_message.date by this offset_date=dialogs[-1].top_message.date-1
Test and tell me if it works for you, I got the info from here:
The original script continued working without changing anything for me.
I tested your method, changed the offset_date=dialogs[-1].top_message.date
to offset_date=dialogs[-1].top_message.date-1
, after change, the script doesn't work, cannot delete the message.
from telegram-delete-all-messages.
@MikeSeaver555
The problem may be to do with Pyrogram. As the Pyrogram bug fixes the script naturally continues to work properly.
from telegram-delete-all-messages.
@erbanku not sure if you did something wrong or I changed something else but if I did it's next to the option I changed, I will share all the text that worked for me, all my messages were deleted from the channel I chose.
from time import sleep
from os import getenv
from pyrogram import Client
from pyrogram.raw.functions.messages import Search
from pyrogram.raw.types import InputPeerSelf, InputMessagesFilterEmpty
from pyrogram.raw.types.messages import ChannelMessages
from pyrogram.errors import FloodWait, UnknownError
API_ID = getenv('API_ID', None) or int(input('Enter your Telegram API id: '))
API_HASH = getenv('API_HASH', None) or input('Enter your Telegram API hash: ')
app = Client("client", api_id=API_ID, api_hash=API_HASH)
app.start()
class Cleaner:
def __init__(self, chats=None, search_chunk_size=100, delete_chunk_size=100):
self.chats = chats or []
if search_chunk_size > 100:
# https://github.com/gurland/telegram-delete-all-messages/issues/31
#
# The issue is that pyrogram.raw.functions.messages.Search uses
# pagination with chunks of 100 messages. Might consider switching
# to search_messages, which handles pagination transparently.
raise ValueError('search_chunk_size > 100 not supported')
self.search_chunk_size = search_chunk_size
self.delete_chunk_size = delete_chunk_size
@staticmethod
def chunks(l, n):
"""Yield successive n-sized chunks from l.
https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks#answer-312464"""
for i in range(0, len(l), n):
yield l[i:i + n]
@staticmethod
def get_all_chats():
dialogs = app.get_dialogs(pinned_only=True)
dialog_chunk = app.get_dialogs()
while len(dialog_chunk) > 0:
dialogs.extend(dialog_chunk)
dialog_chunk = app.get_dialogs(offset_date=dialogs[-1].top_message.date-1)
return [d.chat for d in dialogs]
def select_groups(self):
chats = self.get_all_chats()
groups = [c for c in chats if c.type in ('group', 'supergroup')]
print('Delete all your messages in')
for i, group in enumerate(groups):
print(f' {i+1}. {group.title}')
print(
f' {len(groups) + 1}. '
'(!) DELETE ALL YOUR MESSAGES IN ALL OF THOSE GROUPS (!)\n'
)
n = int(input('Insert option number: '))
if not 1 <= n <= len(groups) + 1:
print('Invalid option selected. Exiting...')
exit(-1)
if n == len(groups) + 1:
print('\nTHIS WILL DELETE ALL YOUR MESSSAGES IN ALL GROUPS!')
answer = input('Please type "I understand" to proceed: ')
if answer.upper() != 'I UNDERSTAND':
print('Better safe than sorry. Aborting...')
exit(-1)
self.chats = groups
else:
self.chats = [groups[n - 1]]
groups_str = ', '.join(c.title for c in self.chats)
print(f'\nSelected {groups_str}.\n')
def run(self):
for chat in self.chats:
peer = app.resolve_peer(chat.id)
message_ids = []
add_offset = 0
while True:
q = self.search_messages(peer, add_offset)
message_ids.extend(msg.id for msg in q['messages'])
messages_count = len(q['messages'])
print(f'Found {messages_count} of your messages in "{chat.title}"')
if messages_count < self.search_chunk_size:
break
add_offset += self.search_chunk_size
self.delete_messages(chat.id, message_ids)
def delete_messages(self, chat_id, message_ids):
print(f'Deleting {len(message_ids)} messages with message IDs:')
print(message_ids)
for chunk in self.chunks(message_ids, self.delete_chunk_size):
try:
app.delete_messages(chat_id=chat_id, message_ids=chunk)
except FloodWait as flood_exception:
sleep(flood_exception.x)
def search_messages(self, peer, add_offset):
print(f'Searching messages. OFFSET: {add_offset}')
return app.send(
Search(
peer=peer,
q='',
filter=InputMessagesFilterEmpty(),
min_date=0,
max_date=0,
offset_id=0,
add_offset=add_offset,
limit=self.search_chunk_size,
max_id=0,
min_id=0,
hash=0,
from_id=InputPeerSelf()
),
sleep_threshold=60
)
if __name__ == '__main__':
try:
deleter = Cleaner()
deleter.select_groups()
deleter.run()
except UnknownError as e:
print(f'UnknownError occured: {e}')
print('Probably API has changed, ask developers to update this utility')
finally:
app.stop()
from telegram-delete-all-messages.
Let me know if it doesn't work, then you probably hasn't been suffering from a different error.
from telegram-delete-all-messages.
It worked perfect for me, no messages in the channel I chose (I replaced the channel name by CHANNEL, so it's not the real name)
Insert option number: 10
Selected <CHANNEL>.
Searching messages. OFFSET: 0
Found 100 of your messages in <CHANNEL>
Searching messages. OFFSET: 100
Found 100 of your messages in <CHANNEL>
Searching messages. OFFSET: 200
Found 84 of your messages in <CHANNEL>
Deleting 284 messages with message IDs:
[366176, 366175, 366172, 366171, 366170, 366169, 366166, 366164, 366160, 366158, 366155, 366153, 366152, 366151, 366149, 366148, 366147, 366087, 366086, 366067, 366063, 366062, 366061, 366060, 365900, 365860, 365843, 365841, 365709, 365656, 365655, 365510, 365500, 365498, 365497, 365496, 365470, 365467, 365466, 365464, 365463, 365461, 365459, 365457, 365456, 365455, 365452, 365446, 365396, 365376, 365375, 365371, 365370, 365368, 365365, 365318, 365146, 365107, 365104, 365098, 365097, 365095, 365092, 365090, 365089, 365088, 365084, 365083, 365078, 365076, 365071, 365069, 365068, 365067, 365066, 365065, 365063, 365062, 364998, 364997, 364996, 364995, 364994, 364993, 364990, 364983, 364982, 364974, 364973, 364972, 364971, 364970, 364969, 364928, 364927, 364923, 364853, 364758, 364748, 364746, 364689, 364685, 364684, 364682, 364681, 364678, 364672, 364671, 364670, 364667, 364664, 364662, 364651, 364650, 364648, 364645, 364644, 364639, 364637, 364634, 364612, 364555, 364532, 364470, 364469,...
from telegram-delete-all-messages.
@erbanku not sure if you did something wrong or I changed something more but if I did it's next to the option I changed, I will share all the text that worked for me, all my messages were deleted from the channel I chose.
from time import sleep from os import getenv from pyrogram import Client from pyrogram.raw.functions.messages import Search from pyrogram.raw.types import InputPeerSelf, InputMessagesFilterEmpty from pyrogram.raw.types.messages import ChannelMessages from pyrogram.errors import FloodWait, UnknownError API_ID = getenv('API_ID', None) or int(input('Enter your Telegram API id: ')) API_HASH = getenv('API_HASH', None) or input('Enter your Telegram API hash: ') app = Client("client", api_id=API_ID, api_hash=API_HASH) app.start() class Cleaner: def __init__(self, chats=None, search_chunk_size=100, delete_chunk_size=100): self.chats = chats or [] if search_chunk_size > 100: # https://github.com/gurland/telegram-delete-all-messages/issues/31 # # The issue is that pyrogram.raw.functions.messages.Search uses # pagination with chunks of 100 messages. Might consider switching # to search_messages, which handles pagination transparently. raise ValueError('search_chunk_size > 100 not supported') self.search_chunk_size = search_chunk_size self.delete_chunk_size = delete_chunk_size @staticmethod def chunks(l, n): """Yield successive n-sized chunks from l. https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks#answer-312464""" for i in range(0, len(l), n): yield l[i:i + n] @staticmethod def get_all_chats(): dialogs = app.get_dialogs(pinned_only=True) dialog_chunk = app.get_dialogs() while len(dialog_chunk) > 0: dialogs.extend(dialog_chunk) dialog_chunk = app.get_dialogs(offset_date=dialogs[-1].top_message.date-1) return [d.chat for d in dialogs] def select_groups(self): chats = self.get_all_chats() groups = [c for c in chats if c.type in ('group', 'supergroup')] print('Delete all your messages in') for i, group in enumerate(groups): print(f' {i+1}. {group.title}') print( f' {len(groups) + 1}. ' '(!) DELETE ALL YOUR MESSAGES IN ALL OF THOSE GROUPS (!)\n' ) n = int(input('Insert option number: ')) if not 1 <= n <= len(groups) + 1: print('Invalid option selected. Exiting...') exit(-1) if n == len(groups) + 1: print('\nTHIS WILL DELETE ALL YOUR MESSSAGES IN ALL GROUPS!') answer = input('Please type "I understand" to proceed: ') if answer.upper() != 'I UNDERSTAND': print('Better safe than sorry. Aborting...') exit(-1) self.chats = groups else: self.chats = [groups[n - 1]] groups_str = ', '.join(c.title for c in self.chats) print(f'\nSelected {groups_str}.\n') def run(self): for chat in self.chats: peer = app.resolve_peer(chat.id) message_ids = [] add_offset = 0 while True: q = self.search_messages(peer, add_offset) message_ids.extend(msg.id for msg in q['messages']) messages_count = len(q['messages']) print(f'Found {messages_count} of your messages in "{chat.title}"') if messages_count < self.search_chunk_size: break add_offset += self.search_chunk_size self.delete_messages(chat.id, message_ids) def delete_messages(self, chat_id, message_ids): print(f'Deleting {len(message_ids)} messages with message IDs:') print(message_ids) for chunk in self.chunks(message_ids, self.delete_chunk_size): try: app.delete_messages(chat_id=chat_id, message_ids=chunk) except FloodWait as flood_exception: sleep(flood_exception.x) def search_messages(self, peer, add_offset): print(f'Searching messages. OFFSET: {add_offset}') return app.send( Search( peer=peer, q='', filter=InputMessagesFilterEmpty(), min_date=0, max_date=0, offset_id=0, add_offset=add_offset, limit=self.search_chunk_size, max_id=0, min_id=0, hash=0, from_id=InputPeerSelf() ), sleep_threshold=60 ) if __name__ == '__main__': try: deleter = Cleaner() deleter.select_groups() deleter.run() except UnknownError as e: print(f'UnknownError occured: {e}') print('Probably API has changed, ask developers to update this utility') finally: app.stop()
This worked for me too now.
And I can normally run the original script without do any changes.
from telegram-delete-all-messages.
Test and tell me if it works for you, I got the info from here:
Thank you so much ... this works perfectly fine now... do you understand if this is just a workaround until this gets fixed in Pyrogram, or is it a permanent change?
If permanent: #47
from telegram-delete-all-messages.
This is the problem of Pyrogram, and Pyrogram has fixed the issue already, so we can run it normally as usual. You don't need to do any changes to the original script.
Test and tell me if it works for you, I got the info from here:
Thank you so much ... this works perfectly fine now... do you understand if this is just a workaround until this gets fixed in Pyrogram, or is it a permanent change?
If permanent: #47
from telegram-delete-all-messages.
should we then at least specify a version that works in the requirements.txt
?
In which version was this fixed?
EDIT: I still see the version from April on PyPI — https://pypi.org/project/Pyrogram/#history
from telegram-delete-all-messages.
should we then at least specify a version that works in the
requirements.txt
?In which version was this fixed?
EDIT: I still see the version from April on PyPI — https://pypi.org/project/Pyrogram/#history
The latest version of Pyrogram (1.2.9) works for me.
requirements.txt
pyrogram
tgcrypto # Optional, for faster cleaning. You could remove this line
from telegram-delete-all-messages.
Suggest you delete config files, reinstall the Pyrogram & Tgcrypto as well and run the script again. Or Just re-clone the repo and run it in a new folder.
from telegram-delete-all-messages.
Suggest you delete config files, reinstall the Pyrogram & Tgcrypto as well and run the script again. Or Just re-clone the repo and run it in a new folder.
I did that, I think youre doing the tests wrong but I dit said nothing before because you said is working do I dont mind
Before I made the changed I reinstalled all
its and index in an array, that expression I changed the index is the one program is not using.
its an assigment so it doesnt matter pyrogram fixed it. Maybe it doesnt happen to all users, maybe it depends on the number of messages or channel you are in
Sorry, there maybe some misunderstanding,this message should to be for @xanoni
from telegram-delete-all-messages.
Suggest you delete config files, reinstall the Pyrogram & Tgcrypto as well and run the script again. Or Just re-clone the repo and run it in a new folder.
I thought I did that last week or so, but will try again
from telegram-delete-all-messages.
You can read here what people says:
https://githubmemory.com/repo/pyrogram/pyrogram/issues/749
With 189 dialogs in total. It continues to loop as dialog as if not dialogs will never be true. I tried it with offset_date = dialogs[-1].top_message.date+1 to return zero dialogs (because there shouldn't be any dialogs after the last dialog) but it keeps returning the last dialog //edit -1 should work!
And you can read here how Pyrogram fixed that.
They deleted this conditional (very related what we were experienced)
if offset_date == dialogs[-1].top_message.date:
Pretty coincidence "dialogs[-1].top_message.date" is the same we had to change to make script works.
from telegram-delete-all-messages.
Pretty coincidence "dialogs[-1].top_message.date" is the same we had to change to make script works.
If I understand this upstream change correctly, then we will no longer need your fix once Pyrogram is updated in PyPI, correct? (Whenever that will be.)
from telegram-delete-all-messages.
Related Issues (20)
- Needs to readapt to the latest version of Pyrogram HOT 7
- SyntaxError: invalid syntax HOT 1
- Doesn't show groups that you haven't joined but have messages in
- [Feature Request] Add command line mode with args HOT 1
- [bug] update pyrogram HOT 1
- The older messages are not getting deleted. HOT 2
- TypeError: get_dialogs() got an unexpected keyword argument 'pinned_only' HOT 4
- Forward all group messages to another group? HOT 1
- Some groups are listed twice HOT 1
- Not deleting all massages HOT 1
- Syntax error line 72 print(f' {i+1}. {group.title}') HOT 2
- Error HOT 1
- Sorry if this is a bad way to ask HOT 1
- It used to run the script very well, but in the last few days it reported the following error: HOT 6
- TypeError: get_dialogs() got an unexpected keyword argument 'pinned_only' HOT 2
- I ran the script today and found the following error: HOT 1
- If you see an error UnicodeEncodeError: 'ascii' codec can't encode characters
- msg_id is too low error HOT 5
- not working HOT 1
- get_dialogs() got an unexpected keyword argument 'pinned_only' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telegram-delete-all-messages.