Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plugin] Sender #478

Merged
merged 1 commit into from
Dec 6, 2023
Merged

[Plugin] Sender #478

merged 1 commit into from
Dec 6, 2023

Conversation

MobCode100
Copy link
Contributor

@MobCode100 MobCode100 commented Jul 26, 2023

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:

  • Added TgcfSender plugin class.
  • Added attribute client inside TgcfMessage class to use as the sender in send_message function.
  • A list ASYNC_PLUGIN_IDS in plugin_models.py containing IDs of plugins that need to load asynchronously (e.g. login a client).
  • load_async_plugins function to load asynchronous plugins.

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

  • I agree to distribute my code contributions under MIT License, and will not change it in the future.
  • I agree that any contribution once merged, cannot be taken back by me.
  • I will abide by the Code of Conduct
  • I understand that the decision of the maintainer is final and abiding. And the maintainer reserves all rights to modify my code. I also understand that the maintainer can remove my code in future, if he thinks so.
  • Once my contribution is merged, my name will permanently appear in the Contribtor's List of this repository.

@MobCode100 MobCode100 requested a review from aahnik as a code owner July 26, 2023 13:50
@aahnik
Copy link
Owner

aahnik commented Jul 28, 2023

This is amazing work 👏🔥🎊

Thanks for your efforts in improving tgcf 😎

@MobCode100
Copy link
Contributor Author

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

@MobCode100
Copy link
Contributor Author

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
Copy link

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

@MobCode100
Copy link
Contributor Author

MobCode100 commented Jul 30, 2023

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
Copy link

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
Copy link
Contributor Author

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
Copy link

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
Copy link
Contributor Author

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
Copy link

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
Copy link
Contributor Author

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
Copy link

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

@aahnik aahnik merged commit c7a108c into aahnik:main Dec 6, 2023
@aahnik
Copy link
Owner

aahnik commented Dec 6, 2023

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
Copy link
Contributor Author

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
Copy link

mtsbh commented Jan 11, 2024

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

@MobCode100
Copy link
Contributor Author

@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
Copy link

djfaizp commented Jul 2, 2024

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

@MobCode100
Copy link
Contributor Author

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
Copy link

djfaizp commented Jul 2, 2024

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
Copy link
Contributor Author

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
Copy link

djfaizp commented Jul 4, 2024

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
Copy link
Contributor Author

Fork the branch and make a pull request once done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants