Files
limoka/N3rcy/modules/emoji.py
2025-07-11 08:27:20 +00:00

66 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ╔╗╔┌─┐┬─┐┌─┐┬ ┬
# ║║║├┤ ├┬┘│ └┬┘
# ╝╚╝└─┘┴└─└─┘ ┴
# Code is licensed under CC-BY-NC-ND 4.0 unless otherwise specified.
# https://creativecommons.org/licenses/by-nc-nd/4.0/
# You CANNOT edit this file without direct permission from the author.
# You can redistribute this file without any changes.
# meta developer: @nercymods
# scope: hikka_min 1.6.2
# requires: bs4
import requests
from bs4 import BeautifulSoup
from hikkatl.tl.types import Message
from .. import loader, utils
@loader.tds
class EmojiInfo(loader.Module):
"""Module for retrieving information about emojis from emojipedia.org"""
strings = {
"name": "EmojiInfo",
"emoji_not_found": "Emoji not found.",
"error": "Error occurred while retrieving emoji information. Error: ",
}
strings_ru = {
"emoji_not_found": "Эмодзи не найдено.",
"error": "Произошла ошибка при получении информации об эмодзи. Ошибка: ",
}
@loader.command(ru_doc="Получить информацию об эмодзи")
async def emoji(self, message: Message):
"""Retrieve information about an emoji"""
if not (emoji := utils.get_args_raw(message)):
await utils.answer(message, self.strings["emoji_not_found"])
return
try:
url = f"https://emojipedia.org/{emoji}/"
response = await utils.run_sync(requests.get, url)
response.raise_for_status()
soup = BeautifulSoup(response.content, "html.parser")
emoji_name = soup.find('title').text
emoji_description = soup.find('div', {'class': 'HtmlContent_html-content-container__Ow2Bk'}).text
emoji_codepoints = ' '.join(['U+{:X}'.format(ord(char)) for char in emoji])
await utils.answer(
message,
(
f"<b>Name: {utils.escape_html(emoji_name)}</b>\n<b>Description:</b>"
f" {utils.escape_html(emoji_description)}\n<b>Codepoints:</b>"
f" {utils.escape_html(emoji_codepoints)}"
),
)
except Exception as e:
await utils.answer(
message, self.strings("error") + utils.escape_html(str(e))
)