add tgraph

This commit is contained in:
yasir 2023-02-09 13:46:03 +07:00
parent 4d2432e344
commit 56865be66b
5 changed files with 76 additions and 23 deletions

View file

@ -3,21 +3,24 @@ import os
import shlex import shlex
from typing import Tuple from typing import Tuple
from html_telegraph_poster import TelegraphPoster from telegraph.aio import Telegraph
from utils import LOGGER
def post_to_telegraph(a_title: str, content: str) -> str: async def post_to_telegraph(is_media: bool, title: str, content: str, media=None):
telegraph = Telegraph()
LOGGER.info(await telegraph.create_account(short_name='MissKaty'))
if is_media:
"""Create a Telegram Post Foto/Video"""
response = await telegraph.upload_file(media)
return f"https://telegra.ph{response[0]['src']}"
"""Create a Telegram Post using HTML Content""" """Create a Telegram Post using HTML Content"""
post_client = TelegraphPoster(use_api=True) response = await telegraph.create_page(
auth_name = "MissKaty Bot" title,
post_client.create_api_token(auth_name) html_content=content,
post_page = post_client.post( author_url="https://t.me/MissKatyPyro"
title=a_title,
author=auth_name,
author_url="https://www.yasir.my.id",
text=content,
) )
return post_page["url"] return response['url']
async def run_subprocess(cmd): async def run_subprocess(cmd):

View file

@ -113,17 +113,13 @@ async def dkick(client, message):
await sleep(1) await sleep(1)
await message.chat.unban_member(member.user.id) await message.chat.unban_member(member.user.id)
except (ChatAdminRequired, UserAdminInvalid): except (ChatAdminRequired, UserAdminInvalid):
await sent_message.edit("❗**Oh tidaakk, saya bukan admin disini**\n__Saya pergi dari sini, tambahkan aku kembali dengan perijinan banned pengguna.__") await sent_message.edit("❗**Oh Nooo, i'm doesn't have admin permission in this group. Make sure i'm have admin permission to <b>ban users</b>.")
await app.leave_chat(message.chat.id)
break break
except FloodWait as e: except FloodWait as e:
await sleep(e.value) await sleep(e.value)
if count == 0: if count == 0:
return await editPesan(sent_message, "There are no deleted accounts in this chat.") return await editPesan(sent_message, "There are no deleted accounts in this chat.")
try: await editPesan(sent_message, f"✔️ **Berhasil menendang {count} akun terhapus.**")
await sent_message.edit(f"✔️ **Berhasil menendang {count} akun terhapus.**")
except ChatWriteForbidden:
await app.leave_chat(message.chat.id)
else: else:
sent_message = await message.reply_text("❗ **Kamu harus jadi admin atau owner grup untuk melakukan tindakan ini.**") sent_message = await message.reply_text("❗ **Kamu harus jadi admin atau owner grup untuk melakukan tindakan ini.**")
await sleep(5) await sleep(5)

View file

@ -125,7 +125,7 @@ async def inline_menu(_, inline_query: InlineQuery):
body_text = f""" body_text = f"""
<pre>{msg}</pre> <pre>{msg}</pre>
""" """
msg = post_to_telegraph(method, body_text) msg = await post_to_telegraph(False, method, body_text)
datajson.append( datajson.append(
InlineQueryResultArticle( InlineQueryResultArticle(
title=method, title=method,
@ -162,7 +162,7 @@ async def inline_menu(_, inline_query: InlineQuery):
body_text = f""" body_text = f"""
<pre>{msg}</pre> <pre>{msg}</pre>
""" """
msg = post_to_telegraph(method, body_text) msg = await post_to_telegraph(False, method, body_text)
datajson.append( datajson.append(
InlineQueryResultArticle( InlineQueryResultArticle(
title=types, title=types,

View file

@ -47,7 +47,7 @@ async def mediainfo(client, message):
""" """
title = "MissKaty Bot Mediainfo" title = "MissKaty Bot Mediainfo"
text_ = file_info.message_type text_ = file_info.message_type
link = post_to_telegraph(title, body_text) link = await post_to_telegraph(False, title, body_text)
markup = InlineKeyboardMarkup([[InlineKeyboardButton(text=text_, url=link)]]) markup = InlineKeyboardMarkup([[InlineKeyboardButton(text=text_, url=link)]])
await kirimPesan(message, " <b>MEDIA INFO</b>", reply_markup=markup, quote=True) await kirimPesan(message, " <b>MEDIA INFO</b>", reply_markup=markup, quote=True)
await process.delete() await process.delete()
@ -67,7 +67,7 @@ async def mediainfo(client, message):
body_text = f""" body_text = f"""
<pre>{output}</pre> <pre>{output}</pre>
""" """
link = post_to_telegraph(title, body_text) link = await post_to_telegraph(False, title, body_text)
# siteurl = "https://spaceb.in/api/v1/documents/" # siteurl = "https://spaceb.in/api/v1/documents/"
# response = await http.post(siteurl, data={"content": output, "extension": 'txt'} ) # response = await http.post(siteurl, data={"content": output, "extension": 'txt'} )
# response = response.json() # response = response.json()

View file

@ -13,8 +13,7 @@ from pyrogram import filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from misskaty import app from misskaty import app
from misskaty.helper.http import http from misskaty.helper import http, rentry, post_to_telegraph
from misskaty.helper.tools import rentry
from misskaty.vars import COMMAND_HANDLER from misskaty.vars import COMMAND_HANDLER
__MODULE__ = "Paste" __MODULE__ = "Paste"
@ -22,6 +21,7 @@ __HELP__ = """
/paste [Text/Reply To Message] - Post text to My Pastebin. /paste [Text/Reply To Message] - Post text to My Pastebin.
/sbin [Text/Reply To Message] - Post text to Spacebin. /sbin [Text/Reply To Message] - Post text to Spacebin.
/neko [Text/Reply To Message] - Post text to Nekobin. /neko [Text/Reply To Message] - Post text to Nekobin.
/tgraph [Text/Reply To Message] - Post text to Telegra.ph.
/rentry [Text/Reply To Message] - Post text to Rentry using markdown style. /rentry [Text/Reply To Message] - Post text to Rentry using markdown style.
/temp_paste [Text/Reply To Message] - Post text to tempaste.com using html style. /temp_paste [Text/Reply To Message] - Post text to tempaste.com using html style.
""" """
@ -63,6 +63,60 @@ def humanbytes(size: int):
# Pattern if extension supported, PR if want to add more # Pattern if extension supported, PR if want to add more
pattern = compiles(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$|x-subrip$") pattern = compiles(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$|x-subrip$")
@app.on_message(filters.command(["tgraph"], COMMAND_HANDLER))
async def telegraph_paste(_, message):
reply = message.reply_to_message
if not reply and len(message.command) < 2:
return await message.reply_text(f"**Reply To A Message With /{message.command[0]} or with command**")
msg = await message.reply_text("`Pasting to Telegraph...`")
data = ""
limit = 1024 * 1024
if reply and reply.document:
if reply.document.file_size > limit:
return await msg.edit(f"**You can only paste files smaller than {humanbytes(limit)}.**")
if not pattern.search(reply.document.mime_type):
return await msg.edit("**Only text files can be pasted.**")
file = await reply.download()
try:
with open(file, "r") as text:
data = text.read()
remove(file)
except UnicodeDecodeError:
try:
remove(file)
except:
pass
return await msg.edit("`File Not Supported !`")
elif reply and (reply.text or reply.caption):
data = reply.text.html or reply.caption.html
elif not reply and len(message.command) >= 2:
data = message.text.split(None, 1)[1]
if message.from_user:
if message.from_user.username:
uname = f"@{message.from_user.username} [{message.from_user.id}]"
else:
uname = f"[{message.from_user.first_name}](tg://user?id={message.from_user.id}) [{message.from_user.id}]"
else:
uname = message.sender_chat.title
try:
url = await post_to_telegraph(False, f"MissKaty Paste", data)
except Exception as e:
await msg.edit(f"ERROR: {e}")
return
if not url:
return await msg.edit("Text Too Short Or File Problems")
button = [
[InlineKeyboardButton("Open Link", url=url)],
[InlineKeyboardButton("Share Link", url=f"https://telegram.me/share/url?url={url}")],
]
pasted = f"**Successfully pasted your data to Telegraph<a href='{url}'>.</a>\n\nPaste by {uname}**"
await msg.edit(pasted, reply_markup=InlineKeyboardMarkup(button))
# Default Paste to Wastebin using Deta # Default Paste to Wastebin using Deta
@app.on_message(filters.command(["paste"], COMMAND_HANDLER)) @app.on_message(filters.command(["paste"], COMMAND_HANDLER))
async def wastepaste(_, message): async def wastepaste(_, message):