From 4d2432e3444d78ebd2a6c2dedcb5fa970496bc8d Mon Sep 17 00:00:00 2001 From: yasir Date: Thu, 9 Feb 2023 12:54:59 +0700 Subject: [PATCH] fix --- misskaty/core/message_utils.py | 19 +++--- misskaty/plugins/admin.py | 32 +--------- misskaty/plugins/genss.py | 3 +- misskaty/plugins/inkick_user.py | 8 ++- misskaty/plugins/inline_search.py | 8 ++- misskaty/plugins/session_generator.py | 2 +- misskaty/plugins/web_scraper.py | 92 --------------------------- 7 files changed, 28 insertions(+), 136 deletions(-) diff --git a/misskaty/core/message_utils.py b/misskaty/core/message_utils.py index a2fed6f1..b8c5d719 100644 --- a/misskaty/core/message_utils.py +++ b/misskaty/core/message_utils.py @@ -1,7 +1,7 @@ import asyncio from logging import getLogger -from pyrogram.errors import ChatWriteForbidden, FloodWait, MessageNotModified +from pyrogram.errors import ChatWriteForbidden, FloodWait, MessageNotModified, ChatAdminRequired, MessageIdInvalid LOGGER = getLogger(__name__) @@ -9,26 +9,29 @@ LOGGER = getLogger(__name__) # Send MSG Pyro -async def kirimPesan(msg, text: str, quote=True, disable_web_page_preview=True, reply_markup=None): +async def kirimPesan(msg, text, **kwargs): try: - return await msg.reply(text=text, quote=quote, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) + return await msg.reply(text, **kwargs) except FloodWait as e: LOGGER.warning(str(e)) await asyncio.sleep(e.value) - return await kirimPesan(msg, text=text, quote=quote, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) + return await kirimPesan(msg, text, **kwargs) + except (ChatWriteForbidden, ChatAdminRequired): + LOGGER.info(f"Leaving from {msg.chat.title} [{msg.chat.id}] because doesn't have admin permission.") + return await msg.leave() except Exception as e: LOGGER.error(str(e)) return # Edit MSG Pyro -async def editPesan(msg, text: str, disable_web_page_preview=True, reply_markup=None): +async def editPesan(msg, text, **kwargs): try: - return await msg.edit(text=text, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) + return await msg.edit(text, **kwargs) except FloodWait as e: LOGGER.warning(str(e)) await asyncio.sleep(e.value) - return await editPesan(msg, text=text, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) - except MessageNotModified: + return await editPesan(msg, text, **kwargs) + except (MessageNotModified, MessageIdInvalid): return except Exception as e: LOGGER.error(str(e)) diff --git a/misskaty/plugins/admin.py b/misskaty/plugins/admin.py index d33a70de..2b823d39 100644 --- a/misskaty/plugins/admin.py +++ b/misskaty/plugins/admin.py @@ -17,6 +17,7 @@ from misskaty.core.decorator.permissions import ( member_permissions, ) from misskaty.core.keyboard import ikb +from misskaty.core.message_utils import kirimPesan from misskaty.helper.functions import ( extract_user, extract_user_and_reason, @@ -495,31 +496,6 @@ async def unmute(_, message): await message.reply_text(f"Unmuted! {umention}") -# Ban deleted accounts -@app.on_message(filters.command("ban_ghosts", COMMAND_HANDLER) & filters.group) -@adminsOnly("can_restrict_members") -async def ban_deleted_accounts(_, message): - if not message.from_user: return - chat_id = message.chat.id - deleted_users = [] - m = await message.reply("Finding ghosts...") - - async for i in app.iter_chat_members(chat_id): - if i.user.is_deleted: - deleted_users.append(i.user.id) - if deleted_users: - banned_users = 0 - for deleted_user in deleted_users: - try: - await message.chat.ban_member(deleted_user) - except Exception: - pass - banned_users += 1 - await m.edit(f"Banned {banned_users} Deleted Accounts") - else: - await m.edit("There are no deleted accounts in this chat") - - @app.on_message(filters.command(["warn", "dwarn"], COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def warn_user(client, message): @@ -663,7 +639,6 @@ async def check_warns(_, message): @app.on_message((filters.command("report", COMMAND_HANDLER) | filters.command(["admins", "admin"], prefixes="@")) & filters.group) @capture_err async def report_user(_, message): - if not message.from_user: return if not message.reply_to_message: return await message.reply_text("Reply to a message to report that user.") reply = message.reply_to_message @@ -677,7 +652,6 @@ async def report_user(_, message): if linked_chat is None: if reply_id in list_of_admins or reply_id == message.chat.id: return await message.reply_text("Do you know that the user you are replying is an admin ?") - elif reply_id in list_of_admins or reply_id == message.chat.id or reply_id == linked_chat.id: return await message.reply_text("Do you know that the user you are replying is an admin ?") user_mention = reply.from_user.mention if reply.from_user else reply.sender_chat.title @@ -687,5 +661,5 @@ async def report_user(_, message): if admin.user.is_bot or admin.user.is_deleted: # return bots or deleted admins continue - text += f"[\u2063](tg://user?id={admin.user.id})" - await message.reply_to_message.reply_text(text) + text += f"#Nodrakor Results For: {kueri}\n\n" if kueri else f"#Nodrakor Latest:\n🌀 Use /nodrakor [title] to start search with title.\n\n" - for c, i in enumerate(SCRAP_DICT[msg.id][0][index], start=1): - NodrakorResult += f"{c}. {i['judul']}\nGenre: {i['genre']}\n" - NodrakorResult += f"Extract: /nodrakor_scrap {i['link']}\n\n" if "/tv/" not in i["link"] else "\n" - IGNORE_CHAR = "[]" - NodrakorResult = ''.join(i for i in NodrakorResult if not i in IGNORE_CHAR) - return NodrakorResult, PageLen - except (IndexError, KeyError): - await editPesan(msg, "Sorry could not find any matching results!") - return None, None - # Kusonime GetData async def getDataKuso(msg, kueri, CurrentPage, user): if not SCRAP_DICT.get(msg.id): @@ -492,23 +455,6 @@ async def savefilm_s(client, message): ) await editPesan(pesan, savefilmres, reply_markup=keyboard) -# Nodrakor CMD -@app.on_message(filters.command(['nodrakor'], COMMAND_HANDLER)) -async def nodrakor_s(client, message): - kueri = ' '.join(message.command[1:]) - if not kueri: - kueri = "" - pesan = await kirimPesan(message, "⏳ Please wait, scraping data from Nodrakor..", quote=True) - CurrentPage = 1 - nodrakorres, PageLen = await getDataNodrakor(pesan, kueri, CurrentPage) - if not nodrakorres: return - keyboard = InlineKeyboard() - keyboard.paginate(PageLen, CurrentPage, 'page_nodrakor#{number}' + f'#{pesan.id}#{message.from_user.id}') - keyboard.row( - InlineButton("❌ Close", f"close#{message.from_user.id}") - ) - await editPesan(pesan, nodrakorres, reply_markup=keyboard) - # Kusonime CMD @app.on_message(filters.command(['kusonime'], COMMAND_HANDLER)) async def kusonime_s(client, message): @@ -620,30 +566,6 @@ async def kusopage_callback(client, callback_query): ) await editPesan(callback_query.message, kusores, reply_markup=keyboard) -# Nodrakor Page Callback -@app.on_callback_query(filters.create(lambda _, __, query: 'page_nodrakor#' in query.data)) -async def nodraakorpage_callback(client, callback_query): - if callback_query.from_user.id != int(callback_query.data.split('#')[3]): - return await callback_query.answer("Not yours..", True) - message_id = int(callback_query.data.split('#')[2]) - CurrentPage = int(callback_query.data.split('#')[1]) - try: - kueri = SCRAP_DICT[message_id][1] - except KeyError: - return await callback_query.answer("Invalid callback data, please send CMD again..") - - try: - modrakorres, PageLen = await getDataNodrakor(callback_query.message, kueri, CurrentPage) - except TypeError: - return - - keyboard = InlineKeyboard() - keyboard.paginate(PageLen, CurrentPage, 'page_nodrakor#{number}' + f'#{message_id}#{callback_query.from_user.id}') - keyboard.row( - InlineButton("❌ Close", f"close#{callback_query.from_user.id}") - ) - await editPesan(callback_query.message, modrakorres, reply_markup=keyboard) - # Lendrive Page Callback @app.on_callback_query(filters.create(lambda _, __, query: 'page_lendrive#' in query.data)) async def moviekupage_callback(client, callback_query): @@ -882,20 +804,6 @@ async def savefilm21_scrap(_, callback_query): return await editPesan(callback_query.message, f"Scrape result from {link}:\n\n{res}", reply_markup=keyboard) -# Scrape DDL Link Nodrakor -@app.on_message(filters.command(["nodrakor_scrap"], COMMAND_HANDLER)) -async def nodrakor_scrap(_, message): - try: - link = message.text.split(" ", maxsplit=1)[1] - html = await http.get(link, headers=headers) - soup = BeautifulSoup(html.text, "lxml") - hasil = soup.find_all(class_="gmr-download-wrap clearfix")[0] - await message.reply(f"Hasil Scrap dari {link}:\n{hasil}") - except IndexError: - return await message.reply(f"Gunakan command /{message.command[0]} [link] untuk scrap link download") - except Exception as e: - await message.reply(f"ERROR: {str(e)}") - # Scrape Link Download Movieku.CC @app.on_message(filters.command(["movieku_scrap"], COMMAND_HANDLER))