forked from breakdowns/slam-mirrorbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Auto set bot command - Added mediainfo command Co-authored-by: brutewooorse <[email protected]> Co-authored-by: code-rgb <[email protected]>
- Loading branch information
1 parent
7dd2997
commit 8b39987
Showing
7 changed files
with
127 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import asyncio | ||
import os | ||
import shlex | ||
from typing import Tuple | ||
from html_telegraph_poster import TelegraphPoster | ||
|
||
def post_to_telegraph(a_title: str, content: str) -> str: | ||
""" Create a Telegram Post using HTML Content """ | ||
post_client = TelegraphPoster(use_api=True) | ||
auth_name = "slam-mirrorbot" | ||
post_client.create_api_token(auth_name) | ||
post_page = post_client.post( | ||
title=a_title, | ||
author=auth_name, | ||
author_url="https://github.com/breakdowns/slam-mirrorbot", | ||
text=content, | ||
) | ||
return post_page["url"] | ||
|
||
|
||
async def runcmd(cmd: str) -> Tuple[str, str, int, int]: | ||
""" run command in terminal """ | ||
args = shlex.split(cmd) | ||
process = await asyncio.create_subprocess_exec( | ||
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE | ||
) | ||
stdout, stderr = await process.communicate() | ||
return ( | ||
stdout.decode("utf-8", "replace").strip(), | ||
stderr.decode("utf-8", "replace").strip(), | ||
process.returncode, | ||
process.pid, | ||
) | ||
|
||
|
||
# Solves ValueError: No closing quotation by removing ' or " in file name | ||
def safe_filename(path_): | ||
if path_ is None: | ||
return | ||
safename = path_.replace("'", "").replace('"', "") | ||
if safename != path_: | ||
os.rename(path_, safename) | ||
return safename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Suggested by - @d0n0t (https://github.com/code-rgb/USERGE-X/issues/9) | ||
# Copyright (C) 2020 BY - GitHub.com/code-rgb [TG - @deleteduser420] | ||
# All rights reserved. | ||
|
||
import os | ||
from pyrogram import filters | ||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup | ||
from bot import app | ||
from bot.helper import post_to_telegraph, runcmd, safe_filename | ||
|
||
@app.on_message(filters.command(['mediainfo'])) | ||
async def mediainfo(client, message): | ||
reply = message.reply_to_message | ||
if not reply: | ||
await message.reply_text("Reply to Media first") | ||
return | ||
process = await message.reply_text("`Processing...`") | ||
x_media = None | ||
available_media = ( | ||
"audio", | ||
"document", | ||
"photo", | ||
"sticker", | ||
"animation", | ||
"video", | ||
"voice", | ||
"video_note", | ||
"new_chat_photo", | ||
) | ||
for kind in available_media: | ||
x_media = getattr(reply, kind, None) | ||
if x_media is not None: | ||
break | ||
if x_media is None: | ||
await process.edit_text("Reply To a Valid Media Format") | ||
return | ||
media_type = str(type(x_media)).split("'")[1] | ||
file_path = safe_filename(await reply.download()) | ||
output_ = await runcmd(f'mediainfo "{file_path}"') | ||
out = None | ||
if len(output_) != 0: | ||
out = output_[0] | ||
body_text = f""" | ||
<h2>JSON</h2> | ||
<pre>{x_media}</pre> | ||
<br> | ||
<h2>DETAILS</h2> | ||
<pre>{out or 'Not Supported'}</pre> | ||
""" | ||
text_ = media_type.split(".")[-1].upper() | ||
link = post_to_telegraph(media_type, body_text) | ||
markup = InlineKeyboardMarkup([[InlineKeyboardButton(text=text_, url=link)]]) | ||
await process.edit_text("ℹ️ <b>MEDIA INFO</b>", reply_markup=markup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ js2py | |
lxml | ||
telegraph | ||
pytz | ||
html-telegraph-poster>=0.2.31 |