mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
feat✨: Ai
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
from typing import List
|
||||
|
||||
from nonebot import on_message
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_saa import Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import NICKNAME, Config
|
||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
||||
from zhenxun.models.friend_user import FriendUser
|
||||
from zhenxun.models.group_member_info import GroupInfoUser
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.depends import UserName
|
||||
|
||||
from .data_source import get_chat_result, hello, no_result
|
||||
|
||||
__zx_plugin_name__ = "AI"
|
||||
__plugin_usage__ = f"""
|
||||
usage:
|
||||
与{NICKNAME}普普通通的对话吧!
|
||||
"""
|
||||
__plugin_version__ = 0.1
|
||||
__plugin_author__ = "HibiKier"
|
||||
__plugin_settings__ = {
|
||||
"level": 5,
|
||||
"cmd": ["Ai", "ai", "AI", "aI"],
|
||||
}
|
||||
__plugin_configs__ = {
|
||||
"TL_KEY": {"value": [], "help": "图灵Key", "type": List[str]},
|
||||
"ALAPI_AI_CHECK": {
|
||||
"value": False,
|
||||
"help": "是否检测青云客骂娘回复",
|
||||
"default_value": False,
|
||||
"type": bool,
|
||||
},
|
||||
"TEXT_FILTER": {
|
||||
"value": ["鸡", "口交"],
|
||||
"help": "文本过滤器,将敏感词更改为*",
|
||||
"default_value": [],
|
||||
"type": List[str],
|
||||
},
|
||||
}
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="AI",
|
||||
description="屑Ai",
|
||||
usage="""
|
||||
与{NICKNAME}普普通通的对话吧!
|
||||
""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="HibiKier",
|
||||
version="0.1",
|
||||
configs=[
|
||||
RegisterConfig(
|
||||
module="alapi",
|
||||
key="ALAPI_TOKEN",
|
||||
value=None,
|
||||
help="在 https://admin.alapi.cn/user/login 登录后获取token",
|
||||
),
|
||||
RegisterConfig(key="TL_KEY", value=[], help="图灵Key", type=List[str]),
|
||||
RegisterConfig(
|
||||
key="ALAPI_AI_CHECK",
|
||||
value=False,
|
||||
help="是否检测青云客骂娘回复",
|
||||
default_value=False,
|
||||
type=bool,
|
||||
),
|
||||
RegisterConfig(
|
||||
key="TEXT_FILTER",
|
||||
value=["鸡", "口交"],
|
||||
help="文本过滤器,将敏感词更改为*",
|
||||
type=List[str],
|
||||
),
|
||||
],
|
||||
).dict(),
|
||||
)
|
||||
|
||||
|
||||
ai = on_message(rule=to_me(), priority=998)
|
||||
|
||||
|
||||
@ai.handle()
|
||||
async def _(message: UniMsg, session: EventSession, uname: str = UserName()):
|
||||
if not message or message.extract_plain_text() in [
|
||||
"你好啊",
|
||||
"你好",
|
||||
"在吗",
|
||||
"在不在",
|
||||
"您好",
|
||||
"您好啊",
|
||||
"你好",
|
||||
"在",
|
||||
]:
|
||||
await hello().finish()
|
||||
if not session.id1:
|
||||
await Text("用户id不存在...").finish()
|
||||
gid = session.id3 or session.id2
|
||||
if gid:
|
||||
nickname = await GroupInfoUser.get_user_nickname(session.id1, gid)
|
||||
else:
|
||||
nickname = await FriendUser.get_user_nickname(session.id1)
|
||||
if not nickname:
|
||||
nickname = uname
|
||||
result = await get_chat_result(message, session.id1, nickname)
|
||||
logger.info(f"问题:{message} ---- 回答:{result}", "ai", session=session)
|
||||
if result:
|
||||
result = str(result)
|
||||
for t in Config.get_config("ai", "TEXT_FILTER"):
|
||||
result = result.replace(t, "*")
|
||||
await Text(result).finish()
|
||||
else:
|
||||
await no_result().finish()
|
||||
Reference in New Issue
Block a user