🐛 修复原神语音合成容易误触以及ck达到30次上限时报错的问题

This commit is contained in:
CMHopeSunshine 2022-08-31 22:46:11 +08:00
parent 23a953190e
commit 1bbfe1329e
2 changed files with 20 additions and 8 deletions

View File

@ -2,7 +2,9 @@ from typing import Union
from nonebot import on_regex
from nonebot.plugin import PluginMetadata
from nonebot.params import RegexDict
from nonebot.rule import Rule
from nonebot.adapters.onebot.v11 import GroupMessageEvent, PrivateMessageEvent, MessageSegment
from nonebot.typing import T_State
from LittlePaimon.utils.tool import freq_limiter
from LittlePaimon.utils.filter import filter_msg
from LittlePaimon.manager.plugin_manager import plugin_manager as pm
@ -26,22 +28,32 @@ SUPPORTS_CHARA = ['派蒙', '凯亚', '安柏', '丽莎', '琴', '香菱', '枫
CHARA_RE = '|'.join(SUPPORTS_CHARA)
voice_cmd = on_regex(rf'(?P<chara>({CHARA_RE})?)说(?P<text>[\w“”——!\?,\.`\'"\(\)\[\]{{}}~\s]+)', priority=90, block=True,
def is_paimon(event: Union[GroupMessageEvent, PrivateMessageEvent], state: T_State) -> bool:
if '_matched_dict' in state and not state['_matched_dict']['chara'] and event.to_me:
state['_matched_dict']['chara'] = '派蒙'
return True
return False
voice_cmd = on_regex(rf'^(?P<chara>({CHARA_RE})?)说(?P<text>[\w“”——!\?,\.`\'"\(\)\[\]{{}}~\s]+)',
priority=90, block=True,
state={
'pm_name': '原神语音合成',
'pm_description': 'AI语音合成让原神角色说任何话',
'pm_usage': '<角色名>说<话>',
'pm_priority': 10
})
}, rule=Rule(is_paimon))
@voice_cmd.handle()
async def _(event: Union[GroupMessageEvent, PrivateMessageEvent], regex_dict: dict = RegexDict()):
if not regex_dict['chara']:
regex_dict['chara'] = '派蒙'
regex_dict['text'] = filter_msg(regex_dict['text'].replace('\r', '').replace('\n', ''))
if not freq_limiter.check(f'genshin_ai_voice_{event.group_id if isinstance(event, GroupMessageEvent) else event.user_id}'):
await voice_cmd.finish(f'原神语音合成冷却中...剩余{freq_limiter.left(f"genshin_ai_voice_{event.group_id if isinstance(event, GroupMessageEvent) else event.user_id}")}')
freq_limiter.start(f'genshin_ai_voice_{event.group_id if isinstance(event, GroupMessageEvent) else event.user_id}', pm.config.AI_voice_cooldown)
if not freq_limiter.check(
f'genshin_ai_voice_{event.group_id if isinstance(event, GroupMessageEvent) else event.user_id}'):
await voice_cmd.finish(
f'原神语音合成冷却中...剩余{freq_limiter.left(f"genshin_ai_voice_{event.group_id if isinstance(event, GroupMessageEvent) else event.user_id}")}')
freq_limiter.start(f'genshin_ai_voice_{event.group_id if isinstance(event, GroupMessageEvent) else event.user_id}',
pm.config.AI_voice_cooldown)
await voice_cmd.finish(MessageSegment.record(
f'http://233366.proxy.nscc-gz.cn:8888/?text={regex_dict["text"]}&speaker={regex_dict["chara"]}'))

View File

@ -166,7 +166,7 @@ async def check_retcode(data: dict, cookie_info, cookie_type: str, user_id: str,
if cookie_info == 'private':
logger.info('原神Cookie', f'用户<m>{user_id}</m>的私人cookie<m>{uid}</m>已达到每日30次查询上限')
else:
logger.info('原神Cookie', f'<m>{cookie_info["cid"]}</m>号公共cookie已达到每日30次查询上限')
logger.info('原神Cookie', f'<m>{cookie_info.id}</m>号公共cookie已达到每日30次查询上限')
return False
else:
if cookie_type == 'public':