mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-21 19:18:17 +00:00
dictionary 查询英语单词/俚语的意思
This commit is contained in:
parent
8729770e47
commit
c16a4c52c3
69
dictionary.py
Normal file
69
dictionary.py
Normal file
@ -0,0 +1,69 @@
|
||||
""" PagerMaid Plugin to provide a dictionary lookup. """
|
||||
|
||||
from pagermaid import version
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.utils import alias_command, pip_install, obtain_message, client
|
||||
from telethon.events.newmessage import NewMessage
|
||||
|
||||
pip_install("PyDictionary")
|
||||
|
||||
from PyDictionary import PyDictionary
|
||||
|
||||
dictionary = PyDictionary()
|
||||
|
||||
|
||||
@listener(is_plugin=True, outgoing=True, command=alias_command("dictionary"),
|
||||
description="查询英语单词的意思")
|
||||
async def get_word_mean(context: NewMessage.Event) -> None:
|
||||
""" Look up a word in the dictionary. """
|
||||
try:
|
||||
word = await obtain_message(context)
|
||||
except ValueError:
|
||||
await context.edit(f"[dictionary] 使用方法:`-{alias_command('dictionary')} <单词>`")
|
||||
return
|
||||
|
||||
result = dictionary.meaning(word)
|
||||
output = f"**Word :** __{word}__\n\n"
|
||||
if result:
|
||||
try:
|
||||
for a, b in result.items():
|
||||
output += f"**{a}**\n"
|
||||
for i in b:
|
||||
output += f"☞__{i}__\n"
|
||||
await context.edit(output)
|
||||
except Exception:
|
||||
await context.edit("[dictionary] 无法查询到单词的意思")
|
||||
else:
|
||||
await context.edit("[dictionary] 无法查询到单词的意思")
|
||||
|
||||
|
||||
@listener(is_plugin=True, outgoing=True, command=alias_command("urbandictionary"),
|
||||
description="解释英语俚语词汇")
|
||||
async def get_urban_mean(context: NewMessage.Event) -> None:
|
||||
""" To fetch meaning of the given word from urban dictionary. """
|
||||
try:
|
||||
word = await obtain_message(context)
|
||||
except ValueError:
|
||||
await context.edit(f"[urbandictionary] 使用方法:`-{alias_command('urbandictionary')} <单词>`")
|
||||
return
|
||||
|
||||
response = await client.get(f"https://api.urbandictionary.com/v0/define?term={word}")
|
||||
try:
|
||||
response = response.json()
|
||||
except:
|
||||
await context.edit("[urbandictionary] API 接口无法访问")
|
||||
return
|
||||
|
||||
if len(response["list"]) == 0:
|
||||
await context.edit("[urbandictionary] 无法查询到单词的意思")
|
||||
return
|
||||
|
||||
word = response["list"][0]["word"]
|
||||
definition = response["list"][0]["definition"]
|
||||
example = response["list"][0]["example"]
|
||||
result = f"**Word :** __{word}__\n\n" \
|
||||
f"**Meaning:**\n" \
|
||||
f"`{definition}`\n\n" \
|
||||
f"**Example:**\n" \
|
||||
f"`{example}`"
|
||||
await context.edit(result)
|
10
list.json
10
list.json
@ -879,6 +879,16 @@
|
||||
"supported": true,
|
||||
"des-short": "凌晨自动备份。",
|
||||
"des": "凌晨自动备份数据文件。"
|
||||
},
|
||||
{
|
||||
"name": "dictionary",
|
||||
"version": "1.00",
|
||||
"section": "chat",
|
||||
"maintainer": "xtaodada",
|
||||
"size": "2.4 kb",
|
||||
"supported": true,
|
||||
"des-short": "查询英语单词/俚语的意思。",
|
||||
"des": "查询英语单词/俚语的意思。\n指令:-dictionary -urbandictionary"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user