aahnik / tgcf

The ultimate tool to automate custom telegram message forwarding. Live-syncer, Auto-poster, backup-bot, cloner, chat-forwarder, duplicator, ... Call it whatever you like! tgcf can fulfill your custom needs.
https://github.com/aahnik/tgcf/wiki
MIT License
1.29k stars 775 forks source link

[Plugin] Sender #478

Closed MobCode100 closed 7 months ago

MobCode100 commented 11 months ago

Plugin description:

Change the sender of forwarded messages other than the currently logged in user/bot.

Problems:

  1. When logged in as a user, destinations do not receive notifications because the user is the one who sent the messages. This can be problematic, particularly for destinations that only have the user as a member. The issue can be resolved by having messages sent by another user/bot.
  2. As Telegram only allows bots to join a channel when the channel owner adds them, which works well for private channels but poses limitations for public channels. A workaround for this issue is to log in to tgcf as the user who has already joined the public channel and then utilize a bot as the forwarder.

Solution:

tgcf will login an additional client and use it to forward received messages with the condition that the client has permission to send messages to the destinations.

Key changes:

I think my use case of tgcf is a bit weird here, but the plugin satisfies my needs. I tried my best to follow existing code style. Sorry if I made mistakes and please do point out for my self improvement. Feel free to change anything that I've made. Thank you so much for this great project!

I have fully read and understood the terms and conditions laid down in the general Contributor License Agreement

aahnik commented 11 months ago

This is amazing work 👏🔥🎊

Thanks for your efforts in improving tgcf 😎

MobCode100 commented 11 months ago

Thank you! Your project helps me a lot, and for that I want to help as best as I can ^_^.

MobCode100 commented 11 months ago

The plugin had a problem with sending media files. The force push just now fixes the problem. Now, I can confirm the plugin works as expected. Sorry for that 🙏.

poliandro commented 11 months ago

If you try to send messages to your own channel, why don't you use the bot directly?

MobCode100 commented 11 months ago

If you try to send messages to your own channel, why don't you use the bot directly?

I want to forward the messages from a public channel, and telegram doesn't allow bot to join a public channel unless the owner of that channel adds it. So the flow will be like, log in user account to read public channels messages, then use bot / other user account to send them.

poliandro commented 11 months ago

I understand now. This is a cool feature. This could be developed further. Make a list of bots, when one hits the limit of forwarded messages, change to next. This will help with copying big chats. You think is possible?

MobCode100 commented 11 months ago

I understand now. This is a cool feature. This could be developed further. Make a list of bots, when one hits the limit of forwarded messages, change to next. This will help with copying big chats. You think is possible?

I see thank you for the idea and info. I didn't know that bots have limits for forwarding messages. This is possible, but I need to know exactly what's the limit for a bot for sending messages and for how long the cool down is e.g. 1000 messages per hour. If I can get that, I could think of a way to implement it.

poliandro commented 11 months ago

I found this. Kind of old, I don't know if it still holds true. And this that seems to confirm, but telegram changed a lot of things lately.

Bots seem to have more restrictions than users. Only a real forward with a bot can tell the real limit.

MobCode100 commented 11 months ago

I found this. Kind of old, I don't know if it still holds true. And this that seems to confirm, but telegram changed a lot of things lately.

Bots seem to have more restrictions than users. Only a real forward with a bot can tell the real limit.

Great information, @poliandro, thank you. I noticed that there are differences in the limits between sending and forwarding messages. This plugin doesn't support forwarding messages, as it's intended for different accounts that don't have access to the original messages, channel, or group. Therefore, it will use the sending limit.

Additionally, looking at how tgcf is currently implemented, only the past mode has a higher chance of reaching the limit, but even then, we can set a delay between sending messages. It is unlikely to be limited using live mode, unless the source itself spams messages, which I have never experienced until this day using Telegram. We would need more real tests and real use cases before we can further improve tgcf in working around Telegram limitations.

poliandro commented 11 months ago

Yes, past mode is the one that will mostly hit limits when the source has many messages, but even live mode can encounter issues . What is the difference between sending and forwarding? Your plugin will work in both live and past, right?

MobCode100 commented 11 months ago

Yes, past mode is the one that will mostly hit limits when the source has many messages, but even live mode can encounter issues . What is the difference between sending and forwarding? Your plugin will work in both live and past, right?

I see, the issue is still open. Great solution, I can imagine a way to do it, but might restructure most of the current code. Still, implementing the solution can't ensure that it'll work, unless the flood wait can be reproduced. Only sending forwarding messages normally can be tested easily.

Sending is creating new messages, forwarding is just sharing a reference to the already received message without changing anything just like the forward function in Telegram app. Of course, the plugin should work in both modes.

poliandro commented 11 months ago

OK, sending is copy message without forward tag. Thank you for the explanation.

aahnik commented 7 months ago

thank you @MobCode100 for this awesome plugin... After going through your code, I understood how cleanly its implemented within the current structure of tgcf... Its a cool and awesome feature to have.

MobCode100 commented 7 months ago

thank you @MobCode100 for this awesome plugin... After going through your code, I understood how cleanly its implemented within the current structure of tgcf... Its a cool and awesome feature to have.

Thank you for your constructive comments, and your efforts for maintaining this project. Welcome back we missed you! Thank you so much for merging my pull requests.

mtsbh commented 6 months ago

@MobCode100 Is this plugin working? Because your tgcf fork seems to be unavailable.

MobCode100 commented 6 months ago

@MobCode100 Is this plugin working? Because your tgcf fork seems to be unavailable.

It's already merged to the main branch that's why I remove my fork. It should work, the last time I tried it.

djfaizp commented 1 week ago

bro when forwarding files using this plug-in it download file and then send it mode:bot past mode

MobCode100 commented 1 week ago

bro when forwarding files using this plug-in it download file and then send it mode:bot past mode

That's how it is. That's intentional.

djfaizp commented 1 week ago

can i bypass downloading

bro when forwarding files using this plug-in it download file and then send it mode:bot past mode

That's how it is. That's intentional.

MobCode100 commented 1 week ago

can i bypass downloading

I don't think so, because to send as another account requires downloading. Unless you made your own plugin or you modify existing.

djfaizp commented 6 days ago

can i bypass downloading

I don't think so, because to send as another account requires downloading. Unless you made your own plugin or you modify existing.

how can i modify i have code is it can be used `class TgcfSender(TgcfPlugin): id_ = "sender"

async def __ainit__(self) -> None:
    # ... (previous initialization code) ...
    self.download_files = self.data.get('download_files', False)

async def modify(self, tm: TgcfMessage) -> TgcfMessage:
    tm.client = self.sender
    if self.download_files and tm.file_type != "nofile":
        tm.new_file = await tm.get_file()
        tm.cleanup = True
    return tm`
MobCode100 commented 6 days ago

Fork the branch and make a pull request once done.