From 175f1d98b96f23fbbc146e7662d0c1910e3289d7 Mon Sep 17 00:00:00 2001
From: yasirarism <55983182+yasirarism@users.noreply.github.com>
Date: Tue, 4 Jul 2023 12:06:16 +0700
Subject: [PATCH] Add kbbi and carbon
---
misskaty/__init__.py | 2 +-
misskaty/plugins/misc_tools.py | 38 ++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/misskaty/__init__.py b/misskaty/__init__.py
index 44c2fbbe..3bfb6205 100644
--- a/misskaty/__init__.py
+++ b/misskaty/__init__.py
@@ -40,7 +40,7 @@ MOD_NOLOAD = ["subscene_dl"]
HELPABLE = {}
cleanmode = {}
botStartTime = time.time()
-misskaty_version = "v2.9.3 - Stable"
+misskaty_version = "v2.10.1 - Stable"
# Pyrogram Bot Client
app = Client(
diff --git a/misskaty/plugins/misc_tools.py b/misskaty/plugins/misc_tools.py
index ed121dfd..a3a6f16b 100644
--- a/misskaty/plugins/misc_tools.py
+++ b/misskaty/plugins/misc_tools.py
@@ -33,6 +33,8 @@ LOGGER = getLogger(__name__)
__MODULE__ = "Misc"
__HELP__ = """
+/carbon [text or reply to text or caption] - Make beautiful snippet code on carbon from text.
+/kbbi [keyword] - Search definition on KBBI (For Indonesian People)
/sof [query] - Search your problem in StackOverflow.
/google [query] - Search using Google Search.
(/tr, /trans, /translate) [lang code] - Translate text using Google Translate.
@@ -54,6 +56,42 @@ def remove_html_tags(text):
return re.sub(clean, "", text)
+@app.on_cmd("kbbi")
+async def kbbi_search(_, ctx: Client):
+ if len(ctx.command) == 1:
+ return await ctx.reply_msg("Please add keyword to search definition in kbbi")
+ r = (await http.get(f"https://yasirapi.eu.org/kbbi?kata={ctx.input}")).json()
+ res = f"Link: {r.get('link')}\nDefinisi:\n"
+ for a in r.get("result"):
+ submakna = "".join(f"{a}, " for a in a['makna'][0]['submakna'])[:-2]
+ contoh = "".join(f"{a}, " for a in a['makna'][0]['contoh'])[:-2]
+ res += f"{a['nomor']}. {a['nama']} ({a['makna'][0]['kelas'][0]['nama']}: {a['makna'][0]['kelas'][0]['deskripsi']})\nKata Dasar: {a['kata_dasar'] if a['kata_dasar'] else '-'}\nBentuk Tidak Baku: {a['bentuk_tidak_baku'] if a['bentuk_tidak_baku'] else '-'}\nSubmakna: {submakna}\nContoh: {contoh if contoh else '-'}\n"
+ await ctx.reply(res)
+
+
+@app.on_cmd("carbon")
+async def carbon_make(_, ctx: Client):
+ if len(ctx.command) or not ctx.reply_to_message:
+ return await ctx.reply("Please reply text to make carbon or add text after command.")
+ if ctx.reply_to_message.text:
+ text = ctx.reply_to_message.text
+ elif ctx.reply_to_message.caption:
+ text = ctx.reply_to_message.caption
+ else:
+ text = ctx.input
+ json_data = {
+ 'code': text,
+ 'backgroundColor': '#1F816D',
+ }
+
+ response = await http.post('https://carbon.yasirapi.eu.org/api/cook', json=json_data)
+ fname = f"carbonBY_{ctx.from_user.id if ctx.from_user else ctx.sender_chat.title}.png"
+ with open(fname, 'wb') as e:
+ e.write(response.content)
+ await ctx.reply_photo(fname)
+ os.remove(fname)
+
+
@app.on_message(filters.command("readqr", COMMAND_HANDLER))
@ratelimiter
async def readqr(c, m):