From 8f4287d0c970c82c435ad7d5e1d9b6473f552eb3 Mon Sep 17 00:00:00 2001 From: code-rgb <62891774+code-rgb@users.noreply.github.com> Date: Mon, 23 Nov 2020 14:14:41 +0530 Subject: [PATCH] added .sticker command to search stickers --- userge/plugins/fun/kang.py | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/userge/plugins/fun/kang.py b/userge/plugins/fun/kang.py index edd11a891..ad998e1cb 100644 --- a/userge/plugins/fun/kang.py +++ b/userge/plugins/fun/kang.py @@ -12,6 +12,8 @@ import os import random +from userge.utils.helper import AioHttp +from bs4 import BeautifulSoup as bs import emoji from PIL import Image from pyrogram.errors import StickersetInvalid, YouBlockedUser @@ -281,3 +283,41 @@ def resize_photo(photo: str) -> io.BytesIO: "Imprisoning this sticker...", "Mr.Steal Your Sticker is stealing this sticker... ", ) + + +# Based on: +# https://github.com/AnimeKaizoku/SaitamaRobot/blob/10291ba0fc27f920e00f49bc61fcd52af0808e14/SaitamaRobot/modules/stickers.py#L42 +@userge.on_cmd( + "sticker", + about={ + "header": "Search Sticker Packs", + "usage": "Reply {tr}sticker or " + "{tr}sticker [text]", + }, +) +async def sticker_search(message: Message): + """search sticker packs""" + reply = message.reply_to_message + query_ = None + if message.input_str: + query_ = message.input_str + elif (reply and reply.from_user): + query_ = reply.from_user.username or reply.from_user.id + + if not query_: + return message.err('reply to a user or provide text to search sticker packs', del_in=3) + + await message.edit(f'šŸ”Ž Searching for sticker packs for "`{query_}`"...') + titlex = f'Sticker Packs For: "{query_}"\n' + sticker_pack = "" + text = await AioHttp.get_text(f"https://combot.org/telegram/stickers?q={query_}") + soup = bs(text[1], 'lxml') + results = soup.find_all("div", {'class': "sticker-pack__header"}) + for pack in results: + if pack.button: + title_ = (pack.find("div", {'class': "sticker-pack__title"})).text + link_ = (pack.a).get('href') + sticker_pack += f"\nā€¢ [{title_}]({link_})" + if not sticker_pack: + sticker_pack = '`āŒ Not Found!`' + await message.edit((titlex + sticker_pack), disable_web_page_preview=True) \ No newline at end of file