Giter Club home page Giter Club logo

Comments (14)

khoben avatar khoben commented on July 25, 2024 2

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 chat_mapping from https://github.com/khoben/telemirror/blob/master/telemirror/mirroring.py and the filter parameters from https://github.com/khoben/telemirror/tree/master/telemirror/messagefilters . Feel free to make a PR.

from telemirror.

Amiinnetdz avatar Amiinnetdz commented on July 25, 2024 1

message forwarded but image stil get this error ?!
ERROR 2024-05-25 15:16:12,865 [mirroring.py:54]:telemirror: name 'types' is not defined
Traceback (most recent call last):
File "/root/frd/telemirror/mirroring.py", line 52, in wrapper
return await fn(self, *args, **kw)
File "/root/frd/telemirror/mirroring.py", line 125, in new_message
proceed, filtered_message = await config.filters.process(
File "/root/frd/telemirror/messagefilters/base.py", line 29, in process
return await self._process_message(entity, event_type)
File "/root/frd/telemirror/messagefilters/restrictsavingfilter.py", line 49, in _process_message
if isinstance(message.media, types.MessageMediaPhoto):
NameError: name 'types' is not defined

from telemirror.

khoben avatar khoben commented on July 25, 2024 1

message forwarded but image stil get this error ?! ERROR 2024-05-25 15:16:12,865 [mirroring.py:54]:telemirror: name 'types' is not defined Traceback (most recent call last): File "/root/frd/telemirror/mirroring.py", line 52, in wrapper return await fn(self, *args, **kw) File "/root/frd/telemirror/mirroring.py", line 125, in new_message proceed, filtered_message = await config.filters.process( File "/root/frd/telemirror/messagefilters/base.py", line 29, in process return await self._process_message(entity, event_type) File "/root/frd/telemirror/messagefilters/restrictsavingfilter.py", line 49, in _process_message if isinstance(message.media, types.MessageMediaPhoto): NameError: name 'types' is not defined

Here is missing imports. See updated filter sample code #68 (comment)

from telemirror.

khoben avatar khoben commented on July 25, 2024 1

all working good but one last problem image send as file Capture d’écran 2024-05-25 172530 thank you for your help

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)

from telemirror.

khoben avatar khoben commented on July 25, 2024

@lucag74 in general, you need to download, upload and change the media object.
Pseudo-code:

# 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

from telemirror.

lucag74 avatar lucag74 commented on July 25, 2024

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 :)

from telemirror.

Amiinnetdz avatar Amiinnetdz commented on July 25, 2024

Hi, anyone fixed that ? i am stil getting "are not supported"

from telemirror.

khoben avatar khoben commented on July 25, 2024

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.
But you can implement it by yourself, check #98 (comment)

from telemirror.

khoben avatar khoben commented on July 25, 2024

Hi, anyone fixed that ? i am stil getting "are not supported"

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

from telemirror.

Amiinnetdz avatar Amiinnetdz commented on July 25, 2024

Hi, anyone fixed that ? i am stil getting "are not supported"

Saw your message with error, indentation is most likely the problem there. Here is a sample filter implementation:

from typing import Tuple, Type

from ..hints import EventMessage, EventLike
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)
            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 ?
WARNING 2024-05-25 14:43:50,223 [mirroring.py:117]:telemirror: Forwards from channel#-1001633397411 with restricted saving content enabled to channel#-1002063015567 are not supported.

my source containt Text and image

from telemirror.

khoben avatar khoben commented on July 25, 2024

Hi, anyone fixed that ? i am stil getting "are not supported"

Saw your message with error, indentation is most likely the problem there. Here is a sample filter implementation:

from typing import Tuple, Type

from ..hints import EventMessage, EventLike
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)
            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 ? WARNING 2024-05-25 14:43:50,223 [mirroring.py:117]:telemirror: Forwards from channel#-1001633397411 with restricted saving content enabled to channel#-1002063015567 are not supported.

my source containt Text and image

You should also add RestrictSavingContentBypassFilter to yaml filter config:

...
directions:
  - from: [-1001]
    to: [-1002]
    filters:
      - RestrictSavingContentBypassFilter

To make the filter importable, add to telemirror/messagefilters/__init__.py:

from .restrictsavingfilter import RestrictSavingContentBypassFilter  # noqa: F401

from telemirror.

Amiinnetdz avatar Amiinnetdz commented on July 25, 2024

all working good but one last problem image send as file
Capture d’écran 2024-05-25 172530
thank you for your help

from telemirror.

Amiinnetdz avatar Amiinnetdz commented on July 25, 2024

it work like a charme <3 thank you bro

from telemirror.

Amiinnetdz avatar Amiinnetdz commented on July 25, 2024

i will try to make it easy with web interface with streamlit can you suggest anything ?

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.