telegraph added
Browse filesAdd files via upload
- Mikobot/plugins/telegraph.py +73 -0
Mikobot/plugins/telegraph.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# <============================================== IMPORTS =========================================================>
|
2 |
+
import os
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
from PIL import Image
|
6 |
+
from pyrogram import filters
|
7 |
+
from telegraph import Telegraph, exceptions, upload_file
|
8 |
+
|
9 |
+
from Mikobot import app
|
10 |
+
from Mikobot.utils.errors import capture_err
|
11 |
+
|
12 |
+
# <=======================================================================================================>
|
13 |
+
|
14 |
+
TMP_DOWNLOAD_DIRECTORY = "tg-File/"
|
15 |
+
bname = "YaeMiko_Roxbot" # ᴅᴏɴ'ᴛ ᴇᴅɪᴛ ᴛʜɪᴀ ʟɪɴᴇ
|
16 |
+
telegraph = Telegraph()
|
17 |
+
r = telegraph.create_account(short_name=bname)
|
18 |
+
auth_url = r["auth_url"]
|
19 |
+
|
20 |
+
|
21 |
+
# <================================================ FUNCTION =======================================================>
|
22 |
+
@app.on_message(filters.command(["tgm", "tmg", "telegraph"], prefixes="/"))
|
23 |
+
@capture_err
|
24 |
+
async def telegraph_upload(client, message):
|
25 |
+
if message.reply_to_message:
|
26 |
+
start = datetime.now()
|
27 |
+
r_message = message.reply_to_message
|
28 |
+
input_str = message.command[0]
|
29 |
+
if input_str in ["tgm", "tmg", "telegraph"]:
|
30 |
+
downloaded_file_name = await client.download_media(
|
31 |
+
r_message, file_name=TMP_DOWNLOAD_DIRECTORY
|
32 |
+
)
|
33 |
+
end = datetime.now()
|
34 |
+
ms = (end - start).seconds
|
35 |
+
h = await message.reply_text(f"Downloaded to file in {ms} seconds.")
|
36 |
+
if downloaded_file_name.endswith(".webp"):
|
37 |
+
resize_image(downloaded_file_name)
|
38 |
+
try:
|
39 |
+
start = datetime.now()
|
40 |
+
media_urls = upload_file(downloaded_file_name)
|
41 |
+
except exceptions.TelegraphException as exc:
|
42 |
+
await h.edit_text("Error: " + str(exc))
|
43 |
+
os.remove(downloaded_file_name)
|
44 |
+
else:
|
45 |
+
end = datetime.now()
|
46 |
+
ms_two = (end - start).seconds
|
47 |
+
os.remove(downloaded_file_name)
|
48 |
+
await h.edit_text(
|
49 |
+
f"""
|
50 |
+
➼ **Uploaded to [Telegraph](https://telegra.ph{media_urls[0]}) in {ms + ms_two} seconds.**\n
|
51 |
+
➼ **Copy Link :** `https://telegra.ph{media_urls[0]}`""",
|
52 |
+
disable_web_page_preview=False,
|
53 |
+
)
|
54 |
+
else:
|
55 |
+
await message.reply_text(
|
56 |
+
"Reply to a message to get a permanent telegra.ph link."
|
57 |
+
)
|
58 |
+
|
59 |
+
|
60 |
+
def resize_image(image):
|
61 |
+
im = Image.open(image)
|
62 |
+
im.save(image, "PNG")
|
63 |
+
|
64 |
+
|
65 |
+
# <=================================================== HELP ====================================================>
|
66 |
+
__help__ = """
|
67 |
+
➠ *TELEGRAPH*:
|
68 |
+
|
69 |
+
» /tgm, /tmg, /telegraph*:* `get telegram link of replied media`
|
70 |
+
"""
|
71 |
+
|
72 |
+
__mod_name__ = "TELEGRAPH"
|
73 |
+
# <================================================ END =======================================================>
|