mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2025-12-29 09:44:50 +00:00
"Add auto approve, Add all types for notes and filters, Add mention all, Add some minor fixes"
This commit is contained in:
parent
f1a339fea4
commit
8f2d5942a6
9 changed files with 512 additions and 120 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
@ -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 = ""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
@ -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
|
||||
|
|
|
|||
106
misskaty/plugins/autoapprove.py
Normal file
106
misskaty/plugins/autoapprove.py
Normal file
|
|
@ -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)
|
||||
|
|
@ -24,57 +24,109 @@ SOFTWARE.
|
|||
import re
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
from database.filters_db import (
|
||||
delete_filter,
|
||||
deleteall_filters,
|
||||
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.decorator.permissions import adminsOnly, member_permissions
|
||||
from misskaty.core.keyboard import ikb
|
||||
from misskaty.helper.functions import extract_text_and_keyb
|
||||
from misskaty.helper.functions import extract_text_and_keyb, extract_urls
|
||||
from misskaty.vars import COMMAND_HANDLER
|
||||
|
||||
__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.
|
||||
/filter [FILTER_NAME] To Save A Filter(reply to a message).
|
||||
|
||||
Supported filter types are Text, Animation, Photo, Document, Video, video notes, Audio, Voice.
|
||||
|
||||
To use more words in a filter use.
|
||||
`/filter Hey_there` To filter "Hey there".
|
||||
/stop [FILTER_NAME] To Stop A Filter.
|
||||
/stopall To delete all the filters in a chat (permanently).
|
||||
|
||||
You can use markdown or html to save text too.
|
||||
"""
|
||||
|
||||
|
||||
@app.on_message(filters.command(["addfilter", "filter"]) & ~filters.private)
|
||||
@app.on_message(filters.command(["addfilter", "filter"], COMMAND_HANDLER) & ~filters.private)
|
||||
@adminsOnly("can_change_info")
|
||||
async def save_filters(_, m):
|
||||
if len(m.command) == 1 or not m.reply_to_message:
|
||||
return await m.reply_msg(
|
||||
"**Usage:**\nReply to a text or sticker with /addfilter [FILTER_NAME] to save it.",
|
||||
del_in=6,
|
||||
async def save_filters(_, message):
|
||||
try:
|
||||
if len(message.command) < 2 or not message.reply_to_message:
|
||||
return await message.reply_text(
|
||||
"**Usage:**\nReply to a message with /filter [FILTER_NAME] To set a new filter."
|
||||
)
|
||||
if not m.reply_to_message.text and not m.reply_to_message.sticker:
|
||||
return await m.reply_msg(
|
||||
"__**You can only save text or stickers in filters for now.**__"
|
||||
)
|
||||
name = m.text.split(None, 1)[1].strip()
|
||||
text = message.text.markdown
|
||||
name = text.split(None, 1)[1].strip()
|
||||
if not name:
|
||||
return await m.reply_msg("**Usage:**\n__/addfilter [FILTER_NAME]__", del_in=6)
|
||||
chat_id = m.chat.id
|
||||
_type = "text" if m.reply_to_message.text else "sticker"
|
||||
return await message.reply_text("**Usage:**\n__/filter [FILTER_NAME]__")
|
||||
chat_id = message.chat.id
|
||||
replied_message = message.reply_to_message
|
||||
text = name.split(" ", 1)
|
||||
if len(text) > 1:
|
||||
name = text[0]
|
||||
data = text[1].strip()
|
||||
if replied_message.sticker or replied_message.video_note:
|
||||
data = None
|
||||
else:
|
||||
if replied_message.sticker or replied_message.video_note:
|
||||
data = None
|
||||
elif not replied_message.text and not replied_message.caption:
|
||||
data = None
|
||||
else:
|
||||
data = replied_message.text.markdown if replied_message.text else replied_message.caption.markdown
|
||||
if replied_message.text:
|
||||
_type = "text"
|
||||
file_id = None
|
||||
if replied_message.sticker:
|
||||
_type = "sticker"
|
||||
file_id = replied_message.sticker.file_id
|
||||
if replied_message.animation:
|
||||
_type = "animation"
|
||||
file_id = replied_message.animation.file_id
|
||||
if replied_message.photo:
|
||||
_type = "photo"
|
||||
file_id = replied_message.photo.file_id
|
||||
if replied_message.document:
|
||||
_type = "document"
|
||||
file_id = replied_message.document.file_id
|
||||
if replied_message.video:
|
||||
_type = "video"
|
||||
file_id = replied_message.video.file_id
|
||||
if replied_message.video_note:
|
||||
_type = "video_note"
|
||||
file_id = replied_message.video_note.file_id
|
||||
if replied_message.audio:
|
||||
_type = "audio"
|
||||
file_id = replied_message.audio.file_id
|
||||
if replied_message.voice:
|
||||
_type = "voice"
|
||||
file_id = replied_message.voice.file_id
|
||||
if replied_message.reply_markup and not "~" in data:
|
||||
urls = extract_urls(replied_message.reply_markup)
|
||||
if urls:
|
||||
response = "\n".join([f"{name}=[{text}, {url}]" for name, text, url in urls])
|
||||
data = data + response
|
||||
name = name.replace("_", " ")
|
||||
_filter = {
|
||||
"type": _type,
|
||||
"data": m.reply_to_message.text.markdown
|
||||
if _type == "text"
|
||||
else m.reply_to_message.sticker.file_id,
|
||||
"data": data,
|
||||
"file_id": file_id,
|
||||
}
|
||||
await save_filter(chat_id, name, _filter)
|
||||
await m.reply_msg(f"__**Saved filter {name}.**__")
|
||||
m.stop_propagation()
|
||||
return await message.reply_text(f"__**Saved filter {name}.**__")
|
||||
except UnboundLocalError:
|
||||
return await message.reply_text("**Replied message is inaccessible.\n`Forward the message and try again`**")
|
||||
|
||||
|
||||
@app.on_message(filters.command("filters") & ~filters.private)
|
||||
@app.on_message(filters.command("filters", COMMAND_HANDLER) & ~filters.private)
|
||||
@capture_err
|
||||
async def get_filterss(_, m):
|
||||
_filters = await get_filters_names(m.chat.id)
|
||||
|
|
@ -87,7 +139,7 @@ async def get_filterss(_, m):
|
|||
await m.reply_msg(msg)
|
||||
|
||||
|
||||
@app.on_message(filters.command(["stop", "stopfilter"]) & ~filters.private)
|
||||
@app.on_message(filters.command(["stop", "stopfilter"], COMMAND_HANDLER) & ~filters.private)
|
||||
@adminsOnly("can_change_info")
|
||||
async def del_filter(_, m):
|
||||
if len(m.command) < 2:
|
||||
|
|
@ -120,33 +172,102 @@ async def filters_re(_, message):
|
|||
_filter = await get_filter(chat_id, word)
|
||||
data_type = _filter["type"]
|
||||
data = _filter["data"]
|
||||
if data_type == "text":
|
||||
file_id = _filter["file_id"]
|
||||
keyb = None
|
||||
if data:
|
||||
if re.findall(r"\[.+\,.+\]", data):
|
||||
if keyboard := extract_text_and_keyb(ikb, data):
|
||||
keyboard = extract_text_and_keyb(ikb, data)
|
||||
if keyboard:
|
||||
data, keyb = keyboard
|
||||
replied_message = message.reply_to_message
|
||||
if replied_message:
|
||||
if text.startswith("~"):
|
||||
await message.delete()
|
||||
if replied_message.from_user.id != message.from_user.id:
|
||||
message = replied_message
|
||||
|
||||
if message.reply_to_message:
|
||||
await message.reply_to_message.reply(
|
||||
data,
|
||||
if data_type == "text":
|
||||
await message.reply_text(
|
||||
text=data,
|
||||
reply_markup=keyb,
|
||||
disable_web_page_preview=True,
|
||||
)
|
||||
|
||||
if text.startswith("~"):
|
||||
await message.delete()
|
||||
return
|
||||
|
||||
return await message.reply(
|
||||
data,
|
||||
reply_markup=keyb,
|
||||
quote=True,
|
||||
disable_web_page_preview=True,
|
||||
if data_type == "sticker":
|
||||
await message.reply_sticker(
|
||||
sticker=file_id,
|
||||
)
|
||||
if data_type == "animation":
|
||||
await message.reply_animation(
|
||||
animation=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if data_type == "photo":
|
||||
await message.reply_photo(
|
||||
photo=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if data_type == "document":
|
||||
await message.reply_document(
|
||||
document=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if data_type == "video":
|
||||
await message.reply_video(
|
||||
video=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if data_type == "video_note":
|
||||
await message.reply_video_note(
|
||||
video_note=file_id,
|
||||
)
|
||||
if data_type == "audio":
|
||||
await message.reply_audio(
|
||||
audio=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if data_type == "voice":
|
||||
await message.reply_voice(
|
||||
voice=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if message.reply_to_message:
|
||||
await message.reply_to_message.reply_sticker(data)
|
||||
|
||||
if text.startswith("~"):
|
||||
await message.delete()
|
||||
return
|
||||
await message.reply_sticker(data, quote=True)
|
||||
|
||||
@app.on_message(filters.command("stopall", COMMAND_HANDLER) & ~filters.private)
|
||||
@adminsOnly("can_change_info")
|
||||
async def stop_all(_, message):
|
||||
_filters = await get_filters_names(message.chat.id)
|
||||
if not _filters:
|
||||
await message.reply_text("**No filters in this chat.**")
|
||||
else:
|
||||
keyboard = InlineKeyboardMarkup(
|
||||
[
|
||||
[InlineKeyboardButton("YES, DO IT", callback_data="stop_yes"),
|
||||
InlineKeyboardButton("Cancel", callback_data="stop_no")
|
||||
]
|
||||
]
|
||||
)
|
||||
await message.reply_text("**Are you sure you want to delete all the filters in this chat forever ?.**", reply_markup=keyboard)
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("stop_(.*)"))
|
||||
async def stop_all_cb(_, cb):
|
||||
chat_id = cb.message.chat.id
|
||||
from_user = cb.from_user
|
||||
permissions = await member_permissions(chat_id, from_user.id)
|
||||
permission = "can_change_info"
|
||||
if permission not in permissions:
|
||||
return await cb.answer(f"You don't have the required permission.\n Permission: {permission}", show_alert=True)
|
||||
input = cb.data.split("_", 1)[1]
|
||||
if input == "yes":
|
||||
stoped_all = await deleteall_filters(chat_id)
|
||||
if stoped_all:
|
||||
return await cb.message.edit("**Successfully deleted all filters on this chat.**")
|
||||
if input == "no":
|
||||
await cb.message.reply_to_message.delete()
|
||||
await cb.message.delete()
|
||||
|
|
@ -26,8 +26,8 @@ Give reputation to other people in group.
|
|||
karma_positive_group = 3
|
||||
karma_negative_group = 4
|
||||
|
||||
regex_upvote = r"^(\+|\+\+|\+1|thx|tnx|ty|tq|thank you|thanx|thanks|pro|cool|good|agree|makasih|👍|\+\+ .+)$"
|
||||
regex_downvote = r"^(-|--|-1|not cool|disagree|worst|bad|👎|-- .+)$"
|
||||
regex_upvote = r"^(\++|\+1|thx||tnx|ty|tq|thank you|thanx|thanks|pro|cool|good|agree|makasih|👍|\+\+ .+)$"
|
||||
regex_downvote = r"^(-+|-1|not cool|disagree|worst|bad|👎|-- .+)$"
|
||||
|
||||
n = "\n"
|
||||
w = " "
|
||||
|
|
|
|||
|
|
@ -24,56 +24,107 @@ SOFTWARE.
|
|||
from re import findall
|
||||
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
from database.notes_db import delete_note, get_note, get_note_names, save_note
|
||||
from database.notes_db import delete_note, get_note, get_note_names, save_note, deleteall_notes
|
||||
from misskaty import app
|
||||
from misskaty.vars import COMMAND_HANDLER
|
||||
from misskaty.core.decorator.errors import capture_err
|
||||
from misskaty.core.decorator.permissions import adminsOnly
|
||||
from misskaty.core.decorator.permissions import adminsOnly, member_permissions
|
||||
from misskaty.core.keyboard import ikb
|
||||
from misskaty.helper.functions import extract_text_and_keyb
|
||||
from misskaty.helper.functions import extract_text_and_keyb, extract_urls
|
||||
|
||||
|
||||
__MODULE__ = "Notes"
|
||||
__HELP__ = """/notes To Get All The Notes In The Chat.
|
||||
|
||||
(/save, /addnote) [NOTE_NAME] To Save A Note (Can be a sticker or text).
|
||||
/save [NOTE_NAME] or /addnote [NOTE_NAME] To Save A Note.
|
||||
|
||||
Supported note types are Text, Animation, Photo, Document, Video, video notes, Audio, Voice.
|
||||
|
||||
To change caption of any files use.\n/save [NOTE_NAME] or /addnote [NOTE_NAME] [NEW_CAPTION].
|
||||
|
||||
#NOTE_NAME To Get A Note.
|
||||
|
||||
(/clear, /delnote) [NOTE_NAME] To Delete A Note.
|
||||
/delete [NOTE_NAME] or delnote [NOTE_NAME] To Delete A Note.
|
||||
/deleteall To delete all the notes in a chat (permanently).
|
||||
"""
|
||||
|
||||
|
||||
@app.on_message(filters.command(["addnote", "save"]) & ~filters.private)
|
||||
@app.on_message(filters.command(["addnote", "save"], COMMAND_HANDLER) & ~filters.private)
|
||||
@adminsOnly("can_change_info")
|
||||
async def save_notee(_, message):
|
||||
try:
|
||||
if len(message.command) < 2 or not message.reply_to_message:
|
||||
await message.reply(
|
||||
text="**Usage:**\nReply to a text or sticker with /addnote [NOTE_NAME] to save it.",
|
||||
)
|
||||
|
||||
elif not message.reply_to_message.text and not message.reply_to_message.sticker:
|
||||
await message.reply("__**You can only save text or stickers in notes.**__")
|
||||
await message.reply_msg("**Usage:**\nReply to a message with /save [NOTE_NAME] to save a new note.")
|
||||
else:
|
||||
name = message.text.split(None, 1)[1].strip()
|
||||
text = message.text.markdown
|
||||
name = text.split(None, 1)[1].strip()
|
||||
if not name:
|
||||
return await message.reply("**Usage**\n__/save [NOTE_NAME]__")
|
||||
_type = "text" if message.reply_to_message.text else "sticker"
|
||||
return await message.reply_msg("**Usage**\n__/save [NOTE_NAME]__")
|
||||
replied_message = message.reply_to_message
|
||||
text = name.split(" ", 1)
|
||||
if len(text) > 1:
|
||||
name = text[0]
|
||||
data = text[1].strip()
|
||||
if replied_message.sticker or replied_message.video_note:
|
||||
data = None
|
||||
else:
|
||||
if replied_message.sticker or replied_message.video_note:
|
||||
data = None
|
||||
elif not replied_message.text and not replied_message.caption:
|
||||
data = None
|
||||
else:
|
||||
data = replied_message.text.markdown if replied_message.text else replied_message.caption.markdown
|
||||
if replied_message.text:
|
||||
_type = "text"
|
||||
file_id = None
|
||||
if replied_message.sticker:
|
||||
_type = "sticker"
|
||||
file_id = replied_message.sticker.file_id
|
||||
if replied_message.animation:
|
||||
_type = "animation"
|
||||
file_id = replied_message.animation.file_id
|
||||
if replied_message.photo:
|
||||
_type = "photo"
|
||||
file_id = replied_message.photo.file_id
|
||||
if replied_message.document:
|
||||
_type = "document"
|
||||
file_id = replied_message.document.file_id
|
||||
if replied_message.video:
|
||||
_type = "video"
|
||||
file_id = replied_message.video.file_id
|
||||
if replied_message.video_note:
|
||||
_type = "video_note"
|
||||
file_id = replied_message.video_note.file_id
|
||||
if replied_message.audio:
|
||||
_type = "audio"
|
||||
file_id = replied_message.audio.file_id
|
||||
if replied_message.voice:
|
||||
_type = "voice"
|
||||
file_id = replied_message.voice.file_id
|
||||
if replied_message.reply_markup and not "~" in data:
|
||||
urls = extract_urls(replied_message.reply_markup)
|
||||
if urls:
|
||||
response = "\n".join([f"{name}=[{text}, {url}]" for name, text, url in urls])
|
||||
data = data + response
|
||||
note = {
|
||||
"type": _type,
|
||||
"data": message.reply_to_message.text.markdown
|
||||
if _type == "text"
|
||||
else message.reply_to_message.sticker.file_id,
|
||||
"data": data,
|
||||
"file_id": file_id,
|
||||
}
|
||||
prefix = message.text.split()[0][0]
|
||||
chat_id = message.chat.id
|
||||
await save_note(chat_id, name, note)
|
||||
await message.reply(f"__**Saved note {name}.**__")
|
||||
await message.reply_msg(f"__**Saved note {name}.**__")
|
||||
except UnboundLocalError:
|
||||
return await message.reply_text("**Replied message is inaccessible.\n`Forward the message and try again`**")
|
||||
|
||||
|
||||
@app.on_message(filters.command("notes") & ~filters.private)
|
||||
@app.on_message(filters.command("notes", COMMAND_HANDLER) & ~filters.private)
|
||||
@capture_err
|
||||
async def get_notes(_, message):
|
||||
chat_id = message.chat.id
|
||||
|
||||
_notes = await get_note_names(chat_id)
|
||||
|
||||
if not _notes:
|
||||
|
|
@ -94,34 +145,117 @@ async def get_one_note(_, message):
|
|||
_note = await get_note(message.chat.id, name)
|
||||
if not _note:
|
||||
return
|
||||
if _note["type"] == "text":
|
||||
type = _note["type"]
|
||||
data = _note["data"]
|
||||
file_id = _note["file_id"]
|
||||
keyb = None
|
||||
if data:
|
||||
if findall(r"\[.+\,.+\]", data):
|
||||
if keyboard := extract_text_and_keyb(ikb, data):
|
||||
keyboard = extract_text_and_keyb(ikb, data)
|
||||
if keyboard:
|
||||
data, keyb = keyboard
|
||||
replied_message = message.reply_to_message
|
||||
if replied_message:
|
||||
if replied_message.from_user.id != message.from_user.id:
|
||||
message = replied_message
|
||||
if type == "text":
|
||||
await message.reply_text(
|
||||
data,
|
||||
text=data,
|
||||
reply_markup=keyb,
|
||||
disable_web_page_preview=True,
|
||||
)
|
||||
else:
|
||||
await message.reply_sticker(_note["data"])
|
||||
if type == "sticker":
|
||||
await message.reply_sticker(
|
||||
sticker=file_id,
|
||||
)
|
||||
if type == "animation":
|
||||
await message.reply_animation(
|
||||
animation=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if type == "photo":
|
||||
await message.reply_photo(
|
||||
photo=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if type == "document":
|
||||
await message.reply_document(
|
||||
document=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if type == "video":
|
||||
await message.reply_video(
|
||||
video=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if type == "video_note":
|
||||
await message.reply_video_note(
|
||||
video_note=file_id,
|
||||
)
|
||||
if type == "audio":
|
||||
await message.reply_audio(
|
||||
audio=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
if type == "voice":
|
||||
await message.reply_voice(
|
||||
voice=file_id,
|
||||
caption=data,
|
||||
reply_markup=keyb,
|
||||
)
|
||||
|
||||
|
||||
@app.on_message(filters.command(["delnote", "clear"]) & ~filters.private)
|
||||
@app.on_message(filters.command(["delnote", "clear"], COMMAND_HANDLER) & ~filters.private)
|
||||
@adminsOnly("can_change_info")
|
||||
async def del_note(_, message):
|
||||
if len(message.command) == 1:
|
||||
return await message.reply("**Usage**\n__/delnote [NOTE_NAME]__")
|
||||
if len(message.command) < 2:
|
||||
return await message.reply_msg("**Usage**\n__/delete [NOTE_NAME]__")
|
||||
name = message.text.split(None, 1)[1].strip()
|
||||
if not name:
|
||||
return await message.reply("**Usage**\n__/delnote [NOTE_NAME]__")
|
||||
return await message.reply_msg("**Usage**\n__/delete [NOTE_NAME]__")
|
||||
|
||||
prefix = message.text.split()[0][0]
|
||||
chat_id = message.chat.id
|
||||
|
||||
deleted = await delete_note(chat_id, name)
|
||||
if deleted:
|
||||
await message.reply(f"**Deleted note {name} successfully.**")
|
||||
await message.reply_msg(f"**Deleted note {name} successfully.**")
|
||||
else:
|
||||
await message.reply("**No such note.**")
|
||||
await message.reply_msg("**No such note.**")
|
||||
|
||||
|
||||
@app.on_message(filters.command("deleteall", COMMAND_HANDLER) & ~filters.private)
|
||||
@adminsOnly("can_change_info")
|
||||
async def delete_all(_, message):
|
||||
_notes = await get_note_names(message.chat.id)
|
||||
if not _notes:
|
||||
return await message.reply_text("**No notes in this chat.**")
|
||||
else:
|
||||
keyboard = InlineKeyboardMarkup(
|
||||
[
|
||||
[InlineKeyboardButton("YES, DO IT", callback_data="delete_yes"),
|
||||
InlineKeyboardButton("Cancel", callback_data="delete_no")
|
||||
]
|
||||
]
|
||||
)
|
||||
await message.reply_text("**Are you sure you want to delete all the notes in this chat forever ?.**", reply_markup=keyboard)
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("delete_(.*)"))
|
||||
async def delete_all_cb(_, cb):
|
||||
chat_id = cb.message.chat.id
|
||||
from_user = cb.from_user
|
||||
permissions = await member_permissions(chat_id, from_user.id)
|
||||
permission = "can_change_info"
|
||||
if permission not in permissions:
|
||||
return await cb.answer(f"You don't have the required permission.\n Permission: {permission}", show_alert=True)
|
||||
input = cb.data.split("_", 1)[1]
|
||||
if input == "yes":
|
||||
stoped_all = await deleteall_notes(chat_id)
|
||||
if stoped_all:
|
||||
return await cb.message.edit("**Successfully deleted all notes on this chat.**")
|
||||
Loading…
Reference in a new issue