-
Notifications
You must be signed in to change notification settings - Fork 5
/
dictionary.py
60 lines (53 loc) · 1.81 KB
/
dictionary.py
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""Urban Dictionary
Syntax: .ud Query"""
import asyncurban
from PyDictionary import PyDictionary
from ULTRA import CMD_HELP
from ULTRA.utils import admin_cmd, edit_or_reply, sudo_cmd
@bot.on(admin_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()
hell = dictionary.meaning(word)
output = f"**Word :** __{word}__\n\n"
try:
for a, b in hell.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}")
CMD_HELP.update(
{
"dictionary": "**Plugin :** `dictionary`\
\n\n**Syntax :** `.ud query`\
\n**Usage : **fetches meaning from Urban dictionary\
\n\n**Syntax : **`.meaning query`\
\n**Usage : **Fetches meaning of the given word\
"
}
)