-
Notifications
You must be signed in to change notification settings - Fork 105
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
[HELP] Skip restricted content #68
Comments
@lucag74 in general, you need to download, upload and change the media object. # 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 |
Fantastic i will try. Your project it's fantastic and i'm using it and the same time i will level up my python and telegram skill :) |
Hi, anyone fixed that ? i am stil getting "are not supported" |
Copying from protected channels isn't implemented because this violates the terms of the user agreement. |
Saw your message with error, indentation is most likely the problem there. Here is a sample filter implementation: 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 |
Hi added this but stil getting this message ? my source containt Text and image |
You should also add ...
directions:
- from: [-1001]
to: [-1002]
filters:
- RestrictSavingContentBypassFilter To make the filter importable, add to from .restrictsavingfilter import RestrictSavingContentBypassFilter # noqa: F401 |
message forwarded but image stil get this error ?! |
Here is missing imports. See updated filter sample code #68 (comment) |
I suppose setting a filename might help: cloned_photo.name = (
message.file.name if message.file.name else "photo.jpg"
) Also I've updated the example #68 (comment) |
it work like a charme <3 thank you bro |
i will try to make it easy with web interface with streamlit can you suggest anything ? |
I think it's a good idea to make a UI, someone might find it useful. You need to somehow save and modify the |
HI,
thank's for your work,
I enable the forward of restrict channel.
i uncommented this
Skip 'restricted saving content' enabled
on event on_new_message
there is a way for this channel mirror only the text , maybe the image (saving to array) ?
(i see one old post)
I can skip all the other element , audio, album etc.. ?
In few word i'm try to avoid the ban, and i'm interested on only text part and maybe images of every message.
Thank's
The text was updated successfully, but these errors were encountered: