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

Restricted Content Forward/Copy #146

Closed
Fnc-Rishu opened this issue Jan 8, 2025 · 8 comments
Closed

Restricted Content Forward/Copy #146

Fnc-Rishu opened this issue Jan 8, 2025 · 8 comments

Comments

@Fnc-Rishu
Copy link

image

@khoben
Copy link
Owner

khoben commented Jan 9, 2025

Be careful with forwards from channels with RESTRICTED SAVING CONTENT. It may lead to an account ban. But if you take risks, look at these comments:
#68 (comment)
#68 (comment)
#123 (comment)

@Fnc-Rishu
Copy link
Author

it worked thnx again

@Fnc-Rishu Fnc-Rishu reopened this Jan 16, 2025
@Fnc-Rishu
Copy link
Author

Fnc-Rishu commented Jan 16, 2025

facing same issue now; even after modifying restrictsavingfilter.py by the code #68 (comment)
modified the init.py also
Image

init.py
Image

Image

@khoben
Copy link
Owner

khoben commented Jan 16, 2025

Check that the filter is installed for the right channels. If you have any more questions, please show the full filter code and configuration file.

@Fnc-Rishu
Copy link
Author

Fnc-Rishu commented Jan 16, 2025

restrictsavingfilter.py

from typing import Tuple, Type

from telethon import TelegramClient, types

from ..hints import EventLike, EventMessage
from .base import MessageFilter

class RestrictSavingContentBypassFilter(MessageFilter):
"""Filter that bypasses saving content restriction

Sample implementation:

Download the media, upload it to the Telegram servers,
and then change to the new uploaded media

```
# If here is media and noforwards enabled
if message.chat.noforwards and message.media:
    # Handle images
    if isinstance(message.media, types.MessageMediaPhoto):
        client: TelegramClient = message.client
        photo: bytes = await client.download_media(message=message, file=bytes)
        cloned_photo: types.TypeInputFile = await client.upload_file(photo)
        message.media = cloned_photo
    # Others media types set to None (remove from original message)...
    else:
        message.media = None

return True, message
```
"""

@property
def restricted_content_allowed(self) -> bool:
    return True

async def _process_message(
    self, message: EventMessage, event_type: Type[EventLike]
) -> Tuple[bool, EventMessage]:
    
    if message.media is None or (
        message.chat is None or not message.chat.noforwards
    ):
        # Forwarding allowed
        return True, message
    
    client: TelegramClient = message.client
    
    # Handle images
    if isinstance(message.media, types.MessageMediaPhoto):
        photo: bytes = await client.download_media(message=message, file=bytes)
        cloned_photo: types.TypeInputFile = await client.upload_file(photo)
        cloned_photo.name = (
            message.file.name if message.file.name else "photo.jpg"
        )
        message.media = cloned_photo
    # Others media types set to None (remove from original message)...
    else:
        message.media = None

    # Process message if not empty
    return bool(message.media or message.message), message

init

from .base import CompositeMessageFilter # noqa: F401
from .messagefilters import * # noqa: F403
from .restrictsavingfilter import RestrictSavingContentBypassFilter # noqa: F401

@Fnc-Rishu
Copy link
Author

Image

@khoben
Copy link
Owner

khoben commented Jan 16, 2025

Everything looks fine, it should work. "Forwards not supported" warning only printed if "Restrict saving content" is enabled for source channel and no filter returns True on restricted_content_allowed property

@Fnc-Rishu
Copy link
Author

Fnc-Rishu commented Jan 18, 2025

So basically, I'm hosting this script on AWS
idk why but from last two days it doesn't refresh until and when I click on cmd screen it shows this error

Image

Image

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

No branches or pull requests

2 participants