mirror of https://github.com/Mai-with-u/MaiBot.git
feat: 添加夜间模式功能
- 添加夜间模式相关配置项到config.py和模板文件 - 在willing_manager中实现夜间时段回复意愿和概率双重抑制 - 支持自定义夜间时段、衰减因子和跨午夜时间配置 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>pull/195/head
parent
4b4a2916e5
commit
5cba55ae2a
|
|
@ -97,6 +97,13 @@ class BotConfig:
|
||||||
default_factory=lambda: ["表情包", "图片", "回复", "聊天记录"]
|
default_factory=lambda: ["表情包", "图片", "回复", "聊天记录"]
|
||||||
) # 添加新的配置项默认值
|
) # 添加新的配置项默认值
|
||||||
|
|
||||||
|
# 夜间模式配置项
|
||||||
|
night_mode_enable: bool = True # 是否启用夜间模式
|
||||||
|
night_mode_start_hour: int = 0 # 夜间模式开始小时
|
||||||
|
night_mode_end_hour: int = 7 # 夜间模式结束小时
|
||||||
|
night_mode_willing_factor: float = 0.3 # 夜间模式意愿衰减因子
|
||||||
|
night_mode_probability_factor: float = 0.2 # 夜间模式概率衰减因子
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_config_dir() -> str:
|
def get_config_dir() -> str:
|
||||||
"""获取配置文件目录"""
|
"""获取配置文件目录"""
|
||||||
|
|
@ -326,6 +333,15 @@ class BotConfig:
|
||||||
config.enable_advance_output = others_config.get("enable_advance_output", config.enable_advance_output)
|
config.enable_advance_output = others_config.get("enable_advance_output", config.enable_advance_output)
|
||||||
config.enable_kuuki_read = others_config.get("enable_kuuki_read", config.enable_kuuki_read)
|
config.enable_kuuki_read = others_config.get("enable_kuuki_read", config.enable_kuuki_read)
|
||||||
|
|
||||||
|
# 在版本 >= 0.0.6 时才处理夜间模式配置项
|
||||||
|
if config.INNER_VERSION in SpecifierSet(">=0.0.6") and "night_mode" in others_config:
|
||||||
|
night_config = others_config["night_mode"]
|
||||||
|
config.night_mode_enable = night_config.get("enable", config.night_mode_enable)
|
||||||
|
config.night_mode_start_hour = night_config.get("start_hour", config.night_mode_start_hour)
|
||||||
|
config.night_mode_end_hour = night_config.get("end_hour", config.night_mode_end_hour)
|
||||||
|
config.night_mode_willing_factor = night_config.get("willing_factor", config.night_mode_willing_factor)
|
||||||
|
config.night_mode_probability_factor = night_config.get("probability_factor", config.night_mode_probability_factor)
|
||||||
|
|
||||||
# 版本表达式:>=1.0.0,<2.0.0
|
# 版本表达式:>=1.0.0,<2.0.0
|
||||||
# 允许字段:func: method, support: str, notice: str, necessary: bool
|
# 允许字段:func: method, support: str, notice: str, necessary: bool
|
||||||
# 如果使用 notice 字段,在该组配置加载时,会展示该字段对用户的警示
|
# 如果使用 notice 字段,在该组配置加载时,会展示该字段对用户的警示
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from .config import global_config
|
from .config import global_config
|
||||||
|
from datetime import datetime # 用于获取当前时间
|
||||||
|
|
||||||
|
|
||||||
class WillingManager:
|
class WillingManager:
|
||||||
|
|
@ -85,6 +86,25 @@ class WillingManager:
|
||||||
if group_id in config.talk_frequency_down_groups:
|
if group_id in config.talk_frequency_down_groups:
|
||||||
reply_probability = reply_probability / down_frequency_rate
|
reply_probability = reply_probability / down_frequency_rate
|
||||||
|
|
||||||
|
# 【夜间模式】根据配置的时间段大幅降低回复意愿
|
||||||
|
if global_config.night_mode_enable:
|
||||||
|
current_hour = datetime.now().hour
|
||||||
|
start_hour = global_config.night_mode_start_hour
|
||||||
|
end_hour = global_config.night_mode_end_hour
|
||||||
|
|
||||||
|
# 处理跨午夜的情况
|
||||||
|
is_night_time = False
|
||||||
|
if start_hour < end_hour: # 例如:0点到7点
|
||||||
|
is_night_time = start_hour <= current_hour < end_hour
|
||||||
|
else: # 例如:22点到8点(跨午夜)
|
||||||
|
is_night_time = current_hour >= start_hour or current_hour < end_hour
|
||||||
|
|
||||||
|
if is_night_time:
|
||||||
|
logger.debug(f"夜间模式生效({current_hour}时)")
|
||||||
|
# 双重抑制:既降低当前意愿又减少回复概率
|
||||||
|
current_willing *= global_config.night_mode_willing_factor # 意愿衰减
|
||||||
|
reply_probability *= global_config.night_mode_probability_factor # 概率衰减
|
||||||
|
|
||||||
reply_probability = min(reply_probability, 1)
|
reply_probability = min(reply_probability, 1)
|
||||||
|
|
||||||
self.group_reply_willing[group_id] = min(current_willing, 3.0)
|
self.group_reply_willing[group_id] = min(current_willing, 3.0)
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,15 @@ word_replace_rate=0.006 # 整词替换概率
|
||||||
enable_advance_output = true # 是否启用高级输出
|
enable_advance_output = true # 是否启用高级输出
|
||||||
enable_kuuki_read = true # 是否启用读空气功能
|
enable_kuuki_read = true # 是否启用读空气功能
|
||||||
|
|
||||||
|
[others.night_mode] # 夜间模式配置
|
||||||
|
enable = true # 是否启用夜间模式
|
||||||
|
start_hour = 0 # 夜间模式开始时间(小时,0-23)
|
||||||
|
end_hour = 7 # 夜间模式结束时间(小时,0-23)
|
||||||
|
willing_factor = 0.3 # 意愿衰减因子(0-1之间,越小抑制越强)
|
||||||
|
probability_factor = 0.2 # 概率衰减因子(0-1之间,越小抑制越强)
|
||||||
|
# 注:如需设置跨午夜的时间段(如22点到次日8点),
|
||||||
|
# 请设置 start_hour = 22, end_hour = 8
|
||||||
|
|
||||||
[groups]
|
[groups]
|
||||||
talk_allowed = [
|
talk_allowed = [
|
||||||
123,
|
123,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue