Comments (14)
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.
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.
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.
all working good but one last problem image send as file
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.
@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.
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.
Hi, anyone fixed that ? i am stil getting "are not supported"
from telemirror.
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.
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.
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.
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), messageHi 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.
all working good but one last problem image send as file
thank you for your help
from telemirror.
it work like a charme <3 thank you bro
from telemirror.
i will try to make it easy with web interface with streamlit can you suggest anything ?
from telemirror.
Related Issues (20)
- [Help] To filter forwarded messages HOT 11
- Пропуски при копировании. HOT 2
- Фильтр сообщений с каналов HOT 1
- can it be used to forward all past messages videos of a channel to new group? HOT 1
- Error while deployment HOT 5
- Exception when message received HOT 4
- Not Forwarding Specific channel HOT 4
- Why the keyword replace isn't working? HOT 1
- where to find mirror.config.yml HOT 2
- how to forward previous messages HOT 3
- can you help me set it up ? HOT 4
- SkipWithKeywordsFilter HOT 1
- Replace links in messages HOT 3
- Is it possible to forward a message only if the message contains specific keywords? HOT 1
- Forward to topic HOT 5
- CHAT_MAPPING forward from Topic to another Topic (example: -100999999#2) HOT 1
- Heroku deployment issues: binding $PORT, pass filters configuration thru environment HOT 10
- Ignore HOT 1
- Not forwarding messages from deafult topic HOT 24
- Delay for forwards HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telemirror.