Spaces:
Runtime error
Runtime error
File size: 4,972 Bytes
78b07ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
from pyrogram import Client, filters
from pyrogram.types import Message
from . import Config, HelpMenu, custom_handler, db, handler, hellbot, on_message
@on_message(["snip", "note"], allow_stan=True)
async def addsnip(client: Client, message: Message):
if len(message.command) < 2 and not message.reply_to_message:
return await hellbot.delete(
message,
f"Reply to a message with {handler}snip <keyword> to save it as a snip.",
)
keyword = (await hellbot.input(message)).replace("#", "")
hell = await hellbot.edit(message, f"Saving snip `#{keyword}`")
msg = await message.reply_to_message.forward(Config.LOGGER_ID)
await db.set_snip(client.me.id, message.chat.id, keyword.lower(), msg.id)
await hellbot.delete(hell, f"**π ππΎπ π²πππ ππππΎ π²πΊππΎπ½:** `#{keyword}`")
await msg.reply_text(
f"**π ππΎπ π²πππ ππππΎ π²πΊππΎπ½:** `#{keyword}`\n\n**DO NOT DELETE THIS MESSAGE!!!**",
)
@on_message(["rmsnip", "rmallsnip"], allow_stan=True)
async def rmsnip(client: Client, message: Message):
if len(message.command[0]) < 7:
if len(message.command) < 2:
return await hellbot.delete(message, "Give a snip note name to remove.")
keyword = (await hellbot.input(message)).replace("#", "")
hell = await hellbot.edit(message, f"Removing snip `#{keyword}`")
if await db.is_snip(client.me.id, message.chat.id, keyword.lower()):
await db.rm_snip(client.me.id, message.chat.id, keyword.lower())
await hellbot.delete(hell, f"**π π²πππ ππππΎ π±πΎππππΎπ½:** `#{keyword}`")
else:
await hellbot.delete(hell, f"**π π²πππ ππππΎ π½ππΎπ πππ πΎπππππ:** `#{keyword}`")
else:
hell = await hellbot.edit(message, "Removing all filters...")
await db.rm_all_snips(client.me.id, message.chat.id)
await hellbot.delete(hell, "All snips have been removed.")
@on_message(["getsnip", "snips"], allow_stan=True)
async def snips(client: Client, message: Message):
if message.command[0][0] == "g":
if len(message.command) < 2:
return await hellbot.delete(message, "Give a snip note name to get.")
keyword = await hellbot.input(message)
hell = await hellbot.edit(message, f"Getting snip `#{keyword}`")
if await db.is_snip(client.me.id, message.chat.id, keyword.lower()):
data = await db.get_snip(client.me.id, message.chat.id, keyword.lower())
msgid = data["snips"][0]["msgid"]
sent = await client.copy_message(message.chat.id, Config.LOGGER_ID, msgid)
await sent.reply_text(f"**π π²πππ ππππΎ:** `#{keyword}`")
await hell.delete()
else:
await hellbot.delete(hell, f"**π π²πππ ππππΎ π½ππΎπ πππ πΎπππππ:** `#{keyword}`")
else:
hell = await hellbot.edit(message, "Getting all snips...")
snips = await db.get_all_snips(client.me.id, message.chat.id)
if snips:
text = f"**π ππ. ππΏ π²πππ ππππΎ ππ ππππ πΌππΊπ:** `{len(snips)}`\n\n"
for i, snip in enumerate(snips, 1):
text += f"** {'0' if i < 10 else ''}{i}:** `#{snip['keyword']}`\n"
await hell.edit(text)
else:
await hellbot.delete(hell, "No snip note saved in this chat.")
@custom_handler(
filters.incoming & filters.regex(r"^#\s*(.*)$") & filters.text & ~filters.service
)
async def snipHandler(client: Client, message: Message):
keyword = message.text.split("#", 1)[1].lower()
if await db.is_snip(client.me.id, message.chat.id, keyword):
data = await db.get_snip(client.me.id, message.chat.id, keyword)
msgid = data["snips"][0]["msgid"]
reply_to = (
message.reply_to_message.id if message.reply_to_message else message.id
)
await client.copy_message(
message.chat.id, Config.LOGGER_ID, msgid, reply_to_message_id=reply_to
)
HelpMenu("snips").add(
"snip",
"<keyword> <reply to message>",
"Save the replied message as a snip note.",
"snip hello",
"An alias of 'note' is also available.",
).add("rmsnip", "<keyword>", "Remove the snip note.", "rmsnip hello").add(
"rmallsnip", None, "Remove all snip notes.", "rmallsnip"
).add(
"getsnip",
"<keyword>",
"Get the snip note.",
"getsnip hello",
).add(
"snips",
None,
"Get all snip notes.",
"snips",
).info(
"Snips are triggered when # is used before the keyword."
).done()
|