Merge branch 'master' of https://github.com/MaiBot-Plus/MaiMbot-Pro-Max
This commit is contained in:
@@ -3,25 +3,49 @@
|
||||
from typing import List
|
||||
from src.common.database.sqlalchemy_models import MonthlyPlan, get_db_session
|
||||
from src.common.logger import get_logger
|
||||
from src.config.config import global_config # 需要导入全局配置
|
||||
|
||||
logger = get_logger("monthly_plan_db")
|
||||
|
||||
def add_new_plans(plans: List[str], month: str):
|
||||
"""
|
||||
批量添加新生成的月度计划到数据库。
|
||||
批量添加新生成的月度计划到数据库,并确保不超过上限。
|
||||
|
||||
:param plans: 计划内容列表。
|
||||
:param month: 目标月份,格式为 "YYYY-MM"。
|
||||
"""
|
||||
with get_db_session() as session:
|
||||
try:
|
||||
# 1. 获取当前有效计划数量
|
||||
current_plan_count = session.query(MonthlyPlan).filter(
|
||||
MonthlyPlan.target_month == month,
|
||||
MonthlyPlan.is_deleted == False
|
||||
).count()
|
||||
|
||||
# 2. 从配置获取上限
|
||||
max_plans = global_config.monthly_plan_system.max_plans_per_month
|
||||
|
||||
# 3. 计算还能添加多少计划
|
||||
remaining_slots = max_plans - current_plan_count
|
||||
|
||||
if remaining_slots <= 0:
|
||||
logger.info(f"{month} 的月度计划已达到上限 ({max_plans}条),不再添加新计划。")
|
||||
return
|
||||
|
||||
# 4. 截取可以添加的计划
|
||||
plans_to_add = plans[:remaining_slots]
|
||||
|
||||
new_plan_objects = [
|
||||
MonthlyPlan(plan_text=plan, target_month=month)
|
||||
for plan in plans
|
||||
for plan in plans_to_add
|
||||
]
|
||||
session.add_all(new_plan_objects)
|
||||
session.commit()
|
||||
|
||||
logger.info(f"成功向数据库添加了 {len(new_plan_objects)} 条 {month} 的月度计划。")
|
||||
if len(plans) > len(plans_to_add):
|
||||
logger.info(f"由于达到月度计划上限,有 {len(plans) - len(plans_to_add)} 条计划未被添加。")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"添加月度计划时发生错误: {e}")
|
||||
session.rollback()
|
||||
|
||||
@@ -683,6 +683,7 @@ class MonthlyPlanSystemConfig(ValidatedConfigBase):
|
||||
generation_threshold: int = Field(default=10, ge=0, description="启动时,如果当月计划少于此数量,则触发LLM生成")
|
||||
plans_per_generation: int = Field(default=5, ge=1, description="每次调用LLM期望生成的计划数量")
|
||||
deletion_probability_on_use: float = Field(default=0.5, ge=0.0, le=1.0, description="计划被使用后,被删除的概率")
|
||||
max_plans_per_month: int = Field(default=20, ge=1, description="每个月允许存在的最大计划数量")
|
||||
|
||||
|
||||
class ContextGroup(ValidatedConfigBase):
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncio
|
||||
import random
|
||||
from datetime import datetime, time, timedelta
|
||||
from typing import Optional, List, Dict, Any
|
||||
from lunar_python import Lunar
|
||||
from pydantic import BaseModel, ValidationError, validator
|
||||
|
||||
from src.common.database.sqlalchemy_models import Schedule, get_db_session
|
||||
@@ -175,6 +176,18 @@ class ScheduleManager:
|
||||
current_month_str = now.strftime("%Y-%m")
|
||||
weekday = now.strftime("%A")
|
||||
|
||||
# 新增:获取节日信息
|
||||
lunar = Lunar.fromDate(now)
|
||||
festivals = lunar.getFestivals()
|
||||
other_festivals = lunar.getOtherFestivals()
|
||||
all_festivals = festivals + other_festivals
|
||||
|
||||
festival_block = ""
|
||||
if all_festivals:
|
||||
festival_text = "、".join(all_festivals)
|
||||
festival_block = f"**今天也是一个特殊的日子: {festival_text}!请在日程中考虑和庆祝这个节日。**"
|
||||
|
||||
|
||||
# 获取月度计划作为额外参考
|
||||
monthly_plans_block = ""
|
||||
used_plan_ids = []
|
||||
@@ -198,7 +211,7 @@ class ScheduleManager:
|
||||
|
||||
prompt = f"""
|
||||
我,{global_config.bot.nickname},需要为自己规划一份今天({today_str},星期{weekday})的详细日程安排。
|
||||
|
||||
{festival_block}
|
||||
**关于我**:
|
||||
- **核心人设**: {personality}
|
||||
- **具体习惯与兴趣**:
|
||||
|
||||
@@ -19,7 +19,7 @@ from src.common.logger import get_logger
|
||||
from src.plugins.built_in.core_actions.no_reply import NoReplyAction
|
||||
from src.plugins.built_in.core_actions.reply import ReplyAction
|
||||
from src.plugins.built_in.core_actions.emoji import EmojiAction
|
||||
from src.plugins.built_in.core_actions.anti_injector_manager import AntiInjectorStatusCommand, AntiInjectorSkipListCommand
|
||||
from src.plugins.built_in.core_actions.anti_injector_manager import AntiInjectorStatusCommand
|
||||
|
||||
logger = get_logger("core_actions")
|
||||
|
||||
@@ -76,7 +76,6 @@ class CoreActionsPlugin(BasePlugin):
|
||||
components.append((EmojiAction.get_action_info(), EmojiAction))
|
||||
if self.get_config("components.enable_anti_injector_manager", True):
|
||||
components.append((AntiInjectorStatusCommand.get_command_info(), AntiInjectorStatusCommand))
|
||||
components.append((AntiInjectorSkipListCommand.get_command_info(), AntiInjectorSkipListCommand))
|
||||
|
||||
|
||||
return components
|
||||
|
||||
@@ -416,11 +416,13 @@ centralized_config = true # 是否启用插件配置集中化管理
|
||||
# 是否启用本功能
|
||||
enable = true
|
||||
# 启动时,如果当月计划少于此数量,则触发LLM生成
|
||||
generation_threshold = 30
|
||||
generation_threshold = 20
|
||||
# 每次调用LLM期望生成的计划数量
|
||||
plans_per_generation = 5
|
||||
plans_per_generation = 4
|
||||
# 计划被使用后,被删除的概率 (0.0 到 1.0)
|
||||
deletion_probability_on_use = 0.5
|
||||
#每个月允许存在的最大计划数量
|
||||
max_plans_per_month = 30
|
||||
|
||||
[wakeup_system]
|
||||
enable = true #"是否启用唤醒度系统"
|
||||
|
||||
Reference in New Issue
Block a user