Skip to content

Commit

Permalink
"Add auto approve, Add all types for notes and filters, Add mention a…
Browse files Browse the repository at this point in the history
…ll, Add some minor fixes"
  • Loading branch information
yasirarism committed Nov 17, 2023
1 parent f1a339f commit 8f2d594
Show file tree
Hide file tree
Showing 9 changed files with 510 additions and 118 deletions.
4 changes: 4 additions & 0 deletions database/filters_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ async def delete_filter(chat_id: int, name: str) -> bool:
return False


async def deleteall_filters(chat_id: int):
return await filtersdb.delete_one({"chat_id": chat_id})


async def get_filter(chat_id: int, name: str) -> Union[bool, dict]:
name = name.lower().strip()
_filters = await _get_filters(chat_id)
Expand Down
4 changes: 4 additions & 0 deletions database/notes_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ async def save_note(chat_id: int, name: str, note: dict):
await notesdb.update_one(
{"chat_id": chat_id}, {"$set": {"notes": _notes}}, upsert=True
)


async def deleteall_notes(chat_id: int):
return await notesdb.delete_one({"chat_id": chat_id})
12 changes: 12 additions & 0 deletions misskaty/helper/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ def get_urls_from_text(text: str) -> bool:
return [x[0] for x in findall(regex, text)]


def extract_urls(reply_markup):
urls = []
if reply_markup.inline_keyboard:
buttons = reply_markup.inline_keyboard
for i, row in enumerate(buttons):
for j, button in enumerate(row):
if button.url:
name = "\n~\nbutton" if i * len(row) + j + 1 == 1 else f"button{i * len(row) + j + 1}"
urls.append((f"{name}", button.text, button.url))
return urls


async def alpha_to_int(user_id_alphabet: str) -> int:
alphabet = list(ascii_lowercase)[:10]
user_id = ""
Expand Down
9 changes: 9 additions & 0 deletions misskaty/helper/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def paginate_modules(page_n, module_dict, prefix, chat=None):
),
)
]
else:
pairs = pairs[modulo_page * COLUMN_SIZE : COLUMN_SIZE * (modulo_page + 1)] + [
(
EqInlineKeyboardButton(
"Back",
callback_data="{}_home({})".format(prefix, modulo_page),
),
)
]

return pairs

Expand Down
40 changes: 21 additions & 19 deletions misskaty/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,25 @@ async def promoteFunc(client, message, strings):
return await message.reply(strings("invalid_id_uname"))
if not user_id:
return await message.reply_text(strings("user_not_found"))
bot = await client.get_chat_member(message.chat.id, client.me.id)
bot = (await client.get_chat_member(message.chat.id, client.me.id)).privileges
if user_id == client.me.id:
return await message.reply_text(strings("promote_self_err"))
if not bot.privileges.can_promote_members:
return await message.reply_text(strings("no_promote_perm"))
return await message.reply_msg(strings("promote_self_err"))
if not bot:
return await message.reply_msg("I'm not an admin in this chat.")
if not bot.can_promote_members:
return await message.reply_msg(strings("no_promote_perm"))
if message.command[0][0] == "f":
await message.chat.promote_member(
user_id=user_id,
privileges=ChatPrivileges(
can_change_info=bot.privileges.can_change_info,
can_invite_users=bot.privileges.can_invite_users,
can_delete_messages=bot.privileges.can_delete_messages,
can_restrict_members=bot.privileges.can_restrict_members,
can_pin_messages=bot.privileges.can_pin_messages,
can_promote_members=bot.privileges.can_promote_members,
can_manage_chat=bot.privileges.can_manage_chat,
can_manage_video_chats=bot.privileges.can_manage_video_chats,
can_change_info=bot.can_change_info,
can_invite_users=bot.can_invite_users,
can_delete_messages=bot.can_delete_messages,
can_restrict_members=bot.can_restrict_members,
can_pin_messages=bot.can_pin_messages,
can_promote_members=bot.can_promote_members,
can_manage_chat=bot.can_manage_chat,
can_manage_video_chats=bot.can_manage_video_chats,
),
)
return await message.reply_text(
Expand All @@ -436,16 +438,16 @@ async def promoteFunc(client, message, strings):
user_id=user_id,
privileges=ChatPrivileges(
can_change_info=False,
can_invite_users=bot.privileges.can_invite_users,
can_delete_messages=bot.privileges.can_delete_messages,
can_restrict_members=bot.privileges.can_restrict_members,
can_pin_messages=bot.privileges.can_pin_messages,
can_invite_users=bot.can_invite_users,
can_delete_messages=bot.can_delete_messages,
can_restrict_members=bot.can_restrict_members,
can_pin_messages=bot.can_pin_messages,
can_promote_members=False,
can_manage_chat=bot.privileges.can_manage_chat,
can_manage_video_chats=bot.privileges.can_manage_video_chats,
can_manage_chat=bot.can_manage_chat,
can_manage_video_chats=bot.can_manage_video_chats,
),
)
await message.reply_text(strings("normal_promote").format(umention=umention))
await message.reply_msg(strings("normal_promote").format(umention=umention))


# Demote Member
Expand Down
106 changes: 106 additions & 0 deletions misskaty/plugins/autoapprove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from database import dbname

from pyrogram import filters
from pyrogram.types import (
CallbackQuery,
ChatJoinRequest,
InlineKeyboardButton,
InlineKeyboardMarkup,
Message,
)

from misskaty import app
from misskaty.vars import SUDO, COMMAND_HANDLER
from misskaty.core.decorator.permissions import adminsOnly, member_permissions

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)
Loading

0 comments on commit 8f2d594

Please sign in to comment.