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

Commit

Permalink
added .sticker command to search stickers
Browse files Browse the repository at this point in the history
  • Loading branch information
code-rgb committed Nov 23, 2020
1 parent 3022044 commit 8f4287d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions userge/plugins/fun/kang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'<b>Sticker Packs For:</b> "<u>{query_}</u>"\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)

0 comments on commit 8f4287d

Please sign in to comment.