Skip to content

Commit

Permalink
fix: safone api & add rayso (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiTheModder authored Nov 12, 2024
1 parent 7ff0f16 commit d53e7cb
Showing 1 changed file with 101 additions and 18 deletions.
119 changes: 101 additions & 18 deletions modules/safone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from utils.misc import prefix, modules_help
from utils.scripts import format_exc, make_carbon

url = "https://api.safone.dev"
url = "https://api.safone.co"

headers = {
"Accept-Language": "en-US,en;q=0.9",
Expand Down Expand Up @@ -51,6 +51,31 @@ async def voice_characters():
return ", ".join(result["characters"])


async def make_rayso(code: str, title: str, theme: str):
data = {
"code": code,
"title": title,
"theme": theme,
"padding": 64,
"language": "auto",
"darkMode": False,
}
response = requests.post(f"{url}/rayso", data=data, headers=headers)
if response.status_code != 200:
return None
result = response.json()
try:
if result["error"] is not None:
return None
except KeyError:
pass
image_data = result["image"]
file_name = "rayso.png"
with open(file_name, "wb") as f:
f.write(base64.b64decode(image_data))
return file_name


@Client.on_message(filters.command("asq", prefix) & filters.me)
async def asq(_, message: Message):
if len(message.command) > 1:
Expand Down Expand Up @@ -333,28 +358,12 @@ async def tts(client: Client, message: Message):
filters.command(["carbonnowsh", "carboon", "carbon", "cboon"], prefix) & filters.me
)
async def carbon(client: Client, message: Message):
if message.reply_to_message.text:
if message.reply_to_message:
text = message.reply_to_message.text
message_id = message.reply_to_message.id
elif len(message.command) > 1:
message_id = None
text = message.text.split(maxsplit=1)[1]
elif message.document:
message_id = message.id
filepath = f"downloads/{message.document.file_name}"
await message.download(filepath)
with open(filepath, "r", encoding="utf-8") as f:
text = f.read()
if os.path.exists(filepath):
os.remove(filepath)
elif message.reply_to_message.document:
message_id = message.reply_to_message.id
filepath = f"downloads/{message.reply_to_message.document.file_name}"
await message.reply_to_message.download(filepath)
with open(filepath, "r", encoding="utf-8") as f:
text = f.read()
if os.path.exists(filepath):
os.remove(filepath)
else:
await message.edit_text("Query not provided!")
return
Expand Down Expand Up @@ -407,6 +416,79 @@ async def ccgen(_, message: Message):
)


@Client.on_message(filters.command("rayso", prefix) & filters.me)
async def rayso(client: Client, message: Message):
title = "Untitled"
themes = [
"vercel",
"supabase",
"tailwind",
"clerk",
"mintlify",
"prisma",
"bitmap",
"noir",
"ice",
"sand",
"forest",
"mono",
"breeze",
"candy",
"crimson",
"falcon",
"meadow",
"midnight",
"raindrop",
"sunset",
]
if message.reply_to_message:
text = message.reply_to_message.text
message_id = message.reply_to_message.id
if 2 <= len(message.command) <= 3:
title = message.text.split(maxsplit=2)[1]
theme = message.text.split(maxsplit=2)[2].lower()
if theme not in themes:
theme = "breeze"
elif len(message.command) > 1:
message_id = message.id
title = message.text.split(maxsplit=3)[1]
theme = message.text.split(maxsplit=3)[2]
if theme not in themes:
theme = "breeze"
text = message.text.split(maxsplit=3)[3]
else:
await message.edit_text("Query not provided!")
return
await message.edit_text("Processing...")

image_file = await make_rayso(text, title, theme)

if image_file is None:
await message.edit_text("Something went wrong")
return
try:
await client.send_photo(
chat_id=message.chat.id,
photo=image_file,
caption=f"<b>Text:</b> <code>{text}</code>",
reply_to_message_id=message_id,
)
await message.delete()
except MediaCaptionTooLong:
cap = text[:850]
await client.send_photo(
chat_id=message.chat.id,
photo=image_file,
caption=f"<b>Text:</b> <code>{cap}</code>",
reply_to_message_id=message_id,
)
await message.delete()
except Exception as e:
await message.edit_text(format_exc(e))
if os.path.exists(image_file):
os.remove(image_file)


modules_help["safone"] = {
"asq [query]*": "Asq",
"app [query]*": "Search for an app on Play Store",
Expand All @@ -415,4 +497,5 @@ async def ccgen(_, message: Message):
"sgemini [prompt]*": "Gemini Model through safone api",
"carbon [code/file/reply]": "Create beautiful image with your code",
"ccgen [bins]*": "Generate credit cards",
"rayso [title]* [theme]* [text/reply to text]*": "Create beautiful image with your text",
}

0 comments on commit d53e7cb

Please sign in to comment.