diff --git a/misskaty/__init__.py b/misskaty/__init__.py index 4045238a..1542b41f 100644 --- a/misskaty/__init__.py +++ b/misskaty/__init__.py @@ -28,7 +28,7 @@ MOD_NOLOAD = ["subscene_dl"] HELPABLE = {} cleanmode = {} botStartTime = time.time() -misskaty_version = "v2.023.5.9 - Stable" +misskaty_version = "v2.023.5.16 - Stable" pymonclient = MongoClient(DATABASE_URI) mongo = AsyncIOMotorClient(DATABASE_URI) diff --git a/misskaty/plugins/dev.py b/misskaty/plugins/dev.py index b8636a58..8f1b7709 100644 --- a/misskaty/plugins/dev.py +++ b/misskaty/plugins/dev.py @@ -22,6 +22,7 @@ from psutil import virtual_memory from pyrogram import enums, filters, Client, __version__ as pyrover from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message from pyrogram.raw.types import UpdateBotStopped +from pykeyboard import InlineKeyboard from misskaty import app, user, botStartTime, misskaty_version, BOT_NAME from misskaty.helper.http import http @@ -81,10 +82,18 @@ async def log_file(self: Client, ctx: Message, strings) -> "Message": @app.on_message(filters.command(["donate"], COMMAND_HANDLER)) -async def donate(_, message): - await message.reply_photo( - "https://telegra.ph/file/2acf7698f300ef3d9138f.jpg", - caption=f"Hai {message.from_user.mention}, jika kamu merasa bot ini berguna bisa melakukan donasi dengan scan kode QRIS diatas yaa. Terimakasih..", +async def donate(client, ctx): + keyboard = InlineKeyboard(row_width=3) + keyboard.add( + InlineButton('QR QRIS [Yasir Store]', url='https://telegra.ph/file/2acf7698f300ef3d9138f.jpg'), + InlineButton('Bank Jago [Yasir Aris M]', '109641845083'), + InlineButton('Saweria', url='https://saweria.co/yasirarism'), + InlineButton('Trakteer', url='https://trakteer.id/yasir-aris-sp7cn'), + InlineButton('Ko-Fi', url='https://ko-fi.com/yasirarism'), + InlineButton('PayPal', url='https://paypal.me/yasirarism'), + ) + await ctx.reply( + f"Hai {message.from_user.mention}, jika kamu merasa bot ini besrguna bisa melakukan donasi dengan ke rekening diatas yaa. Karena server bot ini tidaklah gratis. Terimakasih..\n\n"Hi {message.from_user.mention}, if you feel this bot is useful, you can make a donation to the account above. Because this bot server is not free. Thank you..", ) diff --git a/misskaty/plugins/filter_request.py b/misskaty/plugins/filter_request.py index c70ca6da..f466905d 100644 --- a/misskaty/plugins/filter_request.py +++ b/misskaty/plugins/filter_request.py @@ -10,6 +10,7 @@ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from misskaty import app from .web_scraper import SCRAP_DICT, data_kuso from .pypi_search import PYPI_DICT +from .ytdl_plugins import YT_DB from misskaty.core.decorator.permissions import admins_in_chat from misskaty.core.decorator.ratelimiter import ratelimiter from misskaty.core.decorator.errors import capture_err @@ -115,6 +116,7 @@ async def clear_reqdict(): data_kuso.clear() REQUEST_DB.clear() PYPI_DICT.clear() + YT_DB.clear() admins_in_chat.clear() try: os.rmdir("downloads") diff --git a/misskaty/plugins/media_extractor.py b/misskaty/plugins/media_extractor.py index 62020eb5..68e1de41 100644 --- a/misskaty/plugins/media_extractor.py +++ b/misskaty/plugins/media_extractor.py @@ -54,13 +54,13 @@ def get_base_name(orig_path: str): return ngesplit(f"{ext}$", orig_path, maxsplit=1, flags=I)[0] -def get_subname(lang, url, format): +def get_subname(lang, url, ext): fragment_removed = url.split("#")[0] # keep to left of first # query_string_removed = fragment_removed.split("?")[0] scheme_removed = query_string_removed.split("://")[-1].split(":")[-1] if scheme_removed.find("/") == -1 or not get_base_name(os.path.basename(unquote(scheme_removed))): - return f"[{lang.upper()}] MissKatySub{get_random_string(4)}.{format}" - return f"[{lang.upper()}] {get_base_name(os.path.basename(unquote(scheme_removed)))}.{format}" + return f"[{lang.upper()}] MissKatySub{get_random_string(4)}.{ext}" + return f"[{lang.upper()}] {get_base_name(os.path.basename(unquote(scheme_removed)))}.{ext}" @app.on_message(filters.command(["ceksub", "extractmedia"], COMMAND_HANDLER)) @@ -159,15 +159,15 @@ async def stream_extract(self: Client, update: CallbackQuery, strings): return await update.answer(strings("invalid_cb"), True) await update.message.edit_msg(strings("progress_str")) if codec == "aac": - format = "aac" + ext = "aac" elif codec == "mp3": - format = "mp3" + ext = "mp3" elif codec == "eac3": - format = "eac3" + ext = "eac3" else: - format = "srt" + ext = "srt" start_time = time() - namafile = get_subname(lang, link, format) + namafile = get_subname(lang, link, ext) try: LOGGER.info(f"ExtractSub: {namafile} by {update.from_user.first_name} [{update.from_user.id}]") (await shell_exec(f"mediaextract -i {link} -map {map} '{namafile}'"))[0] diff --git a/misskaty/plugins/misc_tools.py b/misskaty/plugins/misc_tools.py index e9aa59d8..f00f5f69 100644 --- a/misskaty/plugins/misc_tools.py +++ b/misskaty/plugins/misc_tools.py @@ -349,8 +349,11 @@ async def close_callback(bot: Client, query: CallbackQuery): return await query.answer("⚠️ Access Denied!", True) await query.answer("Deleting this message in 5 seconds.") await asyncio.sleep(5) - await query.message.delete_msg() - await query.message.reply_to_message.delete_msg() + try: + await query.message.delete() + await query.message.reply_to_message.delete() + except: + pass headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10"} diff --git a/misskaty/plugins/ocr.py b/misskaty/plugins/ocr.py index bdd3bad8..7eafc9b6 100644 --- a/misskaty/plugins/ocr.py +++ b/misskaty/plugins/ocr.py @@ -30,7 +30,7 @@ __HELP__ = "/ocr [reply to photo] - Read Text From Image" @use_chat_lang() async def ocr(self: Client, ctx: Message, strings): reply = ctx.reply_to_message - if not reply and not reply.photo or not (reply.document and reply.document.mime_type.startswith("image")) or not reply.sticker: + if not reply or not reply.photo or not (reply.document and reply.document.mime_type.startswith("image")) or not reply.sticker: return await ctx.reply_msg(strings("no_photo").format(cmd=ctx.command[0]), quote=True, del_in=6) msg = await ctx.reply_msg(strings("read_ocr"), quote=True) try: @@ -46,13 +46,9 @@ async def ocr(self: Client, ctx: Message, strings): ) ).json() await msg.edit_msg(strings("result_ocr").format(result=req["text"])) - try: + if os.path.exists(file_path): os.remove(file_path) - except: - pass except Exception as e: await msg.edit_msg(str(e)) - try: + if os.path.exists(file_path): os.remove(file_path) - except: - pass diff --git a/misskaty/plugins/session_generator.py b/misskaty/plugins/session_generator.py index 92055246..344d5816 100644 --- a/misskaty/plugins/session_generator.py +++ b/misskaty/plugins/session_generator.py @@ -5,6 +5,7 @@ from pyrogram import Client, filters from pyrogram.errors import ApiIdInvalid, PasswordHashInvalid, PhoneCodeExpired, PhoneCodeInvalid, PhoneNumberInvalid, SessionPasswordNeeded from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from telethon import TelegramClient +from misskaty.core.misskaty_patch.listen.listen import ListenerTimeout from telethon.errors import ApiIdInvalidError, PasswordHashInvalidError, PhoneCodeExpiredError, PhoneCodeInvalidError, PhoneNumberInvalidError, SessionPasswordNeededError from telethon.sessions import StringSession @@ -98,8 +99,7 @@ async def generate_session(bot, msg, telethon=False, is_bot: bool = False): api_id = int(api_id_msg.text) await api_id_msg.delete() except ValueError: - await api_id_msg.reply("**API_ID** must be integer, start generating your session again.", quote=True, reply_markup=InlineKeyboardMarkup(gen_button)) - return + return await api_id_msg.reply("**API_ID** must be integer, start generating your session again.", quote=True, reply_markup=InlineKeyboardMarkup(gen_button)) api_hash_msg = await msg.chat.ask("» Now please send your **API_HASH** to continue.", filters=filters.text) if await is_batal(api_hash_msg): return @@ -130,20 +130,17 @@ async def generate_session(bot, msg, telethon=False, is_bot: bool = False): else: code = await client.send_code(phone_number) except (ApiIdInvalid, ApiIdInvalidError): - await msg.reply("» Your **API_ID** and **API_HASH** combination doesn't match. \n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) - return + return await msg.reply("» Your **API_ID** and **API_HASH** combination doesn't match. \n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) except (PhoneNumberInvalid, PhoneNumberInvalidError): - await msg.reply("» The **PHONE_NUMBER** you've doesn't belong to any account in Telegram.\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) - return + return await msg.reply("» The **PHONE_NUMBER** you've doesn't belong to any account in Telegram.\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) try: phone_code_msg = None if not is_bot: phone_code_msg = await msg.chat.ask("» Please send the **OTP** That you've received from Telegram on your account.\nIf OTP is `12345`, **please send it as** `1 2 3 4 5`.", filters=filters.text, timeout=600) if await is_batal(phone_code_msg): return - except TimeoutError: - await msg.reply("» Time limit reached of 10 minutes.\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) - return + except ListenerTimeout: + return await msg.reply("» Time limit reached of 10 minutes.\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) if not is_bot: phone_code = phone_code_msg.text.replace(" ", "") await phone_code_msg.delete() @@ -153,17 +150,14 @@ async def generate_session(bot, msg, telethon=False, is_bot: bool = False): else: await client.sign_in(phone_number, code.phone_code_hash, phone_code) except (PhoneCodeInvalid, PhoneCodeInvalidError): - await msg.reply("» The OTP you've sent is **wrong.**\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) - return + return await msg.reply("» The OTP you've sent is **wrong.**\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) except (PhoneCodeExpired, PhoneCodeExpiredError): - await msg.reply("» The OTP you've sent is **expired.**\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) - return + return await msg.reply("» The OTP you've sent is **expired.**\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) except (SessionPasswordNeeded, SessionPasswordNeededError): try: two_step_msg = await msg.chat.ask("» Please enter your **Two Step Verification** password to continue.", filters=filters.text, timeout=300) - except TimeoutError: - await msg.reply("» Time limit reached of 5 minutes.\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) - return + except ListenerTimeout: + return await msg.reply("» Time limit reached of 5 minutes.\n\nPlease start generating your session again.", reply_markup=InlineKeyboardMarkup(gen_button)) try: password = two_step_msg.text await two_step_msg.delete() @@ -174,9 +168,9 @@ async def generate_session(bot, msg, telethon=False, is_bot: bool = False): if await is_batal(api_id_msg): return except (PasswordHashInvalid, PasswordHashInvalidError): - await two_step_msg.reply("» The password you've sent is wrong.\n\nPlease start generating session again.", quote=True, reply_markup=InlineKeyboardMarkup(gen_button)) - return + return await two_step_msg.reply("» The password you've sent is wrong.\n\nPlease start generating session again.", quote=True, reply_markup=InlineKeyboardMarkup(gen_button)) elif telethon: + try: await client.start(bot_token=phone_number) else: await client.sign_in_bot(phone_number) diff --git a/misskaty/plugins/stickers.py b/misskaty/plugins/stickers.py index 88f3a4a2..2bf40981 100644 --- a/misskaty/plugins/stickers.py +++ b/misskaty/plugins/stickers.py @@ -46,7 +46,10 @@ SUPPORTED_TYPES = ["jpeg", "png", "webp"] @ratelimiter @use_chat_lang() async def getsticker_(self: Client, ctx: Message, strings): - if sticker := ctx.reply_to_message.sticker: + if not ctx.reply_to_message or ctx.reply_to_message.sticker: + await ctx.reply_msg(strings("not_sticker")) + else: + sticker = ctx.reply_to_message.sticker if sticker.is_animated: await ctx.reply_msg(strings("no_anim_stick")) else: @@ -56,13 +59,11 @@ async def getsticker_(self: Client, ctx: Message, strings): message=ctx.reply_to_message, file_name=f"{path}/{sticker.set_name}.png", ) - await self.reply_to_message.reply_document( + await ctx.reply_to_message.reply_document( document=sticker_file, caption=f"Emoji: {sticker.emoji}\n" f"Sticker ID: {sticker.file_id}\n\n" f"Send by: @{BOT_USERNAME}", ) shutil.rmtree(tempdir, ignore_errors=True) - else: - await ctx.reply_msg(strings("not_sticker")) @app.on_message(filters.command("stickerid", COMMAND_HANDLER) & filters.reply) diff --git a/misskaty/plugins/urban_dict.py b/misskaty/plugins/urban_dict.py index bed05861..decf5cae 100644 --- a/misskaty/plugins/urban_dict.py +++ b/misskaty/plugins/urban_dict.py @@ -35,7 +35,10 @@ async def urbanDictionary(self: Client, ctx: Message): GetWord = message.text CurrentPage = 1 - UDReasult, PageLen = await getData(chat_id, message_id, GetWord, CurrentPage) + try: + UDReasult, PageLen = await getData(chat_id, message_id, GetWord, CurrentPage) + except: + return await ctx.reply_msg("😭 Failed getting info from urban dictionary.") keyboard = InlineKeyboard() keyboard.paginate(PageLen, CurrentPage, "pagination_urban#{number}" + f"#{GetWord}") @@ -57,4 +60,4 @@ async def ud_callback(self: Client, callback_query: CallbackQuery): keyboard = InlineKeyboard() keyboard.paginate(PageLen, CurrentPage, "pagination_urban#{number}" + f"#{GetWord}") - await app.edit_msg(chat_id=chat_id, message_id=message_id, text=UDReasult, reply_markup=keyboard) + await callback_query.message.edit_msg(text=UDReasult, reply_markup=keyboard)