mirror of
https://github.com/PaiGramTeam/PamGram.git
synced 2024-11-22 22:37:21 +00:00
8f424bf0d4
♻️ 重构插件系统 ⚙️ 重写插件 🎨 改进代码结构 📝 完善文档 Co-authored-by: zhxy-CN <admin@owo.cab> Co-authored-by: 洛水居室 <luoshuijs@outlook.com> Co-authored-by: xtaodada <xtao@xtaolink.cn> Co-authored-by: Li Chuangbo <im@chuangbo.li>
49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
import json
|
|
from os import sep
|
|
|
|
from telegram import Update
|
|
from telegram.ext import CommandHandler, CallbackContext
|
|
from telegram.ext import filters
|
|
|
|
from core.baseplugin import BasePlugin
|
|
from core.plugin import Plugin, handler
|
|
from utils.bot import get_all_args
|
|
from utils.decorators.error import error_callable
|
|
from utils.decorators.restricts import restricts
|
|
from utils.log import logger
|
|
|
|
|
|
class HilichurlsPlugin(Plugin, BasePlugin):
|
|
"""丘丘语字典."""
|
|
|
|
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)
|
|
|
|
@handler(CommandHandler, command="hilichurls", block=False)
|
|
@restricts()
|
|
@error_callable
|
|
async def command_start(self, update: Update, context: CallbackContext) -> None:
|
|
message = update.effective_message
|
|
user = update.effective_user
|
|
args = get_all_args(context)
|
|
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
|
|
logger.info(f"用户 {user.full_name}[{user.id}] 查询丘丘语字典命令请求 || 参数 {msg}")
|
|
result = self.hilichurls_dictionary[f"{search}"]
|
|
await message.reply_markdown_v2(f"丘丘语: `{search}`\n\n`{result}`")
|