knadh / tg-archive

A tool for exporting Telegram group chats into static websites like mailing list archives.
MIT License
885 stars 134 forks source link

skipping admin posts #54

Closed caribmorn closed 2 years ago

caribmorn commented 2 years ago

Hello,

My tg-archive seems to be skipping admin posts, ever since a group I follow has multiple admins.. The admins post under NAMEOFGROUP (Admin1) or NAMEOFGROUP (Admin2)..

Tg-archive doesn't seem to raise an exception, it just says fetched 0 messages when I point to the post in particular.

Any ideas?

Thanks in advance

caribmorn commented 2 years ago

I think it's referred to as "anonymous admins mode"

https://www.techmesto.com/manage-remain-anonymous-mode-telegram-group/

caribmorn commented 2 years ago

It seems that there is "not m.sender" like on line 131 of the sync.py.. I wonder if there would be an easy way to put a placeholder there for hidden admins, if not to get the actual userID of the account

knadh commented 2 years ago

Would you be able to figure out if m.sender has any properties that identifies it as an admin? There could be other scenarios where m.sender is null.

caribmorn commented 2 years ago

I'm not sure I understood where .sender comes from, I didn't see it in the docs.

I didn't see anything that identifies the channel as hidden admin (like when I would print out all the info in client.get_entity(self.config["group"]).. That said I'm kind of new to this so maybe someone else should take a look.

That said, I managed a (ahem: quite ugly) workaround, basically it's the following:

1) i took out the verification if there is no m_sender, so it doesn't stop there 2) in _get_user(), it crashes due to no u.username (since it's a "group" posting, so i put the whole thing in an try: except:, and in the except: I put the following:

    m=self.client.get_entity(self.config["group"])`
    avatar = None
    if self.config["download_avatars"]:
        try:
            fname = self._download_avatar(m)
            avatar = fname
        except Exception as e:
            logging.error(
                "error downloading avatar: #{}: {}".format(m.id, e))        
    return User(
        id=m.id,
        username=m.title + " " + post_author,
        first_name=None,
        last_name=None,
        tags="",
        avatar=avatar
    `)``

so basically the try: is for normal messages from a user, and the except is for groups that posted under a groupname quite ugly I know, I'm too impatient to make stuff pythonic but I think it shows a way for people that are better coders. Maybe it introduces other problems (I'm not sure why the code checks for "not m.sender" to begin with, but anyhow.)

caribmorn commented 2 years ago

Poked around some more with GetFullChannelRequest and didn't see anything that shows that it's anonymous admins..

At this point my fix works for my purposes, I'll probably stop poking around and use that.

caribmorn commented 2 years ago

Would you be able to figure out if m.sender has any properties that identifies it as an admin? There could be other scenarios where m.sender is null.

Well, what I find stands out for those posts (in the channel I'm looking at) are that the message has "from_Id=None' and "post_author='Adminname'. Are they all like that? I'm not sure. Are there other scenarios where m.sender is null? I'm not sure..

That said, if the code checks for a combination of no sender, and a post_author, that seems to be a pretty specific combination that is worth scraping.

To specifically address your question though, I don't know other situations where there is no sender, and I don't really know how to find out. And no, I didn't see a flag that is something along the lines of "anonymous sender".