forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords.py
More file actions
145 lines (127 loc) · 3.92 KB
/
words.py
File metadata and controls
145 lines (127 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# 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=Var.HNDLR)}"})