mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
🐛 修复Bot.receive_mutiply_resp()
可能失效的问题
This commit is contained in:
parent
9d131b2089
commit
35a5841d33
@ -1,3 +1,4 @@
|
|||||||
|
import random
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
@ -39,25 +40,39 @@ class GsClient:
|
|||||||
async def send_msg(self):
|
async def send_msg(self):
|
||||||
while True:
|
while True:
|
||||||
intent = await self._input()
|
intent = await self._input()
|
||||||
if intent == '图片测试':
|
for content in [
|
||||||
content = [
|
Message(type='text', data=intent),
|
||||||
Message(
|
Message(type='text', data='开始一场60秒的游戏'),
|
||||||
type='file',
|
Message(type='text', data=intent),
|
||||||
data='xxx.json|XAclpWfLF5d66dtrHx8cqq8E+',
|
Message(type='text', data='233'),
|
||||||
)
|
Message(type='text', data='233'),
|
||||||
]
|
Message(type='text', data='233'),
|
||||||
else:
|
Message(type='text', data='233'),
|
||||||
content = [Message(type='text', data=intent)]
|
Message(type='text', data='233'),
|
||||||
msg = MessageReceive(
|
Message(type='text', data=intent),
|
||||||
bot_id='console',
|
Message(type='text', data=intent),
|
||||||
user_type='direct',
|
Message(type='text', data=intent),
|
||||||
user_pm=1,
|
Message(type='text', data=intent),
|
||||||
group_id=None,
|
Message(type='text', data=intent),
|
||||||
user_id='511',
|
Message(type='text', data=intent),
|
||||||
content=content,
|
Message(type='text', data=intent),
|
||||||
)
|
]:
|
||||||
msg_send = msgjson.encode(msg)
|
user_type = random.choice(['direct', 'group'])
|
||||||
await self.ws.send(msg_send)
|
group_id = random.choice(['555', '666', '777'])
|
||||||
|
user_id = random.choice(['1', '2', '3', '4', '5'])
|
||||||
|
if content.data == '开始一场60秒的游戏':
|
||||||
|
user_type = 'group'
|
||||||
|
group_id = '555'
|
||||||
|
msg = MessageReceive(
|
||||||
|
bot_id='console',
|
||||||
|
user_type=user_type, # type: ignore
|
||||||
|
user_pm=1,
|
||||||
|
group_id=group_id,
|
||||||
|
user_id=user_id,
|
||||||
|
content=[content],
|
||||||
|
)
|
||||||
|
msg_send = msgjson.encode(msg)
|
||||||
|
await self.ws.send(msg_send)
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
recv_task = asyncio.create_task(self.recv_msg())
|
recv_task = asyncio.create_task(self.recv_msg())
|
||||||
|
@ -83,7 +83,11 @@ async def handle_event(ws: _Bot, msg: MessageReceive):
|
|||||||
mutiply_instances = Bot.get_mutiply_instances()
|
mutiply_instances = Bot.get_mutiply_instances()
|
||||||
mutiply_map = Bot.get_mutiply_map()
|
mutiply_map = Bot.get_mutiply_map()
|
||||||
|
|
||||||
if gid in mutiply_map and mutiply_map[gid] in mutiply_instances:
|
if (
|
||||||
|
gid in mutiply_map
|
||||||
|
and event.user_type != 'direct'
|
||||||
|
and mutiply_map[gid] in mutiply_instances
|
||||||
|
):
|
||||||
mutiply_instances[mutiply_map[gid]].mutiply_resp.append(event)
|
mutiply_instances[mutiply_map[gid]].mutiply_resp.append(event)
|
||||||
mutiply_instances[mutiply_map[gid]].set_mutiply_event()
|
mutiply_instances[mutiply_map[gid]].set_mutiply_event()
|
||||||
if uuid == mutiply_instances[mutiply_map[gid]].uuid:
|
if uuid == mutiply_instances[mutiply_map[gid]].uuid:
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
from async_timeout import timeout
|
||||||
|
|
||||||
from gsuid_core.bot import Bot
|
from gsuid_core.bot import Bot
|
||||||
from gsuid_core.sv import SL, SV
|
from gsuid_core.sv import SL, SV
|
||||||
from gsuid_core.models import Event
|
from gsuid_core.models import Event
|
||||||
@ -33,16 +35,17 @@ async def get_fullmatch_msg(bot: Bot, ev: Event):
|
|||||||
await bot.send('[全匹配测试]校验成功!')
|
await bot.send('[全匹配测试]校验成功!')
|
||||||
|
|
||||||
|
|
||||||
@sv_switch.on_fullmatch('测试多人事件')
|
@sv_switch.on_fullmatch('开始一场60秒的游戏')
|
||||||
async def get_event_msg(bot: Bot, ev: Event):
|
async def get_time_limit_resp_msg(bot: Bot, ev: Event):
|
||||||
await bot.send('正在进行[测试多人事件]')
|
await bot.send('接下来开始60秒的游戏!?')
|
||||||
try:
|
try:
|
||||||
while True:
|
async with timeout(60): # 限制时长60秒
|
||||||
resp = await bot.receive_mutiply_resp()
|
while True:
|
||||||
if resp is not None:
|
resp = await bot.receive_mutiply_resp()
|
||||||
await bot.send(f'{resp.user_id}:发送了 - {resp.text}')
|
if resp is not None:
|
||||||
except TimeoutError:
|
await bot.send(f'你说的是 {resp.text} 吧?')
|
||||||
await bot.send('超时了哦!')
|
except asyncio.TimeoutError:
|
||||||
|
await bot.send('时间到!!现在开始计算每个人的分数...')
|
||||||
|
|
||||||
|
|
||||||
@sv_switch.on_fullmatch('开始游戏')
|
@sv_switch.on_fullmatch('开始游戏')
|
||||||
|
@ -34,10 +34,12 @@ def modify_func(func):
|
|||||||
finally:
|
finally:
|
||||||
instancess = Bot.get_instances()
|
instancess = Bot.get_instances()
|
||||||
mutiply_instances = Bot.get_mutiply_instances()
|
mutiply_instances = Bot.get_mutiply_instances()
|
||||||
|
mutiply_map = Bot.get_mutiply_map()
|
||||||
if bot.uuid in instancess:
|
if bot.uuid in instancess:
|
||||||
instancess.pop(bot.uuid)
|
instancess.pop(bot.uuid)
|
||||||
if bot.uuid in mutiply_instances and bot.mutiply_tag:
|
if bot.uuid in mutiply_instances and bot.mutiply_tag:
|
||||||
mutiply_instances.pop(bot.uuid)
|
mutiply_instances.pop(bot.uuid)
|
||||||
|
mutiply_map.pop(bot.gid)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
@ -126,7 +128,7 @@ class SV:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if name == '测试开关':
|
if name == '测试开关':
|
||||||
self.pm = 0
|
self.pm = 6
|
||||||
self.enabled = False
|
self.enabled = False
|
||||||
|
|
||||||
def set(self, **kwargs):
|
def set(self, **kwargs):
|
||||||
|
@ -20,14 +20,14 @@ async def get_event_avatar(
|
|||||||
ev: Event, avatar_path: Optional[Path] = None
|
ev: Event, avatar_path: Optional[Path] = None
|
||||||
) -> Image.Image:
|
) -> Image.Image:
|
||||||
img = None
|
img = None
|
||||||
if 'avatar' in ev.sender and ev.sender['avatar']:
|
if ev.bot_id == 'onebot' and ev.at:
|
||||||
|
return await get_qq_avatar(ev.at)
|
||||||
|
elif 'avatar' in ev.sender and ev.sender['avatar']:
|
||||||
avatar_url = ev.sender['avatar']
|
avatar_url = ev.sender['avatar']
|
||||||
content = (await sget(avatar_url)).content
|
content = (await sget(avatar_url)).content
|
||||||
return Image.open(BytesIO(content)).convert('RGBA')
|
return Image.open(BytesIO(content)).convert('RGBA')
|
||||||
elif ev.bot_id == 'onebot' and not ev.sender:
|
elif ev.bot_id == 'onebot' and not ev.sender:
|
||||||
avatar_url = f'http://q1.qlogo.cn/g?b=qq&nk={ev.user_id}&s=640'
|
return await get_qq_avatar(ev.user_id)
|
||||||
content = (await sget(avatar_url)).content
|
|
||||||
return Image.open(BytesIO(content)).convert('RGBA')
|
|
||||||
elif avatar_path:
|
elif avatar_path:
|
||||||
pic_path_list = list(avatar_path.iterdir())
|
pic_path_list = list(avatar_path.iterdir())
|
||||||
if pic_path_list:
|
if pic_path_list:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user