Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
words.py116 linesDownload Raw Back to plugins
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available -9 10• `{i}meaning <word>`11    Get the meaning of the word.12 13• `{i}synonym <word>`14    Get all synonyms.15 16• `{i}antonym <word>`17    Get all antonyms.18 19• `{i}ud <word>`20    Fetch word defenition from urbandictionary.21"""22import io23 24from pyUltroid.fns.misc import get_synonyms_or_antonyms25from pyUltroid.fns.tools import async_searcher26 27from . import get_string, ultroid_cmd28 29 30@ultroid_cmd(pattern="meaning( (.*)|$)", manager=True)31async def mean(event):32    wrd = event.pattern_match.group(1).strip()33    if not wrd:34        return await event.eor(get_string("wrd_4"))35    url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{wrd}"36    out = await async_searcher(url, re_json=True)37    try:38        return await event.eor(f'**{out["title"]}**')39    except (KeyError, TypeError):40        pass41    defi = out[0]["meanings"][0]["definitions"][0]42    ex = defi["example"] if defi.get("example") else "None"43    text = get_string("wrd_1").format(wrd, defi["definition"], ex)44    if defi.get("synonyms"):45        text += (46            f"\n\n• **{get_string('wrd_5')} :**"47            + "".join(f" {a}," for a in defi["synonyms"])[:-1][:10]48        )49    if defi.get("antonyms"):50        text += (51            f"\n\n**{get_string('wrd_6')} :**"52            + "".join(f" {a}," for a in defi["antonyms"])[:-1][:10]53        )54    if len(text) > 4096:55        with io.BytesIO(str.encode(text)) as fle:56            fle.name = f"{wrd}-meanings.txt"57            await event.reply(58                file=fle,59                force_document=True,60                caption=f"Meanings of {wrd}",61            )62            await event.delete()63    else:64        await event.eor(text)65 66 67@ultroid_cmd(68    pattern="(syno|anto)nym",69)70async def mean(event):71    task = event.pattern_match.group(1) + "nyms"72    try:73        wrd = event.text.split(maxsplit=1)[1]74    except IndexError:75        return await event.eor("Give Something to search..")76    try:77        ok = await get_synonyms_or_antonyms(wrd, task)78        x = get_string("wrd_2" if task == "synonyms" else "wrd_3").format(wrd)79        for c, i in enumerate(ok, start=1):80            x += f"**{c}.** `{i}`\n"81        if len(x) > 4096:82            with io.BytesIO(str.encode(x)) as fle:83                fle.name = f"{wrd}-{task}.txt"84                await event.client.send_file(85                    event.chat_id,86                    fle,87                    force_document=True,88                    allow_cache=False,89                    caption=f"{task} of {wrd}",90                    reply_to=event.reply_to_msg_id,91                )92                await event.delete()93        else:94            await event.eor(x)95    except Exception as e:96        await event.eor(97            get_string("wrd_7" if task == "synonyms" else "wrd_8").format(e)98        )99 100 101@ultroid_cmd(pattern="ud (.*)")102async def _(event):103    word = event.pattern_match.group(1).strip()104    if not word:105        return await event.eor(get_string("autopic_1"))106    out = await async_searcher(107        "http://api.urbandictionary.com/v0/define", params={"term": word}, re_json=True108    )109    try:110        out = out["list"][0]111    except IndexError:112        return await event.eor(get_string("autopic_2").format(word))113    await event.eor(114        get_string("wrd_1").format(out["word"], out["definition"], out["example"]),115    )116