Code Monkey home page Code Monkey logo

Comments (6)

khoben avatar khoben commented on September 16, 2024

Hi, @bratcorpse
Can you provide logs and restricted filter code?

from telemirror.

bratcorpse avatar bratcorpse commented on September 16, 2024

sorry for the late response, it's forwarding text but not attachments

INFO 2024-08-27 06:08:36,843 [mirroring.py:71]:telemirror: [New message]: https://t.me/c/2182848314/7
ERROR 2024-08-27 06:08:37,117 [mirroring.py:165]:telemirror: Error while sending message to chat#-1001596234020. ChatForwardsRestrictedError: You can't forward messages from a protected chat (caused by SendMediaRequest)
INFO 2024-08-27 06:08:48,786 [mirroring.py:71]:telemirror: [New message]: https://t.me/c/2182848314/8
INFO 2024-08-27 06:10:40,369 [mirroring.py:71]:telemirror: [New message]: https://t.me/c/2182848314/9
ERROR 2024-08-27 06:10:40,474 [mirroring.py:165]:telemirror: Error while sending message to chat#-1001596234020. ChatForwardsRestrictedError: You can't forward messages from a protected chat (caused by SendMediaRequest)

`from typing import Tuple, Type
from telethon import types

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

class RestrictSavingContentBypassFilter(MessageFilter):
def init(self, send_restricted_content=True):
self.send_restricted_content = send_restricted_content

async def _process_message(
    self, message: EventMessage, event_type: Type[EventLike]
) -> Tuple[bool, EventMessage]:
    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`

this is the restrictedfilter.py which i'm using

from telemirror.

khoben avatar khoben commented on September 16, 2024

sorry for the late response, it's forwarding text but not attachments

INFO 2024-08-27 06:08:36,843 [mirroring.py:71]:telemirror: [New message]: https://t.me/c/2182848314/7
ERROR 2024-08-27 06:08:37,117 [mirroring.py:165]:telemirror: Error while sending message to chat#-1001596234020. ChatForwardsRestrictedError: You can't forward messages from a protected chat (caused by SendMediaRequest)
INFO 2024-08-27 06:08:48,786 [mirroring.py:71]:telemirror: [New message]: https://t.me/c/2182848314/8
INFO 2024-08-27 06:10:40,369 [mirroring.py:71]:telemirror: [New message]: https://t.me/c/2182848314/9
ERROR 2024-08-27 06:10:40,474 [mirroring.py:165]:telemirror: Error while sending message to chat#-1001596234020. ChatForwardsRestrictedError: You can't forward messages from a protected chat (caused by SendMediaRequest)

`from typing import Tuple, Type
from telethon import types

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

class RestrictSavingContentBypassFilter(MessageFilter):
def init(self, send_restricted_content=True):
self.send_restricted_content = send_restricted_content

async def _process_message(
    self, message: EventMessage, event_type: Type[EventLike]
) -> Tuple[bool, EventMessage]:
    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`

this is the restrictedfilter.py which i'm using

Check that filter was added to mirror.config.yml. Here is sample working implementation for such filter - #68 (comment)

from telemirror.

bratcorpse avatar bratcorpse commented on September 16, 2024

Thank you, photos are working not but it's not sending videos

from telemirror.

khoben avatar khoben commented on September 16, 2024

Thank you, photos are working not but it's not sending videos

Yep, you can handle other types:

...
elif isinstance(message.media, types.MessageMediaDocument):
    client: TelegramClient = message.client
  
    downloaded_media: bytes = await client.download_media(
        message=message, file=bytes
    )
    cloned_media_file: types.TypeInputFile = await client.upload_file(
        downloaded_media
    )
  
    cloned_media = types.InputMediaUploadedDocument(
        file=cloned_media_file,
        mime_type=message.media.document.mime_type,
        attributes=message.media.document.attributes,
        spoiler=message.media.spoiler,
        ttl_seconds=message.media.ttl_seconds,
    )
  
    message.media = cloned_media
else:
...

I think it's also a good idea to check the maximum size for the file, RAM might not be enough for big files:

if message.file and message.file.size > self._max_file_size_bytes:
    # File too big
    return False, message

Or even re-upload from the filesystem.

from telemirror.

bratcorpse avatar bratcorpse commented on September 16, 2024

Thank you for the help, really appreciate it <3!!

from telemirror.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.