✨ 猜语音 无尽模式
This commit is contained in:
parent
cbc3897bbd
commit
f633dc65cd
@ -84,6 +84,7 @@ class Guess:
|
||||
self.time = time
|
||||
self.group_id = group_id
|
||||
self.group = process.get(self.group_id)
|
||||
self.forever = False
|
||||
|
||||
def is_start(self):
|
||||
if not self.group:
|
||||
@ -96,26 +97,30 @@ class Guess:
|
||||
def set_end(self):
|
||||
process[self.group_id] = {}
|
||||
|
||||
def set_forever(self):
|
||||
self.forever = True
|
||||
|
||||
async def start(self):
|
||||
if exists(f"assets{os.sep}voice{os.sep}voice.json"):
|
||||
with open(f"assets{os.sep}voice{os.sep}voice.json", "r", encoding='utf-8') as f:
|
||||
mys_list_raw = json.load(f)
|
||||
else:
|
||||
return "没有找到声音数据"
|
||||
return await app.send_message(self.group_id, "没有找到声音数据")
|
||||
mys_list = list(mys_list_raw.keys())
|
||||
if not mys_list:
|
||||
return "没有找到声音数据"
|
||||
return await app.send_message(self.group_id, "没有找到声音数据")
|
||||
chars = get_chars(mys_list)
|
||||
answer = random.choice(chars)
|
||||
file_id = get_key_list(mys_list, answer)
|
||||
file_id = choice_voice(file_id)
|
||||
if not file_id:
|
||||
return "没有找到声音数据"
|
||||
return await app.send_message(self.group_id, "没有找到声音数据")
|
||||
|
||||
# 记录答案
|
||||
process[self.group_id] = {
|
||||
'start': True,
|
||||
'answer': answer,
|
||||
'forever': self.forever,
|
||||
'ok': set()
|
||||
}
|
||||
|
||||
@ -133,9 +138,9 @@ class Guess:
|
||||
max_instances=1)
|
||||
|
||||
print('答案: ' + answer)
|
||||
return mys_list_raw[file_id]
|
||||
return await app.send_voice(self.group_id, mys_list_raw[file_id])
|
||||
|
||||
async def end_game(self):
|
||||
async def end_game(self, force: bool = False):
|
||||
self.group = process.get(self.group_id)
|
||||
|
||||
ok_list = list(process[self.group_id]['ok'])
|
||||
@ -152,6 +157,7 @@ class Guess:
|
||||
traceback.print_exc()
|
||||
|
||||
# 清理记录
|
||||
forever = process[self.group_id]['forever']
|
||||
process[self.group_id] = {}
|
||||
|
||||
# 记录到数据库给之后奖励做处理
|
||||
@ -165,6 +171,16 @@ class Guess:
|
||||
user_group[user] = info
|
||||
user_db[self.group_id] = user_group
|
||||
|
||||
# 无尽模式
|
||||
if not force:
|
||||
if forever:
|
||||
self.forever = True
|
||||
process[self.group_id] = {'start': True}
|
||||
await self.start()
|
||||
else:
|
||||
if scheduler.get_job(f'{self.group_id}_guess_voice', 'default'):
|
||||
scheduler.remove_job(f'{self.group_id}_guess_voice', 'default')
|
||||
|
||||
# 只添加正确的答案
|
||||
async def add_answer(self, qq: int, msg: str):
|
||||
if self.group.get('answer') and char_name_by_name(msg) == self.group['answer']:
|
||||
|
@ -6,20 +6,24 @@ from defs.guess_voice import Guess
|
||||
|
||||
|
||||
async def guess_voice(client: Client, message: Message):
|
||||
text = message.text.replace("原神猜语音", "")
|
||||
text = message.text.replace("猜语音", "")
|
||||
guess = Guess(message.chat.id, time=guess_time)
|
||||
if text == "排行榜":
|
||||
return await message.reply(await guess.get_rank(client, message))
|
||||
if text == "停止":
|
||||
if guess.is_start():
|
||||
return await guess.end_game(True)
|
||||
if guess.is_start():
|
||||
return await message.reply('游戏正在进行中哦')
|
||||
guess.set_start()
|
||||
await message.reply(f'即将发送一段原神语音,将在 <b>{guess_time}秒</b> 后公布答案')
|
||||
if text == "无尽模式":
|
||||
guess.set_forever()
|
||||
await message.reply(f'即将发送一段原神语音,将在 <b>{guess_time}秒</b> 后公布答案。\n'
|
||||
f'目前处于<b>无尽模式</code>,游戏将只能通过 <code>猜语音停止</code> 来结束。')
|
||||
else:
|
||||
await message.reply(f'即将发送一段原神语音,将在 <b>{guess_time}秒</b> 后公布答案')
|
||||
try:
|
||||
msg = await guess.start()
|
||||
if msg == "没有找到声音数据":
|
||||
await message.reply(msg)
|
||||
else:
|
||||
await client.send_voice(message.chat.id, msg)
|
||||
await guess.start()
|
||||
except Exception as e:
|
||||
guess.set_end()
|
||||
await message.reply("出现未知错误,请联系管理员")
|
||||
|
@ -194,7 +194,7 @@ async def process_group_msg(client: Client, message: Message):
|
||||
await mys2_qun_msg(client, message)
|
||||
if text.startswith('mihoyo'):
|
||||
await mihoyo_qun_msg(client, message)
|
||||
if text.startswith("原神猜语音"):
|
||||
if text.startswith("猜语音"):
|
||||
await guess_voice(client, message)
|
||||
# 处理猜语音游戏
|
||||
await process_guess(client, message)
|
||||
|
Loading…
Reference in New Issue
Block a user