From 2c2e7713d55f93d50072b16947209b12a46cf7a9 Mon Sep 17 00:00:00 2001 From: Ruby280255768 Date: Sun, 11 Apr 2021 16:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8D=E5=BE=AE=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=8B=EF=BC=8C=E5=B8=8C=E6=9C=9B=E8=83=BD=E5=B8=AE?= =?UTF-8?q?=E4=B8=8A=E5=BF=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 稍微修改了一下,希望能帮上忙,修复了之前反馈的错误 --- src/plugins/challenge/__init__.py | 81 ++++++++++++++++++------------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/src/plugins/challenge/__init__.py b/src/plugins/challenge/__init__.py index 5d9667f..8c04b3a 100644 --- a/src/plugins/challenge/__init__.py +++ b/src/plugins/challenge/__init__.py @@ -1,23 +1,34 @@ -from nonebot import on_endswith +from nonebot import on_regex from nonebot.adapters.cqhttp import Bot, Event, Message from datetime import datetime import os - -tf = on_endswith('天赋') -we = on_endswith('武器') -zb = on_endswith('周本') +import re PATH = os.path.abspath('.') +#获取配置的命令起始字符,以免Bot随便响应 +with open(PATH + '/.env.dev', 'r', encoding='utf-8') as f: + for i in f.readlines(): + if re.match('COMMAND_START', i, flags=0): + i = re.search('\[.*\]', i, flags=0).group() + cmd = re.sub('\"', "", i, count=0, flags=0) + if cmd == r'[]': + cmd = "" + break +#通过正则匹配命令起始字符和查询命令 +tf = on_regex('^' + cmd + '.*天赋', flags=0) +we = on_regex('^' + cmd + '.*武器', flags=0) +zb = on_regex('^' + cmd + '.*周本', flags=0) @zb.handle() async def _(bot: Bot, event: Event): await zb.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/zb.png]')) - +#修改判断逻辑,减少错误回复产生 @tf.handle() async def _(bot: Bot, event: Event): mes = str(event.get_message()) + day = str(datetime.now().isoweekday()) if '一' in mes: await tf.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf1.png]')) elif '二' in mes: @@ -30,27 +41,27 @@ async def _(bot: Bot, event: Event): await tf.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf5.png]')) elif '六' in mes: await tf.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf6.png]')) + elif '明' in mes: + if day == '7': + day = '1' + await tf.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf{day}.png]')) + elif day == '6': + await tf.finish(message='明天是周日,所有副本都可以刷哦!') + else: + day = str(int(day) + 1) + await tf.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf{day}.png]')) + elif '日' in mes: + await tf.finish(message='周日所有副本都可以刷哦!') else: - day = str(datetime.now().isoweekday()) - if '明' in mes: - if day == '7': - day = '1' - await tf.finish( - message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf{day}.png]')) - else: - day = str(int(day) + 1) - await tf.finish( - message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf{day}.png]')) - elif day != '7': - await tf.finish( - message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf{day}.png]')) + if day == '7': + await tf.finish(message='今天是周日,所有副本都可以刷哦!') else: - await tf.finish(message='今天星期天所有副本都可以刷哦!') - + await tf.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/tf{day}.png]')) @we.handle() async def _(bot: Bot, event: Event): mes = str(event.get_message()) + day = str(datetime.now().isoweekday()) if '一' in mes: await we.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we1.png]')) elif '二' in mes: @@ -63,19 +74,19 @@ async def _(bot: Bot, event: Event): await we.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we5.png]')) elif '六' in mes: await we.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we6.png]')) + elif '明' in mes: + if day == '7': + day = '1' + await we.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we{day}.png]')) + elif day == '6': + await we.finish(message='明天是周日,所有副本都可以刷哦!') + else: + day = str(int(day) + 1) + await we.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we{day}.png]')) + elif '日' in mes: + await we.finish(message='周日所有副本都可以刷哦!') else: - day = str(datetime.now().isoweekday()) - if '明' in mes: - if day == '7': - day = '1' - await we.finish( - message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we{day}.png]')) - else: - day = str(int(day) + 1) - await we.finish( - message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we{day}.png]')) - elif day != '7': - await we.finish( - message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we{day}.png]')) + if day == '7': + await we.finish(message='今天是周日,所有副本都可以刷哦!') else: - await we.finish(message='今天星期天所有副本都可以刷哦!') + await we.finish(message=Message(f'[CQ:image,file=file:///{PATH}/src/data/challenge/we{day}.png]'))