Comments (6)
Hi, @bratcorpse
Can you provide logs and restricted filter
code?
from telemirror.
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.
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 typesfrom ..hints import EventMessage, EventLike
from .base import MessageFilterclass RestrictSavingContentBypassFilter(MessageFilter):
def init(self, send_restricted_content=True):
self.send_restricted_content = send_restricted_contentasync 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.
Thank you, photos are working not but it's not sending videos
from telemirror.
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.
Thank you for the help, really appreciate it <3!!
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
- Бан аккаунта про login.py HOT 4
- stops forwarding from the news channel HOT 1
- 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 26
- 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.