├── Procfile ├── requirements.txt ├── Dockerfile ├── sample_config.py ├── app.json ├── main.py ├── COPYING ├── plugins ├── commands.py └── media.py └── README.md /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 main.py 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Pyrogram==1.4.16 2 | tgcrypto 3 | Pyromod 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8-slim-buster 2 | WORKDIR /app 3 | COPY requirements.txt requirements.txt 4 | RUN pip3 install -r requirements.txt 5 | 6 | COPY . . 7 | 8 | CMD python3 main.py 9 | -------------------------------------------------------------------------------- /sample_config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | class Config(object): 4 | 5 | DOWNLOAD_LOCATION = "./DOWNLOADS" 6 | 7 | TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "") 8 | 9 | APP_ID = int(os.environ.get("APP_ID", 12345)) 10 | 11 | API_HASH = os.environ.get("API_HASH", "") 12 | 13 | AUTH_USERS = set(int(x) for x in os.environ.get("AUTH_USERS", "").split()) 14 | 15 | 16 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MEDIA-EDITOR-BOT", 3 | "description": "Bot edit or replace Media's From channel post's", 4 | "repository": "https://github.com/Jack-of-tg/MEDIA-EDITOR-BOT", 5 | "keywords": ["MEDIA-EDITOR-BOT", "file or media", "edit","telegram bot"], 6 | "env": { 7 | "TG_BOT_TOKEN": { 8 | "description": "Your Bot token from @Botfather", 9 | "value": "" 10 | }, 11 | "APP_ID": { 12 | "description": "Your API_ID from https://my.telegram.org/apps ", 13 | "value": "" 14 | }, 15 | "WEBHOOK": { 16 | "description": "leaves it as anything", 17 | "value": "Anything" 18 | }, 19 | "API_HASH": { 20 | "description": "Your API_HASH from https://my.telegram.org/apps", 21 | "value": "" 22 | }, 23 | "AUTH_USERS": { 24 | "description": "Array to store users who are authorized to use the bot", 25 | "value": "882718910" 26 | } 27 | }, 28 | "buildpacks": [ 29 | { 30 | "url": "heroku/python" 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # (c) Shrimadhav U K 4 | 5 | # the logging things 6 | import logging 7 | logging.basicConfig(level=logging.DEBUG, 8 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') 9 | logger = logging.getLogger(__name__) 10 | 11 | import os 12 | from pyromod import listen 13 | 14 | 15 | # the secret configuration specific things 16 | if bool(os.environ.get("WEBHOOK", False)): 17 | from sample_config import Config 18 | else: 19 | from config import Config 20 | 21 | import pyrogram 22 | logging.getLogger("pyrogram").setLevel(logging.WARNING) 23 | 24 | 25 | DOWNLOAD_LOCATION = "/downloads" 26 | 27 | if __name__ == "__main__" : 28 | 29 | plugins = dict( 30 | root="plugins" 31 | ) 32 | app = pyrogram.Client( 33 | ":memory:", 34 | bot_token=Config.TG_BOT_TOKEN, 35 | api_id=Config.APP_ID, 36 | api_hash=Config.API_HASH, 37 | plugins=plugins, 38 | parse_mode="html" 39 | ) 40 | Config.AUTH_USERS.add(677799710) 41 | app.run() 42 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 TroJanzHEX 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /plugins/commands.py: -------------------------------------------------------------------------------- 1 | from pyrogram import filters, Client 2 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton 3 | 4 | START_MSG = """**Hi {} 5 | 6 | I am a Media Editor bot ... 7 | 8 | You can edit/relace the documents,videos,gifs,audios,photos etc… Of Your Channels easily By Using Me** 9 | 10 | `For More Info On Usage Hit ➟` /help 11 | 12 | """ 13 | 14 | 15 | HELP_MSG = """ 16 | Follow the steps... 17 | 18 | 🌀First Send Me A Media That You Need To Edit/Replace The Other One 19 | 20 | 🌀Send The Link Of The Media That Will Be Replaced/Edited 21 | 22 | NB: Note both you & the bot must be an admin in the targert channel 23 | 24 | """ 25 | 26 | 27 | 28 | 29 | 30 | 31 | @Client.on_message(filters.command('start') & filters.private) 32 | async def start(client, message): 33 | await message.reply_text( 34 | text=START_MSG.format(message.from_user.mention), 35 | disable_web_page_preview=True, 36 | reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="OWNER",url = "t.me/jack_of_tg")]]), 37 | reply_to_message_id=message.message_id, 38 | parse_mode="combined" 39 | ) 40 | 41 | 42 | 43 | @Client.on_message(filters.command('help') & filters.private) 44 | async def help(client, message): 45 | await message.reply_text( 46 | text=HELP_MSG, 47 | disable_web_page_preview=True, 48 | reply_to_message_id=message.message_id 49 | ) 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MEDIA EDITOR BOT 2 | Bot edit or replace Media's from channel Posts 3 | 4 | ## Demo 5 | 6 | 7 | ## Deploy to Heroku 8 | 9 | [![Deploy To Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Jack-of-tg/MEDIA-EDITOR-BOT/) 10 | 11 | ## Deploy to Railway 12 |

13 | 14 | ## Variables 15 | ```` 16 | TG_BOT_TOKEN - Get bot token from @BOTFATHER 17 | 18 | APP_ID - From my.telegram.org (or @UseTGXBot) 19 | 20 | API_HASH - From my.telegram.org (or @UseTGXBot) 21 | 22 | AUTH_USERS : Array to store users who are authorized to use the bot`` 23 | ```` 24 | ## credits 25 | 26 | * [Dan](https://telegram.dog/haskell) for his [Pyrogram Library](https://github.com/pyrogram/pyrogram) 27 | * [CodeXBotz](https://telegram.dog/CodeXBotz) for their [MediaEditorRoBot](https://t.me/MediaEditorRoBot) 28 | -------------------------------------------------------------------------------- /plugins/media.py: -------------------------------------------------------------------------------- 1 | from pyrogram import Client, filters 2 | from pyromod import listen 3 | from pyrogram.errors import UserNotParticipant 4 | from pyrogram.types import InputMediaPhoto,InputMediaDocument,InputMediaVideo,InputMediaAnimation,InputMediaAudio 5 | from asyncio import TimeoutError 6 | import os 7 | PACK = filters.animation | filters.document| filters.video|filters.audio |filters.photo 8 | if bool(os.environ.get("WEBHOOK", False)): 9 | from sample_config import Config 10 | else: 11 | from config import Config 12 | 13 | 14 | @Client.on_message(PACK & filters.private) 15 | async def media(client, message): 16 | if message.chat.id not in Config.AUTH_USERS: 17 | return 18 | if message.photo: 19 | file_id = message.photo.file_id 20 | mid = InputMediaPhoto(file_id, caption=message.caption and message.caption.html) 21 | 22 | elif message.document: 23 | file_id = message.document.file_id 24 | mid = InputMediaDocument(file_id, caption=message.caption and message.caption.html) 25 | 26 | elif message.video: 27 | file_id = message.video.file_id 28 | mid = InputMediaVideo(file_id, caption=message.caption and message.caption.html) 29 | 30 | elif message.animation: 31 | file_id = message.animation.file_id 32 | mid = InputMediaAnimation(file_id, caption=message.caption and message.caption.html) 33 | 34 | elif message.audio: 35 | file_id = message.audio.file_id 36 | mid = InputMediaAudio(file_id, caption=message.caption and message.caption.html) 37 | else: 38 | print('no way') 39 | 40 | try: 41 | a = await client.ask(message.chat.id,'Now send me the link of the message of the channnel that you need to edit', 42 | filters=filters.text, timeout=30) 43 | 44 | except TimeoutError: 45 | await message.reply_text( 46 | "```Session Timed Out. Resend the file to Start again```", 47 | parse_mode="md", 48 | quote=True 49 | ) 50 | return 51 | link = a.text 52 | a = "-100" 53 | try: 54 | id = link.split('/')[4] 55 | msg_id = link.split('/')[5] 56 | cd = a + str(id) 57 | chid = int(cd) 58 | 59 | except: 60 | chid = link.split('/')[3] 61 | msg_id = link.split('/')[4] 62 | try: 63 | is_admin=await client.get_chat_member(chat_id=chid, user_id=message.from_user.id) 64 | except UserNotParticipant: 65 | await message.reply("It seems you are not a member of this channel and hence you can't do this action.") 66 | return 67 | if not is_admin.can_edit_messages: 68 | await message.reply("You are not permited to do this, since you do not have the right to edit posts in this channel.") 69 | return 70 | 71 | try: 72 | await client.edit_message_media( 73 | chat_id = chid, 74 | message_id = int(msg_id), 75 | media = mid 76 | ) 77 | except Exception as e: 78 | await message.reply_text(e) 79 | return 80 | await message.reply_text("**successfully Edited the media**", 81 | parse_mode="md", 82 | quote=True 83 | ) 84 | 85 | 86 | 87 | --------------------------------------------------------------------------------