Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
Added multi message support in quote
Browse files Browse the repository at this point in the history
Note !!
 .quote renamed to .q
  • Loading branch information
code-rgb authored Nov 19, 2020
1 parent 1b3d657 commit b3bb6d1
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions userge/plugins/fun/quote.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.


import asyncio

from pyrogram.errors.exceptions.bad_request_400 import YouBlockedUser
from pyrogram.errors import YouBlockedUser

from userge import Message, userge


@userge.on_cmd(
"quote",
about={"header": "Quote a message", "usage": "{tr}quote [text or reply to msg]"},
"q",
about={
"header": "Quote a message", "usage": "{tr}q [text or reply to msg]",
"flags": {"-l": "limit, for multiple messages"},
"usage": "Reply {tr}q -l[message limit]",
"examples": [
"{tr}q"
"{tr}q -l3"
],
},
allow_via_bot=False,
del_pre=True
)
async def quotecmd(message: Message):
"""quotecmd"""
asyncio.get_event_loop().create_task(message.delete())
args = message.input_str
quote_list = []
replied = message.reply_to_message
if replied and 'l' in message.flags and not message.filtered_input_str:
args = ""
limit = message.flags.get('l', 1)
if limit.isdigit():
limit = int(limit)
else:
return await message.err('give valid no. of message to quote', del_in=3)
num = min(limit, 20)
async for msg in userge.iter_history(message.chat.id, limit=num, offset_id=replied.message_id, reverse=True):
if msg.message_id != message.message_id:
quote_list.append(msg.message_id)
else:
args = message.input_str
quote_list.append(replied.message_id)
asyncio.get_event_loop().create_task(message.delete())

async with userge.conversation("QuotLyBot") as conv:
try:
if replied and not args:
await conv.forward_message(replied)
if quote_list and not args:
await userge.forward_messages("QuotLyBot", message.chat.id, quote_list)
else:
if not args:
await message.err("input not found!")
Expand All @@ -36,13 +54,22 @@ async def quotecmd(message: Message):
await message.edit("first **unblock** @QuotLyBot")
return
quote = await conv.get_response(mark_read=True)
if not quote.sticker:
if not (quote.sticker or quote.document):
await message.err("something went wrong!")
else:
message_id = replied.message_id if replied else None
await userge.send_sticker(
chat_id=message.chat.id,
sticker=quote.sticker.file_id,
file_ref=quote.sticker.file_ref,
reply_to_message_id=message_id,
)
if quote.sticker:
await userge.send_sticker(
chat_id=message.chat.id,
sticker=quote.sticker.file_id,
file_ref=quote.sticker.file_ref,
reply_to_message_id=message_id,
)
else:
await userge.send_document(
chat_id=message.chat.id,
document=quote.document.file_id,
file_ref=quote.document.file_ref,
reply_to_message_id=message_id,
)

0 comments on commit b3bb6d1

Please sign in to comment.