mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2025-12-29 09:44:50 +00:00
Add ImgBB Upload
This commit is contained in:
parent
9bc375c8f6
commit
f47b9da904
1 changed files with 27 additions and 85 deletions
|
|
@ -21,9 +21,9 @@ __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/media to Telegraph.
|
/tgraph [Text/Reply To Message] - Post text to Telegraph.
|
||||||
|
/imgbb [Images] - Upload image to ImgBB.
|
||||||
/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. (Deprecated)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -82,29 +82,6 @@ async def telegraph_paste(_, message):
|
||||||
else:
|
else:
|
||||||
uname = message.sender_chat.title
|
uname = message.sender_chat.title
|
||||||
msg = await message.reply_msg("`Pasting to Telegraph...`")
|
msg = await message.reply_msg("`Pasting to Telegraph...`")
|
||||||
if reply and (reply.photo or reply.animation):
|
|
||||||
file = await reply.download()
|
|
||||||
try:
|
|
||||||
url = await post_to_telegraph(True, media=file)
|
|
||||||
except Exception as err:
|
|
||||||
remove(file)
|
|
||||||
return msg.edit_msg(f"Failed to upload. ERR: {err}")
|
|
||||||
button = [
|
|
||||||
[InlineKeyboardButton("Open Link", url=url)],
|
|
||||||
[
|
|
||||||
InlineKeyboardButton(
|
|
||||||
"Share Link", url=f"https://telegram.me/share/url?url={url}"
|
|
||||||
)
|
|
||||||
],
|
|
||||||
]
|
|
||||||
|
|
||||||
pasted = f"**Successfully upload your media to Telegraph<a href='{url}'>.</a>\n\nUpload by {uname}**"
|
|
||||||
remove(file)
|
|
||||||
return await msg.edit_msg(
|
|
||||||
pasted,
|
|
||||||
disable_web_page_preview=True,
|
|
||||||
reply_markup=InlineKeyboardMarkup(button),
|
|
||||||
)
|
|
||||||
data = ""
|
data = ""
|
||||||
limit = 1024 * 1024
|
limit = 1024 * 1024
|
||||||
if reply and reply.document:
|
if reply and reply.document:
|
||||||
|
|
@ -432,42 +409,17 @@ async def rentrypaste(_, message):
|
||||||
await msg.edit_msg(pasted, reply_markup=InlineKeyboardMarkup(button))
|
await msg.edit_msg(pasted, reply_markup=InlineKeyboardMarkup(button))
|
||||||
|
|
||||||
|
|
||||||
# Tempaste pastebin
|
# ImgBB Upload
|
||||||
@app.on_message(filters.command(["temp_paste"], COMMAND_HANDLER))
|
@app.on_message(filters.command(["imgbb"], COMMAND_HANDLER))
|
||||||
async def tempaste(_, message):
|
async def imgbb_upload(_, message):
|
||||||
reply = message.reply_to_message
|
reply = message.reply_to_message
|
||||||
target = str(message.command[0]).split("@", maxsplit=1)[0]
|
if not reply and len(message.command) == 1:
|
||||||
if not reply and len(message.command) < 2:
|
|
||||||
return await message.edit_msg(
|
return await message.edit_msg(
|
||||||
f"**Reply To A Message With /{target} or with command**", del_in=6
|
f"**Reply to a photo with /{message.command[0]} command to upload image on ImgBB.**", del_in=6
|
||||||
)
|
)
|
||||||
|
if not reply.photo or not reply.document.mime_type.startswith("image"):
|
||||||
msg = await message.reply_msg("`Pasting to TempPaste...`")
|
return await messsage.reply_msg("This command only support upload photo")
|
||||||
data = ""
|
msg = await message.reply_msg("`Uploading image to ImgBB...`")
|
||||||
limit = 1024 * 1024
|
|
||||||
if reply and reply.document:
|
|
||||||
if reply.document.file_size > limit:
|
|
||||||
return await msg.edit_msg(
|
|
||||||
f"**You can only paste files smaller than {humanbytes(limit)}.**"
|
|
||||||
)
|
|
||||||
if not pattern.search(reply.document.mime_type):
|
|
||||||
return await msg.edit_msg("**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_msg("`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:
|
||||||
if message.from_user.username:
|
if message.from_user.username:
|
||||||
uname = f"@{message.from_user.username}"
|
uname = f"@{message.from_user.username}"
|
||||||
|
|
@ -479,23 +431,11 @@ async def tempaste(_, message):
|
||||||
uname = message.sender_chat.title
|
uname = message.sender_chat.title
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = await fetch.post(
|
data = {"type": "file", "action": "upload"}
|
||||||
"https://tempaste.com/api/v1/create-paste/",
|
files = {"source": (path, open(path, "rb"), "images/jpeg")}
|
||||||
data={
|
headers = {"origin": "https://imgbb.com", "referer": "https://imgbb.com/upload", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42"}
|
||||||
"api_key": "xnwuzXubxk3kCUz9Q2pjMVR8xeTO4t",
|
res = await fetch.post("https://imgbb.com/json", files=files, data=data, headers=headers)
|
||||||
"title": "MissKaty Paste",
|
url = res.json()["image"]["url"]
|
||||||
"paste_content": data,
|
|
||||||
"visibility": "public",
|
|
||||||
"expiry_date_type": "months",
|
|
||||||
"expiry_date": 1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
url = f"https://tempaste.com/{json_loads(req.text)['url']}"
|
|
||||||
except Exception as e:
|
|
||||||
return await msg.edit_msg(f"`{e}`")
|
|
||||||
|
|
||||||
if not url:
|
|
||||||
return await msg.edit_msg("Text Too Short Or File Problems")
|
|
||||||
button = [
|
button = [
|
||||||
[InlineKeyboardButton("Open Link", url=url)],
|
[InlineKeyboardButton("Open Link", url=url)],
|
||||||
[
|
[
|
||||||
|
|
@ -505,5 +445,7 @@ async def tempaste(_, message):
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
||||||
pasted = f"**Successfully pasted your data to Tempaste<a href='{url}'>.</a>\n\nPaste by {uname}**"
|
pasted = f"**Successfully pasted your images to ImgBB<a href='{url}'>.</a>\n\nPaste by {uname}**"
|
||||||
await msg.edit_msg(pasted, reply_markup=InlineKeyboardMarkup(button))
|
await msg.edit_msg(pasted, reply_markup=InlineKeyboardMarkup(button))
|
||||||
|
except Exception as e:
|
||||||
|
await msg.edit_msg(f"ERROR: {e}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue