-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdictionary
48 lines (42 loc) · 1.41 KB
/
dictionary
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
import asyncurban
from PyDictionary import PyDictionary
from . import *
@bot.on(d3vil_cmd(pattern="ud (.*)"))
@bot.on(sudo_cmd(pattern="ud (.*)", allow_sudo=True))
async def _(event):
if event.fwd_from:
return
word = event.pattern_match.group(1)
urban = asyncurban.UrbanDictionary()
try:
mean = await urban.get_word(word)
await edit_or_reply(
event,
"Text: **{}**\n\nMeaning: **{}**\n\nExample: __{}__".format(
mean.word, mean.definition, mean.example
),
)
except asyncurban.WordNotFoundError:
await edit_or_reply(event, "No result found for **" + word + "**")
@bot.on(admin_cmd(pattern="meaning (.*)"))
@bot.on(sudo_cmd(pattern="meaning (.*)", allow_sudo=True))
async def _(event):
if event.fwd_from:
return
word = event.pattern_match.group(1)
dictionary = PyDictionary()
d3vil = dictionary.meaning(word)
output = f"**Word :** __{word}__\n\n"
try:
for a, b in d3vil.items():
output += f"**{a}**\n"
for i in b:
output += f"☞__{i}__\n"
await edit_or_reply(event, output)
except Exception:
await edit_or_reply(event, f"Couldn't fetch meaning of {word}")
CmdHelp("dictionary").add_command(
'ud', 'query', 'fetches meaning from Urban Dictionary'
).add_command(
'meaning', 'query', 'Fetches meaning of the given word'
).add()