commit
3017c2f5ae
9 changed files with 18 additions and 14 deletions
|
@ -117,9 +117,12 @@ class MessageSession(MS):
|
|||
return False
|
||||
return False
|
||||
|
||||
def asDisplay(self):
|
||||
m = self.session.message.message
|
||||
m = re.sub(r'\[CQ:at,qq=(.*?)]', r'QQ|\1', html.unescape(m))
|
||||
def asDisplay(self, text_only=False):
|
||||
m = html.unescape(self.session.message.message)
|
||||
if text_only:
|
||||
return ''.join(
|
||||
re.split(r'\[CQ:.*?]', m)).strip()
|
||||
m = re.sub(r'\[CQ:at,qq=(.*?)]', r'QQ|\1', m)
|
||||
m = re.sub(r'\[CQ:forward,id=(.*?)]', r'\[Ke:forward,id=\1]', m)
|
||||
|
||||
return ''.join(
|
||||
|
|
|
@ -107,7 +107,7 @@ class MessageSession(MS):
|
|||
return True
|
||||
return False
|
||||
|
||||
def asDisplay(self):
|
||||
def asDisplay(self, text_only=False):
|
||||
return self.session.message.text
|
||||
|
||||
async def delete(self):
|
||||
|
|
|
@ -118,7 +118,7 @@ class MessageSession(MS):
|
|||
return True
|
||||
return False
|
||||
|
||||
def asDisplay(self):
|
||||
def asDisplay(self, text_only=False):
|
||||
msg = self.session.message.content
|
||||
msg = re.sub(r'<@(.*?)>', r'Discord|Client|\1', msg)
|
||||
return msg
|
||||
|
|
|
@ -41,7 +41,7 @@ class MessageSession(MessageSession):
|
|||
if result:
|
||||
if msgchain is not None and delete:
|
||||
await send.delete()
|
||||
if result.asDisplay() in confirm_command:
|
||||
if result.asDisplay(text_only=True) in confirm_command:
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
|
|
|
@ -173,9 +173,10 @@ class MessageSession:
|
|||
:return: 任意人的MessageChain对象
|
||||
"""
|
||||
|
||||
def asDisplay(self) -> str:
|
||||
def asDisplay(self, text_only=False) -> str:
|
||||
"""
|
||||
用于将消息转换为一般文本格式。
|
||||
:param text_only: 是否只保留纯文本(默认为False)
|
||||
"""
|
||||
|
||||
def t(self, *args, **kwargs) -> str:
|
||||
|
|
|
@ -133,7 +133,7 @@ async def chemical_code(msg: Bot.MessageSession, id=None, captcha_mode=False):
|
|||
async def ans(msg: Bot.MessageSession, answer): # 定义回答函数的功能
|
||||
wait = await msg.waitAnyone() # 等待对象内的任意人回答
|
||||
if play_state[msg.target.targetId]['active']: # 检查对象是否为活跃状态
|
||||
if wait.asDisplay() != answer: # 如果回答不正确
|
||||
if wait.asDisplay(text_only=True) != answer: # 如果回答不正确
|
||||
Logger.info(f'{wait.asDisplay()} != {answer}') # 输出日志
|
||||
return await ans(wait, answer) # 进行下一轮检查
|
||||
else:
|
||||
|
@ -159,7 +159,7 @@ async def chemical_code(msg: Bot.MessageSession, id=None, captcha_mode=False):
|
|||
result = await msg.waitNextMessage(
|
||||
[Image(newpath), Plain(lang.t('chemical_code.captcha.text', times=set_timeout))])
|
||||
if play_state[msg.target.targetId]['active']: # 检查对象是否为活跃状态
|
||||
if result.asDisplay() == csr['name']:
|
||||
if result.asDisplay(text_only=True) == csr['name']:
|
||||
await result.sendMessage(lang.t('chemical_code.correct'))
|
||||
else:
|
||||
await result.sendMessage(lang.t('chemical_code.incorrect', answer=play_state[msg.target.targetId]["answer"]))
|
||||
|
|
|
@ -51,7 +51,7 @@ async def main(msg: Bot.MessageSession):
|
|||
i += 1
|
||||
reply_text.append(f'{i}. {info}')
|
||||
reply = await msg.waitReply('搜索结果如下:\n' + '\n'.join(reply_text) + '\n请回复编号来选择mod。')
|
||||
replied = reply.asDisplay()
|
||||
replied = reply.asDisplay(text_only=True)
|
||||
if replied.isdigit():
|
||||
replied = int(replied)
|
||||
if replied > len(infos):
|
||||
|
@ -78,7 +78,7 @@ async def main(msg: Bot.MessageSession):
|
|||
for info2 in infos_2:
|
||||
reply_text.append(f'{info2}')
|
||||
reply2 = await msg.waitReply('此mod拥有如下版本:\n' + '\n'.join(reply_text) + '\n请回复版本号来选择版本。')
|
||||
replied2 = reply2.asDisplay()
|
||||
replied2 = reply2.asDisplay(text_only=True)
|
||||
if replied2 in infos_2:
|
||||
mod_url_2 = infos_2[replied2]
|
||||
ver = replied2
|
||||
|
|
|
@ -95,6 +95,6 @@ async def search_pages(session: Bot.MessageSession, title: Union[str, list, tupl
|
|||
msg_list.append(w)
|
||||
msg_list.append('回复编号以查询对应的页面。')
|
||||
reply = await session.waitReply(Plain('\n'.join(msg_list)))
|
||||
if reply.asDisplay().isdigit():
|
||||
if reply.asDisplay(text_only=True).isdigit():
|
||||
reply_number = int(reply.asDisplay()) - 1
|
||||
await query_pages(reply, wait_msg_list[reply_number])
|
||||
|
|
|
@ -328,9 +328,9 @@ async def query_pages(session: Union[Bot.MessageSession, QueryInfo], title: Unio
|
|||
confirm = await session.waitNextMessage(wait_msg_list, delete=True)
|
||||
auto_index = False
|
||||
index = 0
|
||||
if confirm.asDisplay() in confirm_command:
|
||||
if confirm.asDisplay(text_only=True) in confirm_command:
|
||||
auto_index = True
|
||||
elif confirm.asDisplay().isdigit():
|
||||
elif confirm.asDisplay(text_only=True).isdigit():
|
||||
index = int(confirm.asDisplay()) - 1
|
||||
else:
|
||||
return
|
||||
|
|
Reference in a new issue