From b9c385209838aeff1a7ea5908e7fe96ae3d75bd5 Mon Sep 17 00:00:00 2001 From: yasir Date: Wed, 1 Feb 2023 20:58:54 +0700 Subject: [PATCH] Try fix some error --- database/__init__.py | 9 ++ misskaty/__init__.py | 1 - misskaty/core/decorator/errors.py | 3 +- misskaty/core/decorator/pyro_cooldown.py | 38 ++++++++ misskaty/helper/__init__.py | 15 +++- misskaty/helper/tools.py | 1 - misskaty/plugins/admin.py | 34 +++---- misskaty/plugins/afk.py | 22 ++--- misskaty/plugins/auto_approve.py | 1 + misskaty/plugins/banned.py | 8 +- misskaty/plugins/broadcast.py | 9 +- misskaty/plugins/bypass.py | 18 ++-- .../plugins/{chatbot.py => chatbot_ai.py} | 9 +- misskaty/plugins/detect_afk.py | 2 +- misskaty/plugins/filters.py | 61 ++++++------- misskaty/plugins/genss.py | 89 ++++++++----------- misskaty/plugins/grup_tools.py | 2 +- misskaty/plugins/mediainfo.py | 31 +++---- misskaty/plugins/nightmode.py | 2 +- misskaty/plugins/ocr.py | 15 ++-- misskaty/plugins/sangmata.py | 5 +- misskaty/plugins/sed.py | 3 +- misskaty/plugins/stickers.py | 25 ++---- misskaty/plugins/webss.py | 21 ++--- 24 files changed, 226 insertions(+), 198 deletions(-) create mode 100644 misskaty/core/decorator/pyro_cooldown.py rename misskaty/plugins/{chatbot.py => chatbot_ai.py} (67%) diff --git a/database/__init__.py b/database/__init__.py index de382f75..20201831 100644 --- a/database/__init__.py +++ b/database/__init__.py @@ -9,5 +9,14 @@ from motor.motor_asyncio import AsyncIOMotorClient as MongoClient from misskaty.vars import DATABASE_URI +from .afk_db import * +from .filters_db import * +from .imdb_db import * +from .karma_db import * +from .notes_db import * +from .sangmata_db import * +from .users_chats_db import * +from .warn_db import * + mongo = MongoClient(DATABASE_URI) dbname = mongo.MissKatyDB diff --git a/misskaty/__init__.py b/misskaty/__init__.py index 6da92041..b564e379 100644 --- a/misskaty/__init__.py +++ b/misskaty/__init__.py @@ -15,7 +15,6 @@ getLogger("pyrogram").setLevel(ERROR) MOD_LOAD = [] MOD_NOLOAD = [] HELPABLE = {} -DL_TASK = {} cleanmode = {} botStartTime = time.time() diff --git a/misskaty/core/decorator/errors.py b/misskaty/core/decorator/errors.py index 4c1cdea7..2fc1c62a 100644 --- a/misskaty/core/decorator/errors.py +++ b/misskaty/core/decorator/errors.py @@ -42,8 +42,7 @@ def capture_err(func): try: return await func(client, message, *args, **kwargs) except ChatWriteForbidden: - await app.leave_chat(message.chat.id) - return + return await app.leave_chat(message.chat.id) except Exception as err: exc = traceback.format_exc() error_feedback = split_limits( diff --git a/misskaty/core/decorator/pyro_cooldown.py b/misskaty/core/decorator/pyro_cooldown.py new file mode 100644 index 00000000..0deaa855 --- /dev/null +++ b/misskaty/core/decorator/pyro_cooldown.py @@ -0,0 +1,38 @@ +from pyrogram import filters + +from datetime import datetime +import datetime as dtime +import asyncio, time + +data = {} + +async def task(msg, warn = False, sec = None): + try:await msg.delete() + except:pass + if warn: + user = msg.from_user + ids = await msg.reply(f"Sorry {user.mention}, you're in cooldown now, wait for {sec}s to use command again..") + await asyncio.sleep(sec) + await ids.edit(f"Alright {user.mention}, your cooldown is over you can command again.") + await asyncio.sleep(1) + await ids.delete() + +def wait(sec): + async def ___(flt, cli, msg): + user_id = msg.from_user.id + if user_id in data: + if msg.date >= data[user_id]['timestamp'] + flt.data: + data[user_id] = {'timestamp' : msg.date, 'warned' : False} + return True + else: + if not data[user_id]['warned']: + data[user_id]['warned'] = True + asyncio.ensure_future(task(msg, True, flt.data)) # for super accuracy use (future - time.time()) + return False # cause we dont need delete again + + asyncio.ensure_future(task(msg)) + return False + else: + data.update({user_id : {'timestamp' : msg.date, 'warned' : False}}) + return True + return filters.create(___, data=sec) \ No newline at end of file diff --git a/misskaty/helper/__init__.py b/misskaty/helper/__init__.py index b350b85d..eaac85a8 100644 --- a/misskaty/helper/__init__.py +++ b/misskaty/helper/__init__.py @@ -1,2 +1,13 @@ -from .misc import paginate_modules -from .tools import bot_sys_stats +from .ffmpeg_helper import * +from .files import * +from .functions import * +from .http import * +from .human_read import * +from .kuso_utils import * +from .media_helper import * +from .misc import * +from .pyro_progress import * +from .stickerset import * +from .time_gap import * +from .tools import * +from .ytdl_helper import * \ No newline at end of file diff --git a/misskaty/helper/tools.py b/misskaty/helper/tools.py index 076d0709..ff1bea2d 100644 --- a/misskaty/helper/tools.py +++ b/misskaty/helper/tools.py @@ -2,7 +2,6 @@ import os import random import string import time -import json import logging from http.cookies import SimpleCookie from urllib.parse import urlparse diff --git a/misskaty/plugins/admin.py b/misskaty/plugins/admin.py index afe88f66..fda4e1bb 100644 --- a/misskaty/plugins/admin.py +++ b/misskaty/plugins/admin.py @@ -71,7 +71,7 @@ async def admin_cache_func(_, cmu): # Purge CMD -@app.on_message(filters.command("purge", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("purge", COMMAND_HANDLER) & filters.group) @adminsOnly("can_delete_messages") async def purge(_, message): try: @@ -124,7 +124,7 @@ async def purge(_, message): # Kick members -@app.on_message(filters.command(["kick", "dkick"], COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command(["kick", "dkick"], COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def kickFunc(client, message): user_id, reason = await extract_user_and_reason(message) @@ -153,7 +153,7 @@ async def kickFunc(client, message): # Ban/DBan/TBan User -@app.on_message(filters.command(["ban", "dban", "tban"], COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command(["ban", "dban", "tban"], COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def banFunc(client, message): user_id, reason = await extract_user_and_reason(message, sender_chat=True) @@ -203,7 +203,7 @@ async def banFunc(client, message): # Unban members -@app.on_message(filters.command("unban", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("unban", COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def unban_func(_, message): # we don't need reasons for unban, also, we @@ -227,7 +227,7 @@ async def unban_func(_, message): # Ban users listed in a message -@app.on_message(filters.user(SUDO) & filters.command("listban", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.user(SUDO) & filters.command("listban", COMMAND_HANDLER) & filters.group) async def list_ban_(c, message): userid, msglink_reason = await extract_user_and_reason(message) if not userid or not msglink_reason: @@ -276,7 +276,7 @@ async def list_ban_(c, message): # Unban users listed in a message -@app.on_message(filters.user(SUDO) & filters.command("listunban", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.user(SUDO) & filters.command("listunban", COMMAND_HANDLER) & filters.group) async def list_unban_(c, message): userid, msglink = await extract_user_and_reason(message) if not userid or not msglink: @@ -317,7 +317,7 @@ async def list_unban_(c, message): # Delete messages -@app.on_message(filters.command("del", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("del", COMMAND_HANDLER) & filters.group) @adminsOnly("can_delete_messages") async def deleteFunc(_, message): if not message.reply_to_message: @@ -330,7 +330,7 @@ async def deleteFunc(_, message): # Promote Members -@app.on_message(filters.command(["promote", "fullpromote"], COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command(["promote", "fullpromote"], COMMAND_HANDLER) & filters.group) @adminsOnly("can_promote_members") async def promoteFunc(client, message): try: @@ -374,7 +374,7 @@ async def promoteFunc(client, message): # Demote Member -@app.on_message(filters.command("demote", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("demote", COMMAND_HANDLER) & filters.group) @adminsOnly("can_promote_members") async def demote(client, message): user_id = await extract_user(message) @@ -400,7 +400,7 @@ async def demote(client, message): # Pin Messages -@app.on_message(filters.command(["pin", "unpin"], COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command(["pin", "unpin"], COMMAND_HANDLER) & filters.group) @adminsOnly("can_pin_messages") async def pin(_, message): if not message.reply_to_message: @@ -426,7 +426,7 @@ async def pin(_, message): # Mute members -@app.on_message(filters.command(["mute", "tmute"], COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command(["mute", "tmute"], COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def mute(client, message): try: @@ -472,7 +472,7 @@ async def mute(client, message): # Unmute members -@app.on_message(filters.command("unmute", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("unmute", COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def unmute(_, message): user_id = await extract_user(message) @@ -484,7 +484,7 @@ async def unmute(_, message): # Ban deleted accounts -@app.on_message(filters.command("ban_ghosts", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("ban_ghosts", COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def ban_deleted_accounts(_, message): chat_id = message.chat.id @@ -507,7 +507,7 @@ async def ban_deleted_accounts(_, message): await m.edit("There are no deleted accounts in this chat") -@app.on_message(filters.command(["warn", "dwarn"], COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command(["warn", "dwarn"], COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def warn_user(client, message): user_id, reason = await extract_user_and_reason(message) @@ -609,7 +609,7 @@ async def unban_user(_, cq): # Remove Warn -@app.on_message(filters.command("rmwarn", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("rmwarn", COMMAND_HANDLER) & filters.group) @adminsOnly("can_restrict_members") async def remove_warnings(_, message): if not message.reply_to_message: @@ -628,7 +628,7 @@ async def remove_warnings(_, message): # Warns -@app.on_message(filters.command("warns", COMMAND_HANDLER) & ~filters.private) +@app.on_message(filters.command("warns", COMMAND_HANDLER) & filters.group) @capture_err async def check_warns(_, message): user_id = await extract_user(message) @@ -644,7 +644,7 @@ async def check_warns(_, message): # Report User in Group -@app.on_message((filters.command("report", COMMAND_HANDLER) | filters.command(["admins", "admin"], prefixes="@")) & ~filters.private) +@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.reply_to_message: diff --git a/misskaty/plugins/afk.py b/misskaty/plugins/afk.py index e1734629..677aec7c 100644 --- a/misskaty/plugins/afk.py +++ b/misskaty/plugins/afk.py @@ -13,11 +13,13 @@ import time from pyrogram import filters -from database.afk_db import add_afk, cleanmode_off, cleanmode_on, is_afk, remove_afk +from database.afk_db import (add_afk, cleanmode_off, cleanmode_on, is_afk, + remove_afk) from misskaty import app from misskaty.core.decorator.errors import capture_err from misskaty.core.decorator.permissions import adminsOnly -from misskaty.helper.human_read import get_readable_time2 +from misskaty.core.message_utils import kirimPesan +from misskaty.helper import get_readable_time2 from misskaty.vars import COMMAND_HANDLER from utils import put_cleanmode @@ -33,7 +35,7 @@ Just type something in group to remove AFK Status.""" @app.on_message(filters.command(["afk"], COMMAND_HANDLER)) async def active_afk(_, message): if message.sender_chat: - return + return await kirimPesan(message, "This feature not supported for channel.") user_id = message.from_user.id verifier, reasondb = await is_afk(user_id) if verifier: @@ -176,24 +178,24 @@ async def active_afk(_, message): } await add_afk(user_id, details) - send = await message.reply_text(f"{message.from_user.mention} [{message.from_user.id}] is now AFK!.") + send = await kirimPesan(message, f"{message.from_user.mention} [{message.from_user.id}] is now AFK!.") await put_cleanmode(message.chat.id, send.id) -@app.on_message(filters.command("afkdel") & ~filters.private) +@app.on_message(filters.command("afkdel", COMMAND_HANDLER) & filters.group) @adminsOnly("can_change_info") async def afk_state(_, message): - usage = "**Usage:**\n/afkdel [ENABLE|DISABLE]" + usage = "**Usage:**\n/afkdel [ENABLE|DISABLE] to enable or disable auto delete message." if len(message.command) == 1: - return await message.reply_text(usage) + return await kirimPesan(message, usage) chat_id = message.chat.id state = message.text.split(None, 1)[1].strip() state = state.lower() if state == "enable": await cleanmode_on(chat_id) - await message.reply_text("Enabled auto delete AFK message.") + await kirimPesan(message, "Enabled auto delete AFK message in this chat.") elif state == "disable": await cleanmode_off(chat_id) - await message.reply_text("Disabled auto delete AFK message.") + await kirimPesan(message, "Disabled auto delete AFK message.") else: - await message.reply_text(usage) + await kirimPesan(message, usage) diff --git a/misskaty/plugins/auto_approve.py b/misskaty/plugins/auto_approve.py index 51a4e76e..c01096d8 100644 --- a/misskaty/plugins/auto_approve.py +++ b/misskaty/plugins/auto_approve.py @@ -13,6 +13,7 @@ from misskaty import app from misskaty.core.decorator.errors import capture_err +# Filters Approve User by bot in channel @YMovieZNew @capture_err @app.on_chat_join_request(filters.chat(-1001686184174)) async def approve_join_chat(c, m): diff --git a/misskaty/plugins/banned.py b/misskaty/plugins/banned.py index ea2f9d9a..c987ce1e 100644 --- a/misskaty/plugins/banned.py +++ b/misskaty/plugins/banned.py @@ -3,6 +3,7 @@ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message from database.users_chats_db import db from misskaty import app +from misskaty.core.message_utils import kirimPesan from misskaty.vars import SUPPORT_CHAT from utils import temp @@ -24,7 +25,7 @@ disabled_group = filters.create(disabled_chat) @app.on_message(filters.private & banned_user & filters.incoming) async def ban_reply(bot, message): ban = await db.get_ban_status(message.from_user.id) - await message.reply(f'Sorry Dude, You are Banned to use Me. \nBan Reason: {ban["ban_reason"]}') + await kirimPesan(message, f'Sorry Dude, You are Banned to use Me. \nBan Reason: {ban["ban_reason"]}') @app.on_message(filters.group & disabled_group & filters.incoming) @@ -32,8 +33,9 @@ async def grp_bd(bot, message): buttons = [[InlineKeyboardButton("Support", url=f"https://t.me/{SUPPORT_CHAT}")]] reply_markup = InlineKeyboardMarkup(buttons) vazha = await db.get_chat(message.chat.id) - k = await message.reply( - text=f"CHAT NOT ALLOWED 🐞\n\nMy admins has restricted me from working here ! If you want to know more about it contact support..\nReason : {vazha['reason']}.", + k = await kirimPesan( + message, + f"CHAT NOT ALLOWED 🐞\n\nMy admins has restricted me from working here ! If you want to know more about it contact support..\nReason : {vazha['reason']}.", reply_markup=reply_markup, ) try: diff --git a/misskaty/plugins/broadcast.py b/misskaty/plugins/broadcast.py index 880f84d1..5bcc82e2 100644 --- a/misskaty/plugins/broadcast.py +++ b/misskaty/plugins/broadcast.py @@ -6,6 +6,7 @@ from pyrogram import filters from database.users_chats_db import db from misskaty import app +from misskaty.core.message_utils import * from misskaty.vars import SUDO from utils import broadcast_messages @@ -14,7 +15,7 @@ from utils import broadcast_messages async def broadcast(bot, message): users = await db.get_all_users() b_msg = message.reply_to_message - sts = await message.reply_text(text="Broadcasting your messages...") + sts = await kirimPesan(message, "Broadcasting your messages...") start_time = time.time() total_users = await db.total_users_count() done = 0 @@ -28,7 +29,7 @@ async def broadcast(bot, message): if pti: success += 1 elif pti is False: - if sh == "Bocked": + if sh == "Blocked": blocked += 1 elif sh == "Deleted": deleted += 1 @@ -37,6 +38,6 @@ async def broadcast(bot, message): done += 1 await asyncio.sleep(2) if not done % 20: - await sts.edit(f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}") + await editPesan(sts, f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}") time_taken = datetime.timedelta(seconds=int(time.time() - start_time)) - await sts.edit(f"Broadcast Completed:\nCompleted in {time_taken} seconds.\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}") + await editPesan(sts, f"Broadcast Completed:\nCompleted in {time_taken} seconds.\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}") diff --git a/misskaty/plugins/bypass.py b/misskaty/plugins/bypass.py index 955da782..2ddbb319 100644 --- a/misskaty/plugins/bypass.py +++ b/misskaty/plugins/bypass.py @@ -15,10 +15,9 @@ from pyrogram.errors import EntitiesTooLong, MessageTooLong from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from misskaty import app +from misskaty.core.message_utils import * from misskaty.core.decorator.errors import capture_err -from misskaty.helper.http import http -from misskaty.helper.human_read import get_readable_file_size -from misskaty.helper.tools import rentry +from misskaty.helper import http, get_readable_file_size, rentry from misskaty.vars import COMMAND_HANDLER LIST_LINK = """ @@ -89,15 +88,15 @@ def wetransfer_bypass(url: str) -> str: @capture_err async def bypass(_, message): if len(message.command) == 1: - return await message.reply(f"Gunakan perintah /{message.command[0]} untuk bypass url") + return await kirimPesan(message, f"Gunakan perintah /{message.command[0]} untuk bypass url") url = message.command[1] urllib.parse.urlparse(url).netloc - msg = await message.reply("Bypassing URL..", quote=True) + msg = await kirimPesan(message, "Bypassing URL..", quote=True) mention = f"**Bypasser:** {message.from_user.mention} ({message.from_user.id})" if re.match(r"https?://(store.kde.org|www.pling.com)\/p\/(\d+)", url): data = await pling_bypass(url) try: - await msg.edit(f"{data}\n\n{mention}") + await editPesan(msg, f"{data}\n\n{mention}") except (MessageTooLong, EntitiesTooLong): result = await rentry(data) markup = InlineKeyboardMarkup( @@ -108,13 +107,14 @@ async def bypass(_, message): ] ] ) - await msg.edit( + await editPesan( + msg, f"{result}\n\nBecause your bypassed url is too long, so your link will be pasted to rentry.\n{mention}", reply_markup=markup, disable_web_page_preview=True, ) elif "we.tl" or "wetransfer.com" in url: data = wetransfer_bypass(url) - await msg.edit(f"{data}\n\n{mention}") + await editPesan(msg, f"{data}\n\n{mention}") else: - await msg.edit("Unsupported URL..") \ No newline at end of file + await editPesan(msg, "Unsupported URL..") \ No newline at end of file diff --git a/misskaty/plugins/chatbot.py b/misskaty/plugins/chatbot_ai.py similarity index 67% rename from misskaty/plugins/chatbot.py rename to misskaty/plugins/chatbot_ai.py index 00a410d2..8d4a5db8 100644 --- a/misskaty/plugins/chatbot.py +++ b/misskaty/plugins/chatbot_ai.py @@ -3,13 +3,14 @@ from pyrogram.errors import MessageNotModified from misskaty import app from misskaty.helper.http import http +from misskaty.core.message_utils import * from misskaty.vars import COMMAND_HANDLER, OPENAI_API @app.on_message(filters.command("ask", COMMAND_HANDLER)) async def chatbot(c, m): if len(m.command) == 1: - return await m.reply(f"Gunakan perintah /{m.command[0]} [pertanyaan] untuk menanyakan pertanyaan menggunakan AI.") + return await kirimPesan(m, f"Gunakan perintah /{m.command[0]} [pertanyaan] untuk menanyakan pertanyaan menggunakan AI.") pertanyaan = m.text.split(" ", maxsplit=1)[1] headers = { "Content-Type": "application/json", @@ -22,11 +23,11 @@ async def chatbot(c, m): "max_tokens": 200, "temperature": 0, } - msg = await m.reply("Wait a moment looking for your answer..") + msg = await kirimPesan(m, "Wait a moment looking for your answer..") try: response = (await http.post("https://api.openai.com/v1/completions", headers=headers, json=json_data)).json() - await msg.edit(response["choices"][0]["text"]) + await editPesan(msg, response["choices"][0]["text"]) except MessageNotModified: pass except Exception: - await msg.edit("Yahh, sorry i can't get your answer.") + await editPesan(msg, "Yahh, sorry i can't get your answer.") diff --git a/misskaty/plugins/detect_afk.py b/misskaty/plugins/detect_afk.py index ce93a984..f32314cc 100644 --- a/misskaty/plugins/detect_afk.py +++ b/misskaty/plugins/detect_afk.py @@ -27,7 +27,7 @@ from utils import put_cleanmode ) async def chat_watcher_func(_, message): if message.sender_chat: - return + return await message.reply("This feature not supported for channel.") userid = message.from_user.id user_name = message.from_user.first_name if message.entities: diff --git a/misskaty/plugins/filters.py b/misskaty/plugins/filters.py index 381d4216..7faf2cd6 100644 --- a/misskaty/plugins/filters.py +++ b/misskaty/plugins/filters.py @@ -25,22 +25,19 @@ import re from pyrogram import filters -from database.filters_db import ( - delete_filter, - get_filter, - get_filters_names, - save_filter, -) +from database.filters_db import (delete_filter, get_filter, get_filters_names, + save_filter) from misskaty import app from misskaty.core.decorator.errors import capture_err from misskaty.core.decorator.permissions import adminsOnly from misskaty.core.keyboard import ikb +from misskaty.core.message_utils import * from misskaty.helper.functions import extract_text_and_keyb __MODULE__ = "Filters" __HELP__ = """/filters To Get All The Filters In The Chat. -/addfilter [FILTER_NAME] To Save A Filter (Can be a sticker or text). -/stopfilter [FILTER_NAME] To Stop A Filter. +/addfilter [FILTER_NAME] : To Save A Filter (Can be a sticker or text). +/stopfilter [FILTER_NAME] : To Stop A Filter. You can use markdown or html to save text too. """ @@ -48,51 +45,51 @@ You can use markdown or html to save text too. @app.on_message(filters.command("addfilter") & ~filters.private) @adminsOnly("can_change_info") -async def save_filters(_, message): - if len(message.command) == 1 or not message.reply_to_message: - return await message.reply_text("**Usage:**\nReply to a text or sticker with /filter [FILTER_NAME] to save it.") - if not message.reply_to_message.text and not message.reply_to_message.sticker: - return await message.reply_text("__**You can only save text or stickers in filters for now.**__") - name = message.text.split(None, 1)[1].strip() +async def save_filters(_, m): + if len(m.command) == 1 or not m.reply_to_message: + return await kirimPesan(m, "**Usage:**\nReply to a text or sticker with /filter [FILTER_NAME] to save it.") + if not m.reply_to_message.text and not m.reply_to_message.sticker: + return await kirimPesan(m, "__**You can only save text or stickers in filters for now.**__") + name = m.text.split(None, 1)[1].strip() if not name: - return await message.reply_text("**Usage:**\n__/filter [FILTER_NAME]__") - chat_id = message.chat.id - _type = "text" if message.reply_to_message.text else "sticker" + return await kirimPesan(m, "**Usage:**\n__/filter [FILTER_NAME]__") + chat_id = m.chat.id + _type = "text" if m.reply_to_message.text else "sticker" _filter = { "type": _type, - "data": message.reply_to_message.text.markdown if _type == "text" else message.reply_to_message.sticker.file_id, + "data": m.reply_to_message.text.markdown if _type == "text" else m.reply_to_message.sticker.file_id, } await save_filter(chat_id, name, _filter) - await message.reply(f"__**Saved filter {name}.**__") + await kirimPesan(m, f"__**Saved filter {name}.**__") @app.on_message(filters.command("filters") & ~filters.private) @capture_err -async def get_filterss(_, message): - _filters = await get_filters_names(message.chat.id) +async def get_filterss(_, m): + _filters = await get_filters_names(m.chat.id) if not _filters: - return await message.reply_text("**No filters in this chat.**") + return await kirimPesan(m, "**No filters in this chat.**") _filters.sort() - msg = f"List of filters in {message.chat.title} - {message.chat.id}\n" + msg = f"List of filters in {m.chat.title} - {m.chat.id}\n" for _filter in _filters: msg += f"**-** `{_filter}`\n" - await message.reply_text(msg) + await kirimPesan(m, msg) @app.on_message(filters.command("stopfilter") & ~filters.private) @adminsOnly("can_change_info") -async def del_filter(_, message): - if len(message.command) < 2: - return await message.reply_text("**Usage:**\n__/stop [FILTER_NAME]__") - name = message.text.split(None, 1)[1].strip() +async def del_filter(_, m): + if len(m.command) < 2: + return await kirimPesan(m, "**Usage:**\n__/stop [FILTER_NAME]__") + name = m.text.split(None, 1)[1].strip() if not name: - return await message.reply_text("**Usage:**\n__/stop [FILTER_NAME]__") - chat_id = message.chat.id + return await kirimPesan(m, "**Usage:**\n__/stop [FILTER_NAME]__") + chat_id = m.chat.id deleted = await delete_filter(chat_id, name) if deleted: - await message.reply_text(f"**Deleted filter {name}.**") + await kirimPesan(m, f"**Deleted filter {name}.**") else: - await message.reply_text("**No such filter.**") + await kirimPesan(m, "**No such filter.**") @app.on_message( diff --git a/misskaty/plugins/genss.py b/misskaty/plugins/genss.py index 6764b6d7..3c55e6e0 100644 --- a/misskaty/plugins/genss.py +++ b/misskaty/plugins/genss.py @@ -15,10 +15,11 @@ from shutil import rmtree from pyrogram import enums, filters from pyrogram.errors import FloodWait -from misskaty import BOT_USERNAME, DL_TASK, app +from misskaty import BOT_USERNAME, app +from misskaty.core.message_utils import * +from misskaty.core.decorator.pyro_cooldown import wait from misskaty.core.decorator.errors import capture_err -from misskaty.helper.ffmpeg_helper import genss_link, take_ss -from misskaty.helper.pyro_progress import progress_for_pyrogram +from misskaty.helper import genss_link, progress_for_pyrogram, take_ss from misskaty.vars import COMMAND_HANDLER LOGGER = getLogger(__name__) @@ -31,21 +32,16 @@ __HELP__ = """" """ -@app.on_message(filters.command(["genss"], COMMAND_HANDLER)) +@app.on_message(filters.command(["genss"], COMMAND_HANDLER) & wait(30)) @capture_err -async def genss(client, message): - replied = message.reply_to_message +async def genss(client, m): + replied = m.reply_to_message if replied is not None: vid = [replied.video, replied.document] media = next((v for v in vid if v is not None), None) if media is None: - return await message.reply("Reply to a Telegram Video or document as video to generate screenshoot!") - process = await message.reply_text("`Processing, please wait..`") - - if DL_TASK.get(message.from_user.id): - return await process.edit("Sorry to avoid flood and error, bot only process one task per user at a time.") - if not DL_TASK.get(message.from_user.id): - DL_TASK[message.from_user.id] = True + return await kirimPesan(m, "Reply to a Telegram Video or document as video to generate screenshoot!") + process = await kirimPesan(m, "`Processing, please wait..`") c_time = time.time() the_real_download_location = await replied.download( @@ -54,40 +50,31 @@ async def genss(client, message): ) if the_real_download_location is not None: try: - await client.edit_message_text( - text=f"File video berhasil didownload dengan path {the_real_download_location}.", - chat_id=message.chat.id, - message_id=process.id, - ) + await editPesan(process, f"File video berhasil didownload dengan path {the_real_download_location}.") await sleep(2) images = await take_ss(the_real_download_location) - await client.edit_message_text( - text="Mencoba mengupload, hasil generate screenshot..", - chat_id=message.chat.id, - message_id=process.id, - ) - await client.send_chat_action(chat_id=message.chat.id, action=enums.ChatAction.UPLOAD_PHOTO) + await editPesan(process, "Mencoba mengupload, hasil generate screenshot..") + await client.send_chat_action(chat_id=m.chat.id, action=enums.ChatAction.UPLOAD_PHOTO) try: await gather( *[ - message.reply_document(images, reply_to_message_id=message.id), - message.reply_photo(images, reply_to_message_id=message.id), + m.reply_document(images, reply_to_message_id=m.id), + m.reply_photo(images, reply_to_message_id=m.id), ] ) except FloodWait as e: await sleep(e.value) await gather( *[ - message.reply_document(images, reply_to_message_id=message.id), - message.reply_photo(images, reply_to_message_id=message.id), + m.reply_document(images, reply_to_message_id=m.id), + m.reply_photo(images, reply_to_message_id=m.id), ] ) - await message.reply( - f"â˜‘ī¸ Uploaded [1] screenshoot.\n\n{message.from_user.first_name} ({message.from_user.id})\n#ī¸âƒŖ #ssgen #id{message.from_user.id}\n\nSS Generate by @{BOT_USERNAME}", - reply_to_message_id=message.id, + await kirimPesan( + m, f"â˜‘ī¸ Uploaded [1] screenshoot.\n\n{m.from_user.first_name} ({m.from_user.id})\n#ī¸âƒŖ #ssgen #id{message.from_user.id}\n\nSS Generate by @{BOT_USERNAME}", + reply_to_message_id=m.id, ) - del DL_TASK[message.from_user.id] await process.delete() try: os.remove(images) @@ -96,46 +83,40 @@ async def genss(client, message): pass except Exception: exc = traceback.format_exc() - await message.reply(f"Gagal generate screenshot.\n\n{exc}") - del DL_TASK[message.from_user.id] + await kirimPesan(m, f"Gagal generate screenshot.\n\n{exc}") try: os.remove(images) os.remove(the_real_download_location) except: pass else: - await message.reply("Reply to a Telegram media to get screenshots from media..") + await kirimPesan(m, "Reply to a Telegram media to get screenshots from media..") @app.on_message(filters.command(["genss_link"], COMMAND_HANDLER)) @capture_err -async def genss_link(client, message): +async def genss_link(client, m): + if len(m.command) == 1: + return await kirimPesan(m, f"Use /{m.command[0]} link to generate screenshot from URL.") try: - link = message.text.split(" ")[1] - if link.startswith("https://file.yasirweb.my.id"): - link = link.replace("https://file.yasirweb.my.id", "https://file.yasiraris.workers.dev") - if link.startswith("https://link.yasirweb.my.id"): - link = link.replace("https://link.yasirweb.my.id", "https://yasirrobot.herokuapp.com") - process = await message.reply_text("`Processing, please wait..`") - tmp_directory_for_each_user = f"./MissKaty_Genss/{str(message.from_user.id)}" + link = m.text.split(" ")[1] + process = await kirimPesan(m, "`Processing, please wait..`") + tmp_directory_for_each_user = f"./MissKaty_Genss/{str(m.from_user.id)}" if not os.path.isdir(tmp_directory_for_each_user): os.makedirs(tmp_directory_for_each_user) images = await genss_link(process, link, tmp_directory_for_each_user, 5, 8) await sleep(2) - await client.edit_message_text( - text="Mencoba mengupload, hasil generate screenshot..", - chat_id=message.chat.id, - message_id=process.id, - ) - await client.send_chat_action(chat_id=message.chat.id, action=enums.ChatAction.UPLOAD_PHOTO) + await editPesan(process, "Mencoba mengupload, hasil generate screenshot..") + await client.send_chat_action(chat_id=m.chat.id, action=enums.ChatAction.UPLOAD_PHOTO) try: - await message.reply_media_group(images, reply_to_message_id=message.id) + await m.reply_media_group(images, reply_to_message_id=m.id) except FloodWait as e: await sleep(e.value) - await message.reply_media_group(images, reply_to_message_id=message.id) - await message.reply( + await m.reply_media_group(images, reply_to_message_id=m.id) + await kirimPesan( + m, f"â˜‘ī¸ Uploaded [8] screenshoot.\n\nGenerated by @{BOT_USERNAME}.", - reply_to_message_id=message.id, + reply_to_message_id=m.id, ) await process.delete() try: @@ -144,7 +125,7 @@ async def genss_link(client, message): pass except Exception: exc = traceback.format_exc() - await message.reply(f"Gagal generate screenshot.\n\n{exc}") + await kirimPesan(m, f"Gagal generate screenshot.\n\n{exc}") try: rmtree(tmp_directory_for_each_user) except: diff --git a/misskaty/plugins/grup_tools.py b/misskaty/plugins/grup_tools.py index 6eec1ab6..f9a43b93 100644 --- a/misskaty/plugins/grup_tools.py +++ b/misskaty/plugins/grup_tools.py @@ -326,7 +326,7 @@ async def kickme(_, message): try: await message.chat.ban_member(message.from_user.id) txt = f"Pengguna {message.from_user.mention} menendang dirinya sendiri. Mungkin dia sedang frustasi 😕" - txt += f"\nAlasan: {reason}" if reason else "" + txt += f"\nAlasan: {reason}" if reason else "-" await message.reply_text(txt) await message.chat.unban_member(message.from_user.id) except RPCError as ef: diff --git a/misskaty/plugins/mediainfo.py b/misskaty/plugins/mediainfo.py index 7afba059..532fd082 100644 --- a/misskaty/plugins/mediainfo.py +++ b/misskaty/plugins/mediainfo.py @@ -12,28 +12,23 @@ import time from os import remove as osremove from pyrogram import filters -from pyrogram.errors import FloodWait from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup -from misskaty import app, DL_TASK -from misskaty.helper.media_helper import post_to_telegraph, runcmd -from misskaty.helper.pyro_progress import progress_for_pyrogram +from misskaty import app +from misskaty.core.message_utils import * +from misskaty.core.decorator.pyro_cooldown import wait +from misskaty.helper import post_to_telegraph, runcmd, progress_for_pyrogram from misskaty.vars import COMMAND_HANDLER from utils import get_file_id -@app.on_message(filters.command(["mediainfo"], COMMAND_HANDLER)) +@app.on_message(filters.command(["mediainfo"], COMMAND_HANDLER) & wait(30)) async def mediainfo(client, message): if message.reply_to_message and message.reply_to_message.media: - process = await message.reply_text("`Sedang memproses, lama waktu tergantung ukuran file kamu...`", quote=True) + process = await kirimPesan(message, "`Sedang memproses, lama waktu tergantung ukuran file kamu...`", quote=True) file_info = get_file_id(message.reply_to_message) if file_info is None: - return await process.edit_text("Balas ke format media yang valid") - - if DL_TASK.get(message.from_user.id): - return await process.edit("Sorry to avoid flood and error, bot only process one task per user at a time.") - if not DL_TASK.get(message.from_user.id): - DL_TASK[message.from_user.id] = 1 + return await editPesan(process, "Balas ke format media yang valid") c_time = time.time() file_path = await message.reply_to_message.download( @@ -54,11 +49,7 @@ async def mediainfo(client, message): text_ = file_info.message_type link = post_to_telegraph(title, body_text) markup = InlineKeyboardMarkup([[InlineKeyboardButton(text=text_, url=link)]]) - try: - await message.reply("â„šī¸ MEDIA INFO", reply_markup=markup, quote=True) - except FloodWait as f: - await asyncio.sleep(f.value) - del DL_TASK[message.from_user.id] + await kirimPesan(message, "â„šī¸ MEDIA INFO", reply_markup=markup, quote=True) await process.delete() try: osremove(file_path) @@ -67,11 +58,11 @@ async def mediainfo(client, message): else: try: link = message.text.split(" ", maxsplit=1)[1] - process = await message.reply_text("`Mohon tunggu sejenak...`") + process = await kirimPesan(message, "`Mohon tunggu sejenak...`") try: output = subprocess.check_output(["mediainfo", f"{link}"]).decode("utf-8") except Exception: - return await process.edit("Sepertinya link yang kamu kirim tidak valid, pastikan direct link dan bisa di download.") + return await editPesan(process, "Sepertinya link yang kamu kirim tidak valid, pastikan direct link dan bisa di download.") title = "MissKaty Bot Mediainfo" body_text = f"""
{output}
@@ -92,4 +83,4 @@ async def mediainfo(client, message): ) await process.delete() except IndexError: - return await message.reply_text("Gunakan command /mediainfo [link], atau reply telegram media dengan /mediainfo.") + return await kirimPesan(message, "Gunakan command /mediainfo [link], atau reply telegram media dengan /mediainfo.") diff --git a/misskaty/plugins/nightmode.py b/misskaty/plugins/nightmode.py index d89530cb..00ac2e15 100644 --- a/misskaty/plugins/nightmode.py +++ b/misskaty/plugins/nightmode.py @@ -190,7 +190,7 @@ async def job_open_ymoviez(): @app.on_callback_query(filters.regex(r"^nightmd$")) -async def _callbackanightmd(c: Client, q: CallbackQuery): +async def callbackanightmd(c: Client, q: CallbackQuery): await q.answer( f"🔖 Hai, Aku {BOT_USERNAME} dibuat menggunakan Framework Pyrogram v{__version__} dan Python 3.10.\n\nMau buat bot seperti ini? Yuuk belajar di @botindonesia\nOwner: @YasirArisM", show_alert=True, diff --git a/misskaty/plugins/ocr.py b/misskaty/plugins/ocr.py index 477c7694..87336620 100644 --- a/misskaty/plugins/ocr.py +++ b/misskaty/plugins/ocr.py @@ -11,6 +11,7 @@ from pyrogram import filters from telegraph import upload_file from misskaty import app +from misskaty.core.message_utils import * from misskaty.core.decorator.errors import capture_err from misskaty.helper.http import http from misskaty.vars import COMMAND_HANDLER @@ -21,15 +22,15 @@ __HELP__ = "/ocr [reply to photo] - Read Text From Image" @app.on_message(filters.command(["ocr"], COMMAND_HANDLER)) @capture_err -async def ocr(_, message): - reply = message.reply_to_message +async def ocr(_, m): + reply = m.reply_to_message if not reply or not reply.photo and not reply.sticker: - return await message.reply_text(f"Reply photo with /{message.command[0]} command") - msg = await message.reply("Reading image...") + return await kirimPesan(m, f"Reply photo with /{m.command[0]} command") + msg = await kirimPesan(m, "Reading image...") try: file_path = await reply.download() if reply.sticker: - file_path = await reply.download(f"ocr{message.from_user.id}.jpg") + file_path = await reply.download(f"ocr_{m.from_user.id}.jpg") response = upload_file(file_path) url = f"https://telegra.ph{response[0]}" req = ( @@ -38,8 +39,8 @@ async def ocr(_, message): follow_redirects=True, ) ).json() - await msg.edit(f"Hasil OCR:\n{req['text']}") + await editPesan(msg, f"Hasil OCR:\n{req['text']}") os.remove(file_path) except Exception as e: - await msg.edit(str(e)) + await editPesan(msg, str(e)) os.remove(file_path) diff --git a/misskaty/plugins/sangmata.py b/misskaty/plugins/sangmata.py index b6d9bd8f..6571d4b9 100644 --- a/misskaty/plugins/sangmata.py +++ b/misskaty/plugins/sangmata.py @@ -1,6 +1,8 @@ -from misskaty import app from pyrogram import filters + from database.sangmata_db import * +from misskaty import app +from misskaty.core.decorator.permissions import adminsOnly from misskaty.vars import COMMAND_HANDLER __MODULE__ = "SangMata" @@ -37,6 +39,7 @@ async def cek_mataa(_, m): @app.on_message( filters.group & filters.command("sangmata_set", COMMAND_HANDLER) & ~filters.bot & ~filters.via_bot ) +@adminsOnly("can_change_info") async def set_mataa(_, m): if len(m.command) == 1: return await m.reply(f"Use /{m.command[0]} on, to enable sangmata. If you want disable, you can use off parameter.") diff --git a/misskaty/plugins/sed.py b/misskaty/plugins/sed.py index 7a40d630..1b1cd01b 100644 --- a/misskaty/plugins/sed.py +++ b/misskaty/plugins/sed.py @@ -6,13 +6,12 @@ import html import regex from pyrogram import filters from pyrogram.errors import MessageEmpty -from pyrogram.types import Message from misskaty import app @app.on_message(filters.regex(r"^s/(.+)?/(.+)?(/.+)?") & filters.reply) -async def sed(c: app, m: Message): +async def sed(c, m): exp = regex.split(r"(?