From 8b968a517726d412dfe0fdda9149254d761a51c3 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 27 Jul 2022 22:43:42 +0800 Subject: [PATCH] =?UTF-8?q?dictionary=20=E6=9F=A5=E8=AF=A2=E8=8B=B1?= =?UTF-8?q?=E8=AF=AD=E5=8D=95=E8=AF=8D=E7=9A=84=E6=84=8F=E6=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dictionary/main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 dictionary/main.py diff --git a/dictionary/main.py b/dictionary/main.py new file mode 100644 index 0000000..4f39e35 --- /dev/null +++ b/dictionary/main.py @@ -0,0 +1,35 @@ +""" PagerMaid Plugin to provide a dictionary lookup. """ + +from pagermaid.listener import listener +from pagermaid.enums import Message +from pagermaid.utils import pip_install, alias_command + +pip_install("PyDictionary") + +from PyDictionary import PyDictionary + +dictionary_data = PyDictionary() + + +@listener(command="dictionary", + parameters="<单词>", + description="查询英语单词的意思") +async def get_word_mean(message: Message): + """ Look up a word in the dictionary. """ + word = message.arguments + if not word: + return await message.edit(f"[dictionary] 使用方法:`,{alias_command('dictionary')} <单词>`") + + result = dictionary_data.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 message.edit(output) + except Exception as e: + await message.edit(f"[dictionary] 无法查询到单词的意思:{e}") + else: + await message.edit("[dictionary] 无法查询到单词的意思")