mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2025-04-12 23:29:37 +08:00
派蒙语音新增实时更新
This commit is contained in:
parent
04f93b6eb0
commit
6f6996aff2
@ -1,26 +1,49 @@
|
|||||||
import os
|
|
||||||
import random
|
import random
|
||||||
from pathlib import Path
|
import requests
|
||||||
|
|
||||||
from nonebot import on_regex, logger
|
from nonebot import on_regex, on_command, logger
|
||||||
from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageSegment
|
from nonebot.matcher import matchers
|
||||||
|
from nonebot.rule import Rule
|
||||||
|
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent, MessageSegment
|
||||||
from nonebot.exception import FinishedException
|
from nonebot.exception import FinishedException
|
||||||
|
|
||||||
from utils.config import config
|
from utils.config import config
|
||||||
from utils.auth_util import FreqLimiter2
|
from utils.auth_util import FreqLimiter2
|
||||||
from .chat_list import chat_list
|
|
||||||
|
|
||||||
res_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'res', 'voice')
|
voice_url = 'https://static.cherishmoon.fun/LittlePaimon/voice/'
|
||||||
chat_lmt = FreqLimiter2(60)
|
chat_lmt = FreqLimiter2(60)
|
||||||
|
|
||||||
|
update_voice = on_command('更新派蒙语音', priority=2)
|
||||||
|
|
||||||
|
|
||||||
|
def check_group(event: GroupMessageEvent) -> bool:
|
||||||
|
if event.group_id in config.paimon_chat_group:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@update_voice.handle()
|
||||||
|
async def update_paimon_voice(event: MessageEvent):
|
||||||
|
try:
|
||||||
|
old_len = len([m for m in matchers[10] if m.plugin_name == 'Paimon_Chat'])
|
||||||
|
matchers[10] = [m for m in matchers[10] if m.plugin_name != 'Paimon_Chat']
|
||||||
|
voice_list = requests.get('https://static.cherishmoon.fun/LittlePaimon/voice/voice_list.json').json()
|
||||||
|
for key, value in voice_list.items():
|
||||||
|
create_matcher(key, value['pattern'], value['cooldown'], value['pro'], value['files'])
|
||||||
|
new_len = len(voice_list) - old_len
|
||||||
|
await update_voice.send(f'派蒙语音更新成功,本次获取到{len(voice_list)}种语音, 新增{new_len}种语音')
|
||||||
|
except FinishedException:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
await update_voice.send(f'派蒙语音更新失败:{e}')
|
||||||
|
|
||||||
|
|
||||||
def create_matcher(chat_word: str, pattern: str, cooldown: int, pro: float, responses):
|
def create_matcher(chat_word: str, pattern: str, cooldown: int, pro: float, responses):
|
||||||
hammer = on_regex(pattern, priority=10)
|
hammer = on_regex(pattern, priority=10, rule=Rule(check_group))
|
||||||
|
hammer.plugin_name = 'Paimon_Chat'
|
||||||
|
|
||||||
@hammer.handle()
|
@hammer.handle()
|
||||||
async def handler(event: GroupMessageEvent):
|
async def handler(event: GroupMessageEvent):
|
||||||
if event.group_id not in config.paimon_chat_group:
|
|
||||||
return
|
|
||||||
if not chat_lmt.check(event.group_id, chat_word):
|
if not chat_lmt.check(event.group_id, chat_word):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -33,14 +56,13 @@ def create_matcher(chat_word: str, pattern: str, cooldown: int, pro: float, resp
|
|||||||
if '.mp3' not in response:
|
if '.mp3' not in response:
|
||||||
await hammer.finish(response)
|
await hammer.finish(response)
|
||||||
else:
|
else:
|
||||||
await hammer.finish(MessageSegment.record(file=Path(os.path.join(res_path, response))))
|
await hammer.finish(MessageSegment.record(file=voice_url + response))
|
||||||
except FinishedException:
|
except FinishedException:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('派蒙发送语音失败', e)
|
logger.error('派蒙发送语音失败', e)
|
||||||
|
|
||||||
|
|
||||||
|
chat_list = requests.get('https://static.cherishmoon.fun/LittlePaimon/voice/voice_list.json').json()
|
||||||
for k, v in chat_list.items():
|
for k, v in chat_list.items():
|
||||||
create_matcher(k, v['pattern'], v['cooldown'], v['pro'], v['files'])
|
create_matcher(k, v['pattern'], v['cooldown'], v['pro'], v['files'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
chat_list = {
|
|
||||||
'确实': {'pattern': r'.*(雀食|确实).*', 'cooldown': 120, 'pro': 0.5, 'files': ['雀食', '确实']},
|
|
||||||
'坏了': {'pattern': r'.*派蒙.*坏.*', 'cooldown': 120, 'pro': 0.5, 'files': ['你才坏!', '瞎说啥呢?', '派蒙怎么可能会坏!']},
|
|
||||||
'诶嘿': {'pattern': r'.*(诶嘿|哎嘿|欸嘿).*', 'cooldown': 120, 'pro': 0.5, 'files': ['诶嘿.mp3', '诶嘿cn.mp3']},
|
|
||||||
'进不去': {'pattern': r'.*进不?(来|去).*', 'cooldown': 180, 'pro': 0.5, 'files': ['进不去.mp3']},
|
|
||||||
'派蒙是谁': {'pattern': r'.*(派蒙.*是(什么|谁))|((什么|谁)是?.*派蒙).*', 'cooldown': 240, 'pro': 1,
|
|
||||||
'files': ['嘿嘿你猜.mp3', '中二派蒙.mp3', '伙伴.mp3']},
|
|
||||||
'大佬': {'pattern': r'.*((大|巨)佬)|带带|帮帮|邦邦.*', 'cooldown': 240, 'pro': 0.6, 'files': ['大佬nb.mp3']},
|
|
||||||
'好色': {'pattern': r'.*好色|变态(哦|噢)?', 'cooldown': 300, 'pro': 0.5, 'files': ['好色哦.mp3', '好变态.mp3']},
|
|
||||||
'无语': {'pattern': r'.*(\.{3,9})|(\。{3,9})|无语|无话可说.*', 'cooldown': 300, 'pro': 0.6, 'files': ['无语.mp3', '冷淡反应.mp3']},
|
|
||||||
'祝福': {'pattern': r'.*派蒙.*(祝福|吟唱|施法).*', 'cooldown': 360, 'pro': 1, 'files': ['来个祝福.mp3']},
|
|
||||||
'相信': {'pattern': r'.*信?不信|信我.*', 'cooldown': 360, 'pro': 0.5, 'files': ['我信你个鬼.mp3', '真的假的.mp3']},
|
|
||||||
'憨批': {'pattern': r'.*(憨批|傻(逼|B|b)).*', 'cooldown': 360, 'pro': 0.5, 'files': ['憨批.mp3']},
|
|
||||||
'可爱': {'pattern': r'.*可爱|卡哇伊', 'cooldown': 360, 'pro': 0.5, 'files': ['真是个小可爱.mp3']},
|
|
||||||
'绿茶': {'pattern': r'.*派蒙.*(giegie|绿茶).*', 'cooldown': 360, 'pro': 1, 'files': ['绿茶派.mp3']},
|
|
||||||
'不是吧': {'pattern': r'不(是|会)吧', 'cooldown': 300, 'pro': 0.4, 'files': ['不是吧阿sir.mp3']},
|
|
||||||
'好耶': {'pattern': r'好耶|太(好|棒)(了|啦)|好(\!|\!)', 'cooldown': 180, 'pro': 0.75, 'files': ['好耶.mp3', '太好啦.mp3']},
|
|
||||||
'好听': {'pattern': r'(好|真|非常)?好听(\!|\!)?', 'cooldown': 360, 'pro': 0.4, 'files': ['好听.mp3']},
|
|
||||||
'耽误时间': {'pattern': r'快{3,5}|gkd|搞?快点|赶紧的?|(.*耽误.*时间.*)', 'cooldown': 360, 'pro': 0.6, 'files': ['耽误时间.mp3']},
|
|
||||||
'不可以': {'pattern': r'不(可以|行|能)(吧|的|噢)?', 'cooldown': 240, 'pro': 0.4, 'files': ['不可以.mp3']},
|
|
||||||
'好意思': {'pattern': r'.*好意思.*', 'cooldown': 300, 'pro': 0.5, 'files': ['好意思.mp3']},
|
|
||||||
'不要啊': {'pattern': r'不(好|要)(吧|啊)', 'cooldown': 180, 'pro': 0.5, 'files': ['不要啊.mp3']},
|
|
||||||
'羡慕': {'pattern': r'.*羡慕.*', 'cooldown': 180, 'pro': 0.5, 'files': ['羡慕.mp3']},
|
|
||||||
'过分': {'pattern': r'.*过分.*', 'cooldown': 300, 'pro': 0.4, 'files': ['好过分.mp3']},
|
|
||||||
'不明白': {'pattern': r'.*明白.*', 'cooldown': 300, 'pro': 0.4, 'files': ['不明白.mp3']},
|
|
||||||
'哪里不对': {'pattern': r'(是|对)(吧|吗)', 'cooldown': 300, 'pro': 0.4, 'files': ['哪里不对.mp3']}
|
|
||||||
}
|
|
@ -72,6 +72,7 @@
|
|||||||
+ 5.20
|
+ 5.20
|
||||||
- 修复`ysc`缺少资源问题
|
- 修复`ysc`缺少资源问题
|
||||||
- 封装部分常用方法,优化导包
|
- 封装部分常用方法,优化导包
|
||||||
|
- `Paimon_Chat`新增`更新派蒙语音`,实时更新语音
|
||||||
|
|
||||||
## 功能列表
|
## 功能列表
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
res/voice/伙伴.mp3
BIN
res/voice/伙伴.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
res/voice/坏蛋.mp3
BIN
res/voice/坏蛋.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
res/voice/好听.mp3
BIN
res/voice/好听.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
res/voice/好耶.mp3
BIN
res/voice/好耶.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
res/voice/憨批.mp3
BIN
res/voice/憨批.mp3
Binary file not shown.
Binary file not shown.
BIN
res/voice/无语.mp3
BIN
res/voice/无语.mp3
Binary file not shown.
Binary file not shown.
BIN
res/voice/泪目.mp3
BIN
res/voice/泪目.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
res/voice/羡慕.mp3
BIN
res/voice/羡慕.mp3
Binary file not shown.
Binary file not shown.
BIN
res/voice/诶嘿.mp3
BIN
res/voice/诶嘿.mp3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3
res/weapon/.gitignore
vendored
3
res/weapon/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
# ignore all except .gitignore file
|
|
||||||
*
|
|
||||||
!.gitignore
|
|
Loading…
x
Reference in New Issue
Block a user