# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀ # █▀█ █ █ █ █▀█ █▀▄ █ # © Copyright 2022 # https://t.me/hikariatama # # 🔒 Licensed under the GNU AGPLv3 # 🌐 https://www.gnu.org/licenses/agpl-3.0.html # meta pic: https://static.dan.tatar/dictionary_icon.png # meta banner: https://mods.hikariatama.ru/badges/dictionary.jpg # meta developer: @hikarimods # requires: aiohttp urllib bs4 # scope: inline # scope: hikka_only # scope: hikka_min 1.2.10 import logging import re from urllib.parse import quote_plus import aiohttp from bs4 import BeautifulSoup from telethon.tl.types import Message from .. import loader, utils logging.getLogger("charset_normalizer").setLevel(logging.ERROR) HEADERS = { "accept": "text/html", "user-agent": "Hikka userbot", } @loader.tds class UrbanDictionaryMod(loader.Module): """Search for words meaning in urban dictionary""" strings = { "name": "UrbanDictionary", "no_args": "🚫 Specify term to find the definition for", "err": "🧞‍♂️ I don't know about term {}", "no_page": "🚫 Can't switch to that page", "meaning": "🧞‍♂️ {}:\n\n{}", } strings_ru = { "no_args": "🚫 Укажи, для какого слова искать определение", "err": "🧞‍♂️ Я не знаю, что значит {}", "no_page": "🚫 Нельзя переключиться на эту страницу", "meaning": "🧞‍♂️ {}:\n\n{}", "_cmd_doc_mean": "<слова> - Найти определение слова в UrbanDictionary", "_cls_doc": "Ищет определения слов в UrbanDictionary", } strings_de = { "no_args": "🚫 Gib ein Wort ein, um dessen Bedeutung zu finden", "err": "🧞‍♂️ Ich weiß nicht, was {} bedeutet", "no_page": "🚫 Du kannst nicht zu dieser Seite wechseln", "meaning": "🧞‍♂️ {}:\n\n{}", "_cmd_doc_mean": " - Finde die Bedeutung eines Wortes in UrbanDictionary", "_cls_doc": "Sucht nach Bedeutungen von Wörtern in UrbanDictionary", } strings_hi = { "no_args": "🚫 किस शब्द के लिए परिभाषा ढूंढने के लिए निर्दिष्ट करें", "err": "🧞‍♂️ मैं नहीं जानता है कि {} क्या मतलब है", "no_page": "🚫 आप इस पृष्ठ पर नहीं जा सकते", "meaning": "🧞‍♂️ {}:\n\n{}", "_cmd_doc_mean": "<शब्द> - उर्बन डिक्शनरी में शब्द का अर्थ ढूंढें", "_cls_doc": "उर्बन डिक्शनरी में शब्दों के अर्थ ढूंढता है", } strings_tr = { "no_args": "🚫 Bir kelimenin anlamını bulmak için belirtin", "err": "🧞‍♂️ Bilmiyorum {} ne demek", "no_page": "🚫 Bu sayfaya geçemezsiniz", "meaning": "🧞‍♂️ {}:\n\n{}", "_cmd_doc_mean": " - UrbanDictionary'de bir kelimenin anlamını bulun", "_cls_doc": "UrbanDictionary'de kelimelerin anlamlarını arar", } async def scrape(self, term: str) -> str: term = "".join( [ i.lower() for i in term if i.lower() in "абвгдежзийклмнопрстуфхцчшщъыьэюяabcdefghijklmnopqrstuvwxyz " ] ) endpoint = "https://www.urbandictionary.com/define.php?term={}" url = endpoint.format(quote_plus(term.lower())) async with aiohttp.ClientSession() as session: async with session.request("GET", url, headers=HEADERS) as resp: html = await resp.text() soup = BeautifulSoup(re.sub(r"", "♠️", html), "html.parser") return [ definition.get_text().replace("♠️", "\n") for definition in soup.find_all("div", class_="meaning") ] async def meancmd(self, message: Message): """ - Find definition of the word in urban dictionary""" args = utils.get_args_raw(message) if not args: await utils.answer(message, self.strings("no_args")) return means = await self.scrape(args) if not means: await utils.answer(message, self.strings("err").format(args)) return await self.inline.list( message=message, strings=[self.strings("meaning").format(args, mean) for mean in means], )