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
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"""
post_client = TelegraphPoster(use_api=True)
auth_name = "MissKaty Bot"
post_client.create_api_token(auth_name)
post_page = post_client.post(
title=a_title,
author=auth_name,
author_url="https://www.yasir.my.id",
text=content,
response = await telegraph.create_page(
title,
html_content=content,
author_url="https://t.me/MissKatyPyro"
)
return post_page["url"]
return response['url']
async def run_subprocess(cmd):

View file

@ -113,17 +113,13 @@ async def dkick(client, message):
await sleep(1)
await message.chat.unban_member(member.user.id)
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 app.leave_chat(message.chat.id)
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>.")
break
except FloodWait as e:
await sleep(e.value)
if count == 0:
return await editPesan(sent_message, "There are no deleted accounts in this chat.")
try:
await sent_message.edit(f"✔️ **Berhasil menendang {count} akun terhapus.**")
except ChatWriteForbidden:
await app.leave_chat(message.chat.id)
await editPesan(sent_message, f"✔️ **Berhasil menendang {count} akun terhapus.**")
else:
sent_message = await message.reply_text("❗ **Kamu harus jadi admin atau owner grup untuk melakukan tindakan ini.**")
await sleep(5)

View file

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

View file

@ -47,7 +47,7 @@ async def mediainfo(client, message):
"""
title = "MissKaty Bot Mediainfo"
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)]])
await kirimPesan(message, " <b>MEDIA INFO</b>", reply_markup=markup, quote=True)
await process.delete()
@ -67,7 +67,7 @@ async def mediainfo(client, message):
body_text = f"""
<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/"
# response = await http.post(siteurl, data={"content": output, "extension": 'txt'} )
# response = response.json()

View file

@ -13,8 +13,7 @@ from pyrogram import filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from misskaty import app
from misskaty.helper.http import http
from misskaty.helper.tools import rentry
from misskaty.helper import http, rentry, post_to_telegraph
from misskaty.vars import COMMAND_HANDLER
__MODULE__ = "Paste"
@ -22,6 +21,7 @@ __HELP__ = """
/paste [Text/Reply To Message] - Post text to My Pastebin.
/sbin [Text/Reply To Message] - Post text to Spacebin.
/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.
/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 = 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
@app.on_message(filters.command(["paste"], COMMAND_HANDLER))
async def wastepaste(_, message):