Update plugins/ExtraMods/carbon.py
Browse files- plugins/ExtraMods/carbon.py +26 -15
plugins/ExtraMods/carbon.py
CHANGED
|
@@ -12,26 +12,37 @@ async def make_carbon(code, tele=False):
|
|
| 12 |
image = BytesIO(await resp.read())
|
| 13 |
image.name = "carbon.png"
|
| 14 |
if tele:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
return image
|
| 19 |
|
| 20 |
|
| 21 |
@Client.on_message(filters.command("carbon"))
|
| 22 |
async def carbon_func(b, message):
|
| 23 |
if not message.reply_to_message:
|
| 24 |
-
return await message.reply_text("ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴛᴇxᴛ
|
| 25 |
if not message.reply_to_message.text:
|
| 26 |
-
return await message.reply_text("ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴛᴇxᴛ
|
| 27 |
user_id = message.from_user.id
|
| 28 |
-
m = await message.reply_text("
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
image = BytesIO(await resp.read())
|
| 13 |
image.name = "carbon.png"
|
| 14 |
if tele:
|
| 15 |
+
try:
|
| 16 |
+
uf = upload_file(image)
|
| 17 |
+
image.close()
|
| 18 |
+
return f"https://graph.org{uf[0]}"
|
| 19 |
+
except Exception as e:
|
| 20 |
+
logger.error(f"Error uploading carbon image to Telegraph: {e}")
|
| 21 |
+
return None
|
| 22 |
return image
|
| 23 |
|
| 24 |
|
| 25 |
@Client.on_message(filters.command("carbon"))
|
| 26 |
async def carbon_func(b, message):
|
| 27 |
if not message.reply_to_message:
|
| 28 |
+
return await message.reply_text("ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴛᴇxᴛ ᴍᴇꜱꜱᴀɢᴇ ᴛᴏ ᴍᴀᴋᴇ ᴄᴀʀʙᴏɴ.")
|
| 29 |
if not message.reply_to_message.text:
|
| 30 |
+
return await message.reply_text("ʀᴇᴘʟʏ ᴛᴏ ᴀ ᴛᴇxᴛ ᴍᴇꜱꜱᴀɢᴇ ᴛᴏ ᴍᴀᴋᴇ ᴄᴀʀʙᴏɴ.")
|
| 31 |
user_id = message.from_user.id
|
| 32 |
+
m = await message.reply_text("ᴘʀᴏᴄᴇꜱꜱɪɴɢ...")
|
| 33 |
+
try:
|
| 34 |
+
carbon = await make_carbon(message.reply_to_message.text)
|
| 35 |
+
if not carbon:
|
| 36 |
+
logger.error(f"Failed to generate carbon image for user {user_id}")
|
| 37 |
+
return await m.edit_text("Failed to generate carbon image. Please try again later.")
|
| 38 |
+
await m.edit_text("ᴜᴘʟᴏᴀᴅɪɴɢ..")
|
| 39 |
+
await message.reply_photo(
|
| 40 |
+
photo=carbon,
|
| 41 |
+
caption="**ᴍᴀᴅᴇ ʙʏ: @mkn_bots_updates**",
|
| 42 |
+
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("ꜱᴜᴩᴩᴏʀᴛ ᴜꜱ", url="https://t.me/mkn_bots_updates")]]),
|
| 43 |
+
)
|
| 44 |
+
await m.delete()
|
| 45 |
+
carbon.close()
|
| 46 |
+
except Exception as e:
|
| 47 |
+
logger.error(f"Error in carbon command for user {user_id}: {e}")
|
| 48 |
+
await m.edit_text("An error occurred while generating the carbon image. Please try again later.")
|