新版本重构了ai模型提供商逻辑,新增MCUNC,阿里云百炼ai提供商,支持语言可配置,优化日志输出格式
This commit is contained in:
21
main.py
21
main.py
@@ -1,6 +1,6 @@
|
||||
from ncatbot.core.notice import NoticeMessage
|
||||
from ncatbot.core import BotClient, Request
|
||||
import logging
|
||||
from model.logger import setup_logger
|
||||
import asyncio
|
||||
from control.group import group
|
||||
from control.private import private
|
||||
@@ -9,6 +9,7 @@ from control.notice import notice
|
||||
import toml
|
||||
|
||||
|
||||
logger = setup_logger()
|
||||
with open("./config.toml", "r", encoding="utf-8") as f:
|
||||
config = toml.load(f)
|
||||
bt_uin = config.get("bot_qq")
|
||||
@@ -25,7 +26,7 @@ api = bot.run_blocking(bt_uin=bt_uin, root=root, ws_uri=ws_uri, web_uri=web_uri,
|
||||
|
||||
@bot.group_event()
|
||||
async def on_group_message(msg):
|
||||
logging.info(f"收到消息:{msg.raw_message},来自{msg.group_id}群聊{msg.user_id}用户")
|
||||
logger.info(f"收到消息:{msg.raw_message},来自{msg.group_id}群聊{msg.user_id}用户")
|
||||
if msg.user_id == 2854196310: # qq管家,防止刷屏。bot大战请看
|
||||
pass
|
||||
else:
|
||||
@@ -34,12 +35,12 @@ async def on_group_message(msg):
|
||||
if return_message is None:
|
||||
return
|
||||
else:
|
||||
logging.info(f"返回消息:{return_message}")
|
||||
logger.info(f"返回消息:{return_message}")
|
||||
await bot.api.post_group_msg(group_id=msg.group_id, text=return_message, reply=msg.message_id)
|
||||
|
||||
@bot.private_event()
|
||||
async def on_private_message(msg):
|
||||
logging.info(f"收到消息:{msg.raw_message},来自{msg.user_id}用户")
|
||||
logger.info(f"收到消息:{msg.raw_message},来自{msg.user_id}用户")
|
||||
if msg.user_id == 2854196310: # qq管家,防止刷屏。
|
||||
pass
|
||||
else:
|
||||
@@ -48,33 +49,33 @@ async def on_private_message(msg):
|
||||
if return_message is None:
|
||||
return
|
||||
else:
|
||||
logging.info(f"返回消息:{return_message}")
|
||||
logger.info(f"返回消息:{return_message}")
|
||||
await bot.api.post_private_msg(user_id=msg.user_id, text=return_message, reply=msg.message_id)
|
||||
|
||||
|
||||
@bot.request_event()
|
||||
async def on_request_event(msg: Request):
|
||||
logging.info(f"收到request事件:{msg.request_type},来自{msg.group_id}群聊,{msg.user_id}用户,验证消息:{msg.comment}")
|
||||
logger.info(f"收到request事件:{msg.request_type},来自{msg.group_id}群聊,{msg.user_id}用户,验证消息:{msg.comment}")
|
||||
ctrl = request(msg)
|
||||
accept_friend_application = ctrl.main()
|
||||
if accept_friend_application is True:
|
||||
await msg.reply(True, comment="请求已通过")
|
||||
logging.info("请求已通过")
|
||||
logger.info("请求已通过")
|
||||
else:
|
||||
await msg.reply(False, comment="请求被拒绝")
|
||||
logging.info("请求被拒绝")
|
||||
logger.info("请求被拒绝")
|
||||
|
||||
|
||||
|
||||
@bot.notice_event()
|
||||
async def on_notice_event(msg: NoticeMessage):
|
||||
logging.info(f"收到notice事件:{msg['notice_type']},来自{msg['user_id']}用户")
|
||||
logger.info(f"收到notice事件:{msg['notice_type']},来自{msg['user_id']}用户")
|
||||
ctrl = notice(msg)
|
||||
return_message = ctrl.main()
|
||||
if return_message is None:
|
||||
return
|
||||
else:
|
||||
logging.info(f"返回消息:{return_message}")
|
||||
logger.info(f"返回消息:{return_message}")
|
||||
await bot.api.post_group_msg(group_id=msg["group_id"], text=return_message)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user