2022-08-26 07:15:53 +00:00
|
|
|
import json
|
|
|
|
from os import sep
|
|
|
|
|
|
|
|
from telegram import Update
|
2022-09-08 01:08:37 +00:00
|
|
|
from telegram.ext import CommandHandler, CallbackContext
|
|
|
|
from telegram.ext import filters
|
2022-08-26 07:15:53 +00:00
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
from core.baseplugin import BasePlugin
|
|
|
|
from core.plugin import Plugin, handler
|
2022-12-01 02:27:27 +00:00
|
|
|
from utils.bot import get_args
|
2022-08-26 07:15:53 +00:00
|
|
|
from utils.decorators.error import error_callable
|
|
|
|
from utils.decorators.restricts import restricts
|
2022-09-08 01:08:37 +00:00
|
|
|
from utils.log import logger
|
2022-08-26 07:15:53 +00:00
|
|
|
|
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
class HilichurlsPlugin(Plugin, BasePlugin):
|
|
|
|
"""丘丘语字典."""
|
2022-08-26 07:15:53 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""加载数据文件.数据整理自 https://wiki.biligame.com/ys By @zhxycn."""
|
|
|
|
with open(f"resources{sep}json{sep}hilichurls_dictionary.json", "r", encoding="utf8") as f:
|
|
|
|
self.hilichurls_dictionary = json.load(f)
|
|
|
|
|
2022-09-08 01:08:37 +00:00
|
|
|
@handler(CommandHandler, command="hilichurls", block=False)
|
2022-08-26 07:15:53 +00:00
|
|
|
@restricts()
|
2022-09-08 01:08:37 +00:00
|
|
|
@error_callable
|
2022-08-26 07:15:53 +00:00
|
|
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
2022-09-08 01:08:37 +00:00
|
|
|
message = update.effective_message
|
2022-08-26 07:15:53 +00:00
|
|
|
user = update.effective_user
|
2022-12-01 02:27:27 +00:00
|
|
|
args = get_args(context)
|
2022-08-26 07:15:53 +00:00
|
|
|
if len(args) >= 1:
|
|
|
|
msg = args[0]
|
|
|
|
else:
|
|
|
|
reply_message = await message.reply_text("请输入要查询的丘丘语。")
|
|
|
|
if filters.ChatType.GROUPS.filter(reply_message):
|
|
|
|
self._add_delete_message_job(context, message.chat_id, message.message_id)
|
|
|
|
self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id)
|
|
|
|
return
|
|
|
|
search = str.casefold(msg) # 忽略大小写以方便查询
|
|
|
|
if search not in self.hilichurls_dictionary:
|
|
|
|
reply_message = await message.reply_text(f"在丘丘语字典中未找到 {msg}。")
|
|
|
|
if filters.ChatType.GROUPS.filter(reply_message):
|
|
|
|
self._add_delete_message_job(context, message.chat_id, message.message_id)
|
|
|
|
self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id)
|
|
|
|
return
|
2022-09-08 01:08:37 +00:00
|
|
|
logger.info(f"用户 {user.full_name}[{user.id}] 查询丘丘语字典命令请求 || 参数 {msg}")
|
2022-08-26 07:15:53 +00:00
|
|
|
result = self.hilichurls_dictionary[f"{search}"]
|
|
|
|
await message.reply_markdown_v2(f"丘丘语: `{search}`\n\n`{result}`")
|