Files
Ultroid-fork/plugins/words.py
Aditya b0f6d58d77 Ultroid - v0.0.3
* Ultroid - v0.0.3

Full Changelog - https://t.me/TheUltroid/21


Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: Danish <72792730+1Danish-00@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: buddhhu <buddhhu@users.noreply.github.com>
Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com>
Co-authored-by: 1Danish-00 <1Danish-00@users.noreply.github.com>
Co-authored-by: Sρι∂у <68327188+sppidy@users.noreply.github.com>
Co-authored-by: sppidy <sppidy@users.noreply.github.com>
Co-authored-by: Arnab Paryali <arnabxd@pm.me>
Co-authored-by: Programming Error <error@notavailable.live>
Co-authored-by: ArnabXD <ArnabXD@users.noreply.github.com>
Co-authored-by: xditya <xditya@users.noreply.github.com>
Co-authored-by: ProgrammingError <ProgrammingError@users.noreply.github.com>
2021-03-04 23:00:10 +05:30

146 lines
3.9 KiB
Python

# Ultroid - UserBot
# Copyright (C) 2020 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
• `{i}meaning <word>`
Get the meaning of the word.
• `{i}synonym <word>`
Get all synonyms.
• `{i}antonym <word>`
Get all antonyms.
• `{i}ud <word>`
Fetch word defenition from urbandictionary.
"""
import asyncurban
from PyDictionary import PyDictionary
from . import *
dictionary = PyDictionary()
@ultroid_cmd(
pattern="meaning",
)
async def mean(event):
evid = event.message.id
xx = await eor(event, "`Processing...`")
wrd = event.text.split(" ", maxsplit=1)[1]
ok = dictionary.meaning(wrd)
try:
p = ok["Noun"]
except BaseException:
return await xx.edit("Oops! No such word found!!")
x = f"**Word** - `{wrd}`\n\n**Meanings** - \n"
c = 1
for i in p:
x += f"**{c}.** `{i}`\n"
c += 1
if len(x) > 4096:
with io.BytesIO(str.encode(x)) as fle:
fle.name = f"{wrd}-meanings.txt"
await ultroid_bot.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption=f"Meanings of {wrd}",
reply_to=evid,
)
await xx.delete()
else:
await xx.edit(x)
@ultroid_cmd(
pattern="synonym",
)
async def mean(event):
evid = event.message.id
xx = await eor(event, "`Processing...`")
wrd = event.text.split(" ", maxsplit=1)[1]
ok = dictionary.synonym(wrd)
x = f"**Word** - `{wrd}`\n\n**Synonyms** - \n"
c = 1
try:
for i in ok:
x += f"**{c}.** `{i}`\n"
c += 1
if len(x) > 4096:
with io.BytesIO(str.encode(x)) as fle:
fle.name = f"{wrd}-synonyms.txt"
await ultroid_bot.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption=f"Synonyms of {wrd}",
reply_to=evid,
)
await xx.delete()
else:
await xx.edit(x)
except Exception as e:
await xx.edit(f"No synonym found!!\n{str(e)}")
@ultroid_cmd(
pattern="antonym",
)
async def mean(event):
evid = event.message.id
xx = await eor(event, "`Processing...`")
wrd = event.text.split(" ", maxsplit=1)[1]
ok = dictionary.antonym(wrd)
x = f"**Word** - `{wrd}`\n\n**Antonyms** - \n"
c = 1
try:
for i in ok:
x += f"**{c}.** `{i}`\n"
c += 1
if len(x) > 4096:
with io.BytesIO(str.encode(x)) as fle:
fle.name = f"{wrd}-antonyms.txt"
await ultroid_bot.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption=f"Antonyms of {wrd}",
reply_to=evid,
)
await xx.delete()
else:
await xx.edit(x)
except Exception as e:
await xx.edit(f"No antonym found!!\n{str(e)}")
@ultroid_cmd(pattern="ud (.*)")
async def _(event):
xx = await eor(event, "`Processing...`")
word = event.pattern_match.group(1)
if word is None:
return await xx.edit("`No word given!`")
urban = asyncurban.UrbanDictionary()
try:
mean = await urban.get_word(word)
await xx.edit(
f"**Text**: `{mean.word}`\n\n**Meaning**: `{mean.definition}`\n\n**Example**: __{mean.example}__"
)
except asyncurban.WordNotFoundError:
await xx.edit(f"**No result found for** `{word}`")
HELP.update({f"{__name__.split('.')[1]}": f"{__doc__.format(i=HNDLR)}"})