| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- """
- MIT License
- Copyright (c) 2021 TheHamkerCat
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- """
- from re import findall
- from pyrogram import filters
- from wbb import SUDOERS, USERBOT_ID, USERBOT_PREFIX, app, app2, eor
- from wbb.core.decorators.errors import capture_err
- from wbb.core.decorators.permissions import adminsOnly
- from wbb.core.keyboard import ikb
- from wbb.utils.dbfunctions import (delete_note, get_note, get_note_names,
- save_note)
- from wbb.utils.functions import extract_text_and_keyb
- __MODULE__ = "Notes"
- __HELP__ = """/notes To Get All The Notes In The Chat.
- /save [NOTE_NAME] To Save A Note (Can be a sticker or text).
- #NOTE_NAME To Get A Note.
- /delete [NOTE_NAME] To Delete A Note.
- Checkout /markdownhelp to know more about formattings and other syntax.
- """
- @app2.on_message(filters.command("save", prefixes=USERBOT_PREFIX) & SUDOERS)
- @app.on_message(filters.command("save") & ~filters.edited & ~filters.private)
- @adminsOnly("can_change_info")
- async def save_notee(_, message):
- if len(message.command) < 2 or not message.reply_to_message:
- await eor(
- message,
- text="**Usage:**\nReply to a text or sticker with /save [NOTE_NAME] to save it.",
- )
- elif (
- not message.reply_to_message.text
- and not message.reply_to_message.sticker
- ):
- await eor(
- message,
- text="__**You can only save text or stickers in notes.**__",
- )
- else:
- name = message.text.split(None, 1)[1].strip()
- if not name:
- return await eor(message, text="**Usage**\n__/save [NOTE_NAME]__")
- _type = "text" if message.reply_to_message.text else "sticker"
- note = {
- "type": _type,
- "data": message.reply_to_message.text.markdown
- if _type == "text"
- else message.reply_to_message.sticker.file_id,
- }
- prefix = message.text.split()[0][0]
- chat_id = message.chat.id if prefix != USERBOT_PREFIX else USERBOT_ID
- await save_note(chat_id, name, note)
- await eor(message, text=f"__**Saved note {name}.**__")
- @app2.on_message(filters.command("notes", prefixes=USERBOT_PREFIX) & SUDOERS)
- @app.on_message(filters.command("notes") & ~filters.edited & ~filters.private)
- @capture_err
- async def get_notes(_, message):
- prefix = message.text.split()[0][0]
- is_ubot = bool(prefix == USERBOT_PREFIX)
- chat_id = USERBOT_ID if is_ubot else message.chat.id
- _notes = await get_note_names(chat_id)
- if not _notes:
- return await eor(message, text="**No notes in this chat.**")
- _notes.sort()
- msg = f"List of notes in {'USERBOT' if is_ubot else message.chat.title}\n"
- for note in _notes:
- msg += f"**-** `{note}`\n"
- await eor(message, text=msg)
- @app2.on_message(filters.command("get", prefixes=USERBOT_PREFIX) & SUDOERS)
- async def get_one_note_userbot(_, message):
- if len(message.text.split()) < 2:
- return await eor(message, text="Invalid arguments")
- name = message.text.split(None, 1)[1]
- _note = await get_note(USERBOT_ID, name)
- if not _note:
- return await eor(message, text="No such note.")
- if _note["type"] == "text":
- data = _note["data"]
- await eor(
- message,
- text=data,
- disable_web_page_preview=True,
- )
- else:
- await message.reply_sticker(_note["data"])
- @app.on_message(
- filters.regex(r"^#.+") & filters.text & ~filters.edited & ~filters.private
- )
- @capture_err
- async def get_one_note(_, message):
- name = message.text.replace("#", "", 1)
- if not name:
- return
- _note = await get_note(message.chat.id, name)
- if not _note:
- return
- if _note["type"] == "text":
- data = _note["data"]
- keyb = None
- if findall(r"\[.+\,.+\]", data):
- keyboard = extract_text_and_keyb(ikb, data)
- if keyboard:
- data, keyb = keyboard
- await message.reply_text(
- data,
- reply_markup=keyb,
- disable_web_page_preview=True,
- )
- else:
- await message.reply_sticker(_note["data"])
- @app2.on_message(filters.command("delete", prefixes=USERBOT_PREFIX) & SUDOERS)
- @app.on_message(filters.command("delete") & ~filters.edited & ~filters.private)
- @adminsOnly("can_change_info")
- async def del_note(_, message):
- if len(message.command) < 2:
- return await eor(message, text="**Usage**\n__/delete [NOTE_NAME]__")
- name = message.text.split(None, 1)[1].strip()
- if not name:
- return await eor(message, text="**Usage**\n__/delete [NOTE_NAME]__")
- prefix = message.text.split()[0][0]
- is_ubot = bool(prefix == USERBOT_PREFIX)
- chat_id = USERBOT_ID if is_ubot else message.chat.id
- deleted = await delete_note(chat_id, name)
- if deleted:
- await eor(message, text=f"**Deleted note {name} successfully.**")
- else:
- await eor(message, text="**No such note.**")
|