2022-05-15 20:15:10 +08:00
|
|
|
import asyncio
|
|
|
|
from pathlib import Path
|
2022-06-21 16:26:13 +08:00
|
|
|
from typing import Union
|
2022-05-20 18:44:18 +08:00
|
|
|
|
2022-05-15 20:15:10 +08:00
|
|
|
from nonebot import on_command
|
2022-06-21 16:26:13 +08:00
|
|
|
from nonebot.adapters.onebot.v11 import GroupMessageEvent, PrivateMessageEvent, MessageSegment, Bot, MessageEvent, \
|
|
|
|
Message
|
2022-05-15 20:15:10 +08:00
|
|
|
from nonebot.exception import FinishedException
|
2022-05-20 18:44:18 +08:00
|
|
|
from nonebot.params import CommandArg
|
|
|
|
from nonebot.permission import SUPERUSER
|
2022-06-21 16:26:13 +08:00
|
|
|
from nonebot.plugin import PluginMetadata
|
2022-05-15 20:15:10 +08:00
|
|
|
|
2022-05-20 18:44:18 +08:00
|
|
|
from utils.config import config
|
|
|
|
from . import download_data
|
|
|
|
from . import util
|
|
|
|
from .handler import Guess, get_random_voice
|
2022-05-15 20:15:10 +08:00
|
|
|
|
|
|
|
setting_time = config.paimon_guess_voice # 游戏持续时间
|
|
|
|
|
2022-05-19 18:15:56 +08:00
|
|
|
dir_name = Path() / 'data' / 'LittlePaimon' / 'guess_voice' / 'voice'
|
2022-05-15 20:15:10 +08:00
|
|
|
|
2022-06-21 16:26:13 +08:00
|
|
|
|
|
|
|
__plugin_meta__ = PluginMetadata(
|
|
|
|
name="原神猜语音",
|
|
|
|
description="小派蒙的原神猜语音模块",
|
|
|
|
usage=(
|
|
|
|
"原神猜语音[语言]\n"
|
|
|
|
"原神语音[语言]<角色名>\n"
|
|
|
|
"更新原神语音资源\n"
|
|
|
|
),
|
|
|
|
extra={
|
|
|
|
'type': '娱乐',
|
|
|
|
'range': ['private', 'group'],
|
|
|
|
"author": "惜月 <277073121@qq.com>",
|
|
|
|
"version": "1.0.0",
|
|
|
|
},
|
|
|
|
)
|
2022-05-15 20:15:10 +08:00
|
|
|
|
|
|
|
guess_game = on_command('原神猜语音', priority=12, block=True)
|
2022-06-09 21:57:56 +08:00
|
|
|
guess_game.__paimon_help__ = {
|
2022-06-21 16:26:13 +08:00
|
|
|
"usage": "原神猜语音[语言]",
|
2022-06-09 21:57:56 +08:00
|
|
|
"introduce": "来一起猜语音吧",
|
2022-06-21 16:26:13 +08:00
|
|
|
"priority": 5
|
2022-06-09 21:57:56 +08:00
|
|
|
}
|
2022-05-15 20:15:10 +08:00
|
|
|
ys_voice = on_command('原神语音', priority=12, block=True)
|
2022-06-09 21:57:56 +08:00
|
|
|
ys_voice.__paimon_help__ = {
|
2022-06-21 16:26:13 +08:00
|
|
|
"usage": "原神语音[语言]<角色名>",
|
2022-06-09 21:57:56 +08:00
|
|
|
"introduce": "随机发一条该角色的语音",
|
2022-06-21 16:26:13 +08:00
|
|
|
"priority": 6
|
2022-06-09 21:57:56 +08:00
|
|
|
}
|
2022-05-15 20:15:10 +08:00
|
|
|
update_ys_voice = on_command('更新原神语音资源', priority=12, permission=SUPERUSER, block=True)
|
|
|
|
|
|
|
|
|
2022-06-07 17:02:33 +08:00
|
|
|
async def download_voice(bot: Bot, event: MessageEvent):
|
2022-05-15 21:12:39 +08:00
|
|
|
if not dir_name.exists():
|
|
|
|
dir_name.mkdir(parents=True, exist_ok=True)
|
|
|
|
await bot.send(event, '资源尚未初始化,现在开始下载资源,这需要较长的时间,请耐心等待')
|
|
|
|
await download_data.update_voice_data()
|
|
|
|
await bot.send(event, '资源下载完成,请重新发送指令开始游戏')
|
2022-05-15 20:15:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
@guess_game.handle()
|
2022-06-21 16:26:13 +08:00
|
|
|
async def guess_genshin_voice(bot: Bot, event: GroupMessageEvent, msg: Message = CommandArg()):
|
2022-05-15 20:15:10 +08:00
|
|
|
await download_voice(bot, event)
|
2022-06-21 16:26:13 +08:00
|
|
|
keyword = msg.extract_plain_text().strip()
|
2022-05-15 20:15:10 +08:00
|
|
|
guess = Guess(event.group_id, time=setting_time)
|
|
|
|
|
|
|
|
hard_mode = False
|
|
|
|
|
|
|
|
if keyword == '排行榜':
|
|
|
|
await guess_game.finish(await guess.get_rank(bot, event))
|
|
|
|
if keyword in ['中', '中国', '汉语', '中文', '中国话', 'Chinese', 'cn'] or not keyword:
|
|
|
|
keyword = '中'
|
|
|
|
elif keyword in ['日', '日本', '日语', '霓虹', '日本语', 'Japanese', 'jp']:
|
|
|
|
keyword = '日'
|
|
|
|
elif keyword in ['韩', '韩国', '韩语', '棒子', '南朝鲜', '南朝鲜语']:
|
|
|
|
keyword = '韩'
|
|
|
|
elif keyword in ['英', '英文', '英语', '洋文', 'English', 'en']:
|
|
|
|
keyword = '英'
|
|
|
|
elif keyword in ['2', '难', '困难', '地狱']:
|
|
|
|
hard_mode = True
|
|
|
|
else:
|
|
|
|
await guess_game.finish(f'没有找到{keyword}的语音')
|
|
|
|
if guess.is_start():
|
|
|
|
await guess_game.finish('游戏正在进行中哦')
|
|
|
|
guess.set_start()
|
|
|
|
await guess_game.send(f'即将发送一段原神语音,将在{setting_time}秒后公布答案')
|
|
|
|
await asyncio.sleep(1)
|
|
|
|
try:
|
|
|
|
if hard_mode:
|
|
|
|
await guess_game.finish(await guess.start2())
|
|
|
|
else:
|
|
|
|
res = await guess.start(keyword.split())
|
|
|
|
await guess_game.finish(res)
|
|
|
|
except FinishedException:
|
|
|
|
pass
|
|
|
|
except Exception as e:
|
|
|
|
guess.set_end()
|
2022-05-19 19:51:39 +08:00
|
|
|
await guess_game.finish('出错了,可能是该角色缺少语音资源:' + str(e))
|
2022-05-15 20:15:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
@ys_voice.handle()
|
2022-06-21 16:26:13 +08:00
|
|
|
async def get_genshin_voice(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent], msg: Message = CommandArg()):
|
|
|
|
name = msg.extract_plain_text().strip()
|
2022-05-15 20:15:10 +08:00
|
|
|
if name.startswith('日'):
|
|
|
|
language = '日'
|
|
|
|
name = name[1:]
|
2022-06-21 16:26:13 +08:00
|
|
|
elif name.startswith('韩'):
|
|
|
|
language = '韩'
|
|
|
|
name = name[1:]
|
|
|
|
elif name.startswith('英'):
|
|
|
|
language = '英'
|
|
|
|
name = name[1:]
|
2022-05-15 20:15:10 +08:00
|
|
|
else:
|
|
|
|
language = '中'
|
2022-06-21 16:26:13 +08:00
|
|
|
name = name.replace('中', '')
|
2022-05-15 20:15:10 +08:00
|
|
|
await download_voice(bot, event)
|
|
|
|
path = await get_random_voice(name, language)
|
|
|
|
if not path:
|
|
|
|
await ys_voice.finish(f'没有找到{name}的语音呢')
|
|
|
|
await ys_voice.finish(MessageSegment.record(file=Path(path)))
|
|
|
|
|
|
|
|
|
|
|
|
@update_ys_voice.handle()
|
2022-06-21 16:26:13 +08:00
|
|
|
async def update_genshin_voice(bot: Bot, event: Union[GroupMessageEvent, PrivateMessageEvent]):
|
2022-05-15 20:15:10 +08:00
|
|
|
await update_ys_voice.send('将在后台开始更新原神语音资源,请耐心等待资源下载完成后再使用原神语音')
|
|
|
|
await download_data.update_voice_data()
|
|
|
|
await update_ys_voice.finish('原神语音资源更新完成')
|