feat: 更新了插件商店部分功能
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
import json
|
||||
import locale
|
||||
import os
|
||||
from typing import Any
|
||||
from typing_extensions import Any
|
||||
|
||||
import nonebot
|
||||
|
||||
|
@ -74,15 +74,15 @@ async def send_markdown(markdown: str, bot: T_Bot, *, message_type: str = None,
|
||||
|
||||
|
||||
def button(name: str, cmd: str, reply: bool = False, enter: bool = True) -> str:
|
||||
"""生成点击按钮的链接
|
||||
"""生成点击按钮
|
||||
Args:
|
||||
name:
|
||||
cmd:
|
||||
name: 按钮显示内容
|
||||
cmd: 发送的命令,已在函数内url编码,不需要再次编码
|
||||
reply: 是否以回复的方式发送消息
|
||||
enter: 自动发送消息则为True
|
||||
enter: 自动发送消息则为True,否则填充到输入框
|
||||
|
||||
Returns:
|
||||
markdown格式的链接
|
||||
markdown格式的可点击回调按钮
|
||||
|
||||
"""
|
||||
return f"[{name}](mqqapi://aio/inlinecmd?command={encode_url(cmd)}&reply={str(reply).lower()}&enter={str(enter).lower()})"
|
||||
|
@ -2,11 +2,12 @@ import os
|
||||
|
||||
import nonebot
|
||||
import yaml
|
||||
from typing_extensions import Any
|
||||
|
||||
from src.utils.data import LiteModel
|
||||
|
||||
_resource_data = {}
|
||||
_loaded_resource_packs = [] # 按照加载顺序排序
|
||||
_loaded_resource_packs = [] # 按照加载顺序排序
|
||||
|
||||
|
||||
class ResourceMetadata(LiteModel):
|
||||
@ -41,3 +42,14 @@ def load_resource_from_dir(path: str):
|
||||
from src.utils.language import load_from_dir
|
||||
load_from_dir(os.path.join(path, "lang"))
|
||||
_loaded_resource_packs.append(ResourceMetadata(**metadata))
|
||||
|
||||
|
||||
def get_res(path: str, default: Any = None) -> str | Any:
|
||||
"""
|
||||
获取资源包中的文件
|
||||
Args:
|
||||
default: 默认
|
||||
path: 文件相对路径
|
||||
Returns: 文件绝对路径
|
||||
"""
|
||||
return _resource_data.get(path, default)
|
||||
|
@ -49,3 +49,26 @@ def de_escape(text: str) -> str:
|
||||
|
||||
def encode_url(text: str) -> str:
|
||||
return quote(text, safe="")
|
||||
|
||||
|
||||
def keywords_in_text(keywords: list[str], text: str, all_matched: bool) -> bool:
|
||||
"""
|
||||
检查关键词是否在文本中
|
||||
Args:
|
||||
keywords: 关键词列表
|
||||
text: 文本
|
||||
all_matched: 是否需要全部匹配
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if all_matched:
|
||||
for keyword in keywords:
|
||||
if keyword not in text:
|
||||
return False
|
||||
return True
|
||||
else:
|
||||
for keyword in keywords:
|
||||
if keyword in text:
|
||||
return True
|
||||
return False
|
||||
|
Reference in New Issue
Block a user