MissKatyPyro/misskaty/plugins/autoapprove.py
deepsource-autofix[bot] 2aa93bb4d5
style: format code with isort, Ruff Formatter and Yapf (#300)
* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in f9f107e according to the output
from isort, Ruff Formatter and Yapf.

Details: None

* refactor: autofix issues in 2 files

Resolved issues in the following files with DeepSource Autofix:
1. misskaty/plugins/download_upload.py
2. misskaty/plugins/nightmodev2.py

* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in 1bc1345 according to the output
from isort, Ruff Formatter and Yapf.

Details: https://github.com/yasirarism/MissKatyPyro/pull/300

* refactor: autofix issues in 2 files

Resolved issues in the following files with DeepSource Autofix:
1. misskaty/plugins/dev.py
2. misskaty/plugins/misc_tools.py

* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in 58d2f1a according to the output
from isort, Ruff Formatter and Yapf.

Details: https://github.com/yasirarism/MissKatyPyro/pull/300

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Yasir Aris M <git@yasirdev.my.id>
2024-07-30 11:52:58 +07:00

93 lines
3.1 KiB
Python

from pyrogram import filters
from pyrogram.types import (
CallbackQuery,
ChatJoinRequest,
InlineKeyboardButton,
InlineKeyboardMarkup,
Message,
)
from database import dbname
from misskaty import app
from misskaty.core.decorator.permissions import adminsOnly, member_permissions
from misskaty.vars import COMMAND_HANDLER, SUDO
approvaldb = dbname["autoapprove"]
# For /help menu
__MODULE__ = "Autoapprove"
__HELP__ = """
command: /autoapprove
This module helps to automatically accept chat join request send by a user through invitation link of your group
"""
@app.on_message(filters.command("autoapprove", COMMAND_HANDLER) & filters.group)
@adminsOnly("can_change_info")
async def approval_command(_, message: Message):
chat_id = message.chat.id
if (await approvaldb.count_documents({"chat_id": chat_id})) > 0:
keyboard_OFF = InlineKeyboardMarkup(
[[InlineKeyboardButton("Turn OFF", callback_data="approval_off")]]
)
await message.reply(
"**Autoapproval for this chat: Enabled.**",
reply_markup=keyboard_OFF,
)
else:
keyboard_ON = InlineKeyboardMarkup(
[[InlineKeyboardButton("Turn ON", callback_data="approval_on")]]
)
await message.reply(
"**Autoapproval for this chat: Disabled.**",
reply_markup=keyboard_ON,
)
@app.on_callback_query(filters.regex("approval(.*)"))
async def approval_cb(_, cb: CallbackQuery):
chat_id = cb.message.chat.id
from_user = cb.from_user
permissions = await member_permissions(chat_id, from_user.id)
permission = "can_restrict_members"
if permission not in permissions:
if from_user.id not in SUDO:
return await cb.answer(
f"You don't have the required permission.\n Permission: {permission}",
show_alert=True,
)
command_parts = cb.data.split("_", 1)
option = command_parts[1]
if option == "on":
if await approvaldb.count_documents({"chat_id": chat_id}) == 0:
approvaldb.insert_one({"chat_id": chat_id})
keyboard_off = InlineKeyboardMarkup(
[[InlineKeyboardButton("Turn OFF", callback_data="approval_off")]]
)
await cb.edit_message_text(
"**Autoapproval for this chat: Enabled.**",
reply_markup=keyboard_off,
)
elif option == "off":
if await approvaldb.count_documents({"chat_id": chat_id}) > 0:
approvaldb.delete_one({"chat_id": chat_id})
keyboard_on = InlineKeyboardMarkup(
[[InlineKeyboardButton("Turn ON", callback_data="approval_on")]]
)
await cb.edit_message_text(
"**Autoapproval for this chat: Disabled.**",
reply_markup=keyboard_on,
)
return await cb.answer()
@app.on_chat_join_request(filters.group)
async def accept(_, message: ChatJoinRequest):
chat = message.chat
user = message.from_user
if (await approvaldb.count_documents({"chat_id": chat.id})) > 0:
await app.approve_chat_join_request(chat_id=chat.id, user_id=user.id)