mirror of
https://github.com/MuRuLOSE/limoka.git
synced 2026-06-16 14:34:17 +02:00
130 lines
5.8 KiB
Python
130 lines
5.8 KiB
Python
# ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
|
||
# ⠿⠿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠟⠛⠛⠛⠛⠛
|
||
# ⣶⣦⣤⣤⣤⣤⣤⣤⣬⣭⣭⣍⣉⡙⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⣋⣩⣭⣥⣤⣴⣶⣶⣶⣶⣶⣶⣶⣶⣶
|
||
# ⣆⠀⠀⠀⢡⠁⠀⡀⠀⢸⠟⠻⣯⠙⠛⠷⣶⣬⡙⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢉⣥⣶⡟⠻⣙⡉⠀⢰⡆⠀⠀⣡⠀⣧⠀⠀⠀⢨
|
||
# ⠻⣦⠀⠀⠈⣇⣀⣧⣴⣿⣶⣶⣿⣷⠀⢀⡇⠉⠻⢶⣌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣡⡶⠟⠉⠀⢣⠀⣿⠷⠀⠀⠀⠀⣿⡷⢀⠇⠀⠀⢠⣿
|
||
# ⣦⡈⢧⡀⠀⠘⢮⡙⠛⠉⠀⠄⠙⢿⣀⠞⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⠈⠳⣄⠉⠓⠒⠚⠋⢀⡠⠋⠀⢀⣴⣏⣿
|
||
# ⣿⣿⣿⣛⣦⣀⠀⠙⠓⠦⠤⣤⠔⠛⠁⠀⠀⠀⠀⠀⢀⣀⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣤⣤⣤⣤⣤⣀⣀⣀⣀⢙⢓⣒⡒⠚⠋⢠⣤⢶⣟⣽⣿⣿
|
||
# ⣿⣿⣿⣿⣿⣿⣷⣦⠀⠀⣴⣿⣷⣶⣶⣶⣾⡖⢰⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣾⣿⣿⣶⣾⣿⣿⣿⣿⣿⣿
|
||
# ⣿⣿⣿⣿⣿⣿⣿⣿⠀⢀⣿⣿⣿⣿⣿⣿⣿⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
|
||
# ⣿⣿⣿⣿⣿⣿⣿⡏⠀⢸⣿⣿⣿⣿⣿⣿⣿⠁⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
|
||
# ⣿⣿⣿⣿⣿⣿⣿⣷⠀⢸⣿⣿⣿⣿⣿⣿⣿⠀⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
|
||
|
||
# 🔒 Licensed under the GNU GPLv3
|
||
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
|
||
# https://t.me/amorescam
|
||
|
||
#
|
||
# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
|
||
# █▀█ █ █ █ █▀█ █▀▄ █
|
||
# © Copyright 2022
|
||
#
|
||
# https://t.me/hikariatama
|
||
#
|
||
# 🔒 Licensed under the GNU GPLv3
|
||
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
|
||
|
||
# meta developer: @amoremods
|
||
# meta banner: https://raw.githubusercontent.com/AmoreForever/assets/master/Imgbb.jpg
|
||
|
||
|
||
import imghdr
|
||
import io
|
||
import random
|
||
import re
|
||
|
||
import requests
|
||
from telethon.errors.rpcerrorlist import YouBlockedUserError
|
||
from telethon.tl.types import Message
|
||
from .. import loader, utils
|
||
|
||
|
||
@loader.tds
|
||
class ImgbbUploader(loader.Module):
|
||
"""Upload you photo/video/gif to https://ibb.co"""
|
||
|
||
strings = {
|
||
"name": "Imgbb",
|
||
"noargs": "🚫 <b>File not specified</b>",
|
||
"err": "🚫 <b>Error uploading</b>",
|
||
"ban": "🎒 @Imgbb_com_bot pls unblock this bot",
|
||
"not_an_image": "🚫 <b>This platform only supports images </b>",
|
||
"uploading": "📤 <b>Uploading...</b>",
|
||
}
|
||
|
||
async def get_media(self, message: Message):
|
||
reply = await message.get_reply_message()
|
||
m = None
|
||
if reply and reply.media:
|
||
m = reply
|
||
elif message.media:
|
||
m = message
|
||
elif not reply:
|
||
await utils.answer(message, self.strings("noargs"))
|
||
return False
|
||
|
||
if not m:
|
||
file = io.BytesIO(bytes(reply.raw_text, "utf-8"))
|
||
file.name = "file.txt"
|
||
else:
|
||
file = io.BytesIO(await self._client.download_media(m, bytes))
|
||
file.name = (
|
||
m.file.name
|
||
or (
|
||
"".join(
|
||
[
|
||
random.choice("abcdefghijklmnopqrstuvwxyz1234567890")
|
||
for _ in range(16)
|
||
]
|
||
)
|
||
)
|
||
+ m.file.ext
|
||
)
|
||
|
||
return file
|
||
|
||
async def get_image(self, message: Message):
|
||
file = await self.get_media(message)
|
||
if not file:
|
||
return False
|
||
|
||
if imghdr.what(file) not in ["gif", "png", "jpg", "jpeg", "tiff", "bmp"]:
|
||
await utils.answer(message, self.strings("not_an_image"))
|
||
return False
|
||
|
||
return file
|
||
|
||
async def imgbbcmd(self, message: Message):
|
||
"""imgbb uploader"""
|
||
message = await utils.answer(message, self.strings("uploading"))
|
||
file = await self.get_image(message)
|
||
if not file:
|
||
return
|
||
|
||
chat = "@Imgbb_com_bot"
|
||
|
||
async with self._client.conversation(chat) as conv:
|
||
try:
|
||
m = await conv.send_message(file=file)
|
||
response = await conv.get_response()
|
||
except YouBlockedUserError:
|
||
await utils.answer(message, self.strings("ban"))
|
||
return
|
||
|
||
await m.delete()
|
||
await response.delete()
|
||
|
||
try:
|
||
url = (
|
||
re.search(
|
||
r'<meta property="og:image" data-react-helmet="true"'
|
||
r' content="(.*?)"',
|
||
(await utils.run_sync(requests.get, response.raw_text)).text,
|
||
)
|
||
.group(1)
|
||
.split("?")[0]
|
||
)
|
||
except Exception:
|
||
url = response.raw_text
|
||
await utils.answer(message, f"😸 Your file uploaded: <code>{url}</code>")
|