From 4a5cc5153fbd4da6a0d228bb42735a93eb9949c1 Mon Sep 17 00:00:00 2001 From: CRAZY <674015283@qq.com> Date: Sun, 21 Aug 2022 20:11:44 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=B4=A8=E5=8F=98?= =?UTF-8?q?=E4=BB=AA=E5=9B=BE=E7=89=87=E8=8E=B7=E5=8F=96=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/query_user/query_memo/data_source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/genshin/query_user/query_memo/data_source.py b/plugins/genshin/query_user/query_memo/data_source.py index 007c90de..f1d62503 100644 --- a/plugins/genshin/query_user/query_memo/data_source.py +++ b/plugins/genshin/query_user/query_memo/data_source.py @@ -36,7 +36,7 @@ async def _(): "https://patchwiki.biligame.com/images/ys/thumb/c/cc/6k6kuj1kte6m1n7hexqfrn92z6h4yhh.png/60px-委托任务logo.png", "https://patchwiki.biligame.com/images/ys/d/d9/t1hv6wpucbwucgkhjntmzroh90nmcdv.png", "https://s3.bmp.ovh/imgs/2022/07/24/28d9338c7da4bcb2.png", - "https://genshin.honeyhunterworld.com/img/gadget/i_3016.png", + "https://genshin.honeyhunterworld.com/img/i_3016.png", ], ): file = memo_path / name From bc53f329a91d1c995a4733294ff6ab06c693e1e4 Mon Sep 17 00:00:00 2001 From: CRAZY <674015283@qq.com> Date: Sun, 21 Aug 2022 20:33:06 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B0=98=E6=AD=8C?= =?UTF-8?q?=E5=A3=B6=E5=92=8C=E8=B4=A8=E5=8F=98=E4=BB=AA=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/query_user/query_memo/data_source.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/genshin/query_user/query_memo/data_source.py b/plugins/genshin/query_user/query_memo/data_source.py index f1d62503..e1e1c25a 100644 --- a/plugins/genshin/query_user/query_memo/data_source.py +++ b/plugins/genshin/query_user/query_memo/data_source.py @@ -35,8 +35,8 @@ async def _(): "20.png?x-oss-process=image//resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,png", "https://patchwiki.biligame.com/images/ys/thumb/c/cc/6k6kuj1kte6m1n7hexqfrn92z6h4yhh.png/60px-委托任务logo.png", "https://patchwiki.biligame.com/images/ys/d/d9/t1hv6wpucbwucgkhjntmzroh90nmcdv.png", - "https://s3.bmp.ovh/imgs/2022/07/24/28d9338c7da4bcb2.png", - "https://genshin.honeyhunterworld.com/img/i_3016.png", + "https://s3.bmp.ovh/imgs/2022/08/21/3a3b2e6c22e305ff.png", + "https://s3.bmp.ovh/imgs/2022/08/21/c2d7ace21e1d46cf.png", ], ): file = memo_path / name From c46660319379583d8cbe03ead0f6185deb715fc6 Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Sun, 21 Aug 2022 21:58:31 +0800 Subject: [PATCH 03/21] Fix at messages with suffixed text --- plugins/word_bank/_rule.py | 4 +++- plugins/word_bank/message_handle.py | 4 +++- plugins/word_bank/word_handle.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/word_bank/_rule.py b/plugins/word_bank/_rule.py index 91f8f498..df0b784e 100644 --- a/plugins/word_bank/_rule.py +++ b/plugins/word_bank/_rule.py @@ -23,8 +23,10 @@ async def check(event: MessageEvent) -> bool: for seg in event.message: if seg.type == 'at': temp += f"[at:{seg.data['qq']}]" - else: + elif isinstance(seg, str): temp += seg + elif seg.type == 'text': + temp += seg.data["text"] problem = temp if problem: return await WordBank.check(event, problem) is not None diff --git a/plugins/word_bank/message_handle.py b/plugins/word_bank/message_handle.py index 7aa7bd8d..af5a7973 100644 --- a/plugins/word_bank/message_handle.py +++ b/plugins/word_bank/message_handle.py @@ -33,8 +33,10 @@ async def _(event: MessageEvent): for seg in event.message: if seg.type == 'at': temp += f"[at:{seg.data['qq']}]" - else: + elif isinstance(seg, str): temp += seg + elif seg.type == 'text': + temp += seg.data["text"] problem = temp elif text: problem = text diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index f729883f..5c6d7818 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -117,8 +117,10 @@ async def _( _problem[0] = str(_problem[0])[str(_problem).index('问')+1:] temp = '' for g in _problem: - if isinstance(g, str) or g.type == 'text': + if isinstance(g, str): temp += g + elif g.type == 'text': + temp += g.data['text'] elif g.type == 'at': temp += f"[at:{g.data['qq']}]" problem = temp From cf7a64c934ad673d8dd49b0b1787c08fbdca3ce0 Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Sun, 21 Aug 2022 22:24:06 +0800 Subject: [PATCH 04/21] =?UTF-8?q?fix:=20=E9=97=AE=E7=AD=94=E4=B8=BA[at=20+?= =?UTF-8?q?=20=E6=96=87=E6=9C=AC]=E7=9A=84=E6=83=85=E5=86=B5=E6=97=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/word_handle.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index 5c6d7818..e35ac3dd 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -113,8 +113,9 @@ async def _( if seg.type == 'text' and '答' in str(seg): _problem = event.message[:index] answer = event.message[index:] - answer[0] = str(answer[0])[str(answer).index('答')+1:] - _problem[0] = str(_problem[0])[str(_problem).index('问')+1:] + answer[0] = str(answer[0])[str(answer[0]).index('答')+1:] + _problem[0] = str(_problem[0])[str(_problem[0]).index('问')+1:] + _problem.append(seg.data['text'][:seg.data['text'].index('答')]) temp = '' for g in _problem: if isinstance(g, str): From 3bb9aaf637408c8ad4bc07b30fbb588a6e67e3f4 Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Sun, 21 Aug 2022 23:21:34 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E8=AF=8D=E6=9D=A1=E5=89=8D=E5=85=88=E6=A3=80=E6=9F=A5=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E6=9C=89=E6=95=88=E6=80=A7=20&=20=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E8=AF=8D=E6=9D=A1=E5=85=88=E8=BF=9B=E8=A1=8C=E8=BD=AC=E4=B9=89?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E7=84=B6=E7=AC=A6=E5=8F=B7=E9=83=BD=E4=B9=B1?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/word_handle.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index e35ac3dd..7762ce3b 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -1,3 +1,4 @@ +import re from typing import Tuple, Any, Optional from nonebot.internal.params import Arg, ArgStr @@ -5,11 +6,12 @@ from nonebot.typing import T_State from utils.utils import get_message_at, is_number, get_message_img from nonebot.params import CommandArg, RegexGroup, Command +from nonebot.exception import FinishedException from services.log import logger from configs.path_config import DATA_PATH from utils.message_builder import custom_forward_msg from ._model import WordBank -from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message, MessageEvent, PrivateMessageEvent +from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message, MessageEvent, PrivateMessageEvent, unescape from nonebot import on_command, on_regex from configs.config import Config from ._data_source import delete_word, update_word, show_word @@ -126,7 +128,7 @@ async def _( temp += f"[at:{g.data['qq']}]" problem = temp break - index = len((word_scope or "") + "添加词条" + (word_type or "") + problem) + 1 + index = len((word_scope or "") + "添加词条" + (word_type or "") + unescape(problem)) + 1 event.message[0] = event.message[0].data["text"][index + 1 :].strip() state["word_scope"] = word_scope state["word_type"] = word_type @@ -144,6 +146,12 @@ async def _( problem_image: Message = Arg("problem_image"), ): try: + if word_type == "正则": + try: + problem = unescape(problem) + re.compile(problem) + except re.error: + await add_word.finish(f"添加词条失败,正则表达式 {problem} 非法!") await WordBank.add_problem_answer( event.user_id, event.group_id if isinstance(event, GroupMessageEvent) and (not word_scope or word_scope == '1') else 0, @@ -153,6 +161,8 @@ async def _( answer, ) except Exception as e: + if isinstance(e, FinishedException): + await add_word.finish() logger.error( f"(USER {event.user_id}, GROUP " f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})" From f570bffcf71b8db86dc7f7936ac7ac34cbfd6864 Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Sun, 21 Aug 2022 23:42:46 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=97=B6=E5=80=99=E5=BF=BD=E8=A7=86=E4=BA=86word=5Ftype?= =?UTF-8?q?=E7=9A=84=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/_model.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/word_bank/_model.py b/plugins/word_bank/_model.py index b236c711..3759cd58 100644 --- a/plugins/word_bank/_model.py +++ b/plugins/word_bank/_model.py @@ -234,19 +234,21 @@ class WordBank(db.Model): query = query.where(cls.word_scope == word_type) sql_text += f" and word_scope = {word_scope}" # 完全匹配 - if await query.where(cls.problem == problem).gino.first(): + if await query.where(((cls.word_type == 0) | (cls.word_type == 3)) & (cls.problem == problem)).gino.first(): return query.where(cls.problem == problem) + # 模糊匹配 + if await query.where((cls.word_type == 1) & (cls.problem.contains(problem))).gino.first(): + return query.where(cls.problem.contains(problem)) # 正则匹配 if await db.first( - db.text(sql_text + f" and word_type = 2 and '{problem}' ~ problem;") + db.text(sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;") ): - return sql_text + f" and word_type = 2 and '{problem}' ~ problem;" - # 模糊匹配 - if await db.first( - db.text(sql_text + f" and word_type = 1 and '{problem}' ~ problem;") - ): - return sql_text + f" and word_type = 1 and '{problem}' ~ problem;" - return None + return sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;" + # if await db.first( + # db.text(sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;") + # ): + # return sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;" + # return None @classmethod async def get_answer( @@ -456,4 +458,4 @@ class WordBank(db.Model): ) problem_list.append(problem) _tmp.append(q.problem) - return problem_list + return problem_list \ No newline at end of file From 31d4d29f3e622b295e30b64e6a9690eaed8cbed9 Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Sun, 21 Aug 2022 23:47:21 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=97=B6=E5=80=99=E5=BF=BD=E8=A7=86=E4=BA=86word=5Ftype?= =?UTF-8?q?=E7=9A=84=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/word_bank/_model.py b/plugins/word_bank/_model.py index 42479b75..3759cd58 100644 --- a/plugins/word_bank/_model.py +++ b/plugins/word_bank/_model.py @@ -234,10 +234,10 @@ class WordBank(db.Model): query = query.where(cls.word_scope == word_type) sql_text += f" and word_scope = {word_scope}" # 完全匹配 - if await query.where(cls.problem == problem).gino.first(): + if await query.where(((cls.word_type == 0) | (cls.word_type == 3)) & (cls.problem == problem)).gino.first(): return query.where(cls.problem == problem) # 模糊匹配 - if await query.where(cls.problem.contains(problem)).gino.first(): + if await query.where((cls.word_type == 1) & (cls.problem.contains(problem))).gino.first(): return query.where(cls.problem.contains(problem)) # 正则匹配 if await db.first( From 308b76dc7d985e8174047ae42832d44d9a298cae Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Mon, 22 Aug 2022 00:38:25 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=5Frule=E4=B8=AD=E4=BD=BF=E7=94=A8message?= =?UTF-8?q?segment=E4=B8=AD=E6=9C=AA=E8=BD=AC=E4=B9=89=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=EF=BC=8C=E8=80=8C=E6=B7=BB=E5=8A=A0=E8=AF=8D?= =?UTF-8?q?=E6=9D=A1=E6=97=B6=E4=BD=BF=E7=94=A8=E4=BA=86=E8=BD=AC=E4=B9=89?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=BA=8C=E8=80=85=E4=B8=8D=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/word_handle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index 7762ce3b..8802a2f0 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -128,7 +128,8 @@ async def _( temp += f"[at:{g.data['qq']}]" problem = temp break - index = len((word_scope or "") + "添加词条" + (word_type or "") + unescape(problem)) + 1 + problem = unescape(problem) + index = len((word_scope or "") + "添加词条" + (word_type or "") + problem) + 1 event.message[0] = event.message[0].data["text"][index + 1 :].strip() state["word_scope"] = word_scope state["word_type"] = word_type @@ -148,7 +149,6 @@ async def _( try: if word_type == "正则": try: - problem = unescape(problem) re.compile(problem) except re.error: await add_word.finish(f"添加词条失败,正则表达式 {problem} 非法!") From 76bef8a725d78e02b08311b75e43d3691b000d7d Mon Sep 17 00:00:00 2001 From: xiayingLIULI <88604496+xiayingLIULI@users.noreply.github.com> Date: Mon, 22 Aug 2022 00:40:51 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E5=AF=B9=E7=B1=B3=E6=B8=B8=E7=A4=BEcooki?= =?UTF-8?q?e=E8=BF=9B=E8=A1=8C=E5=88=A4=E6=96=AD=EF=BC=8C=E6=95=B4?= =?UTF-8?q?=E5=90=88=E7=B1=B3=E6=B8=B8=E7=A4=BE=E7=AD=BE=E5=88=B0=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/query_user/bind/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/genshin/query_user/bind/__init__.py b/plugins/genshin/query_user/bind/__init__.py index 8cb3be7d..38a8ac74 100644 --- a/plugins/genshin/query_user/bind/__init__.py +++ b/plugins/genshin/query_user/bind/__init__.py @@ -93,6 +93,8 @@ async def _(event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message print(cookie) cookie_json = json.loads(cookie) print(cookie_json) + if 'login_ticket' not in cookie_json: + await bind.finish("请发送正确的cookie!") login_ticket = cookie_json['login_ticket'] # try: res = await AsyncHttpx.get(url=bbs_Cookie_url.format(login_ticket)) From a9eadca46cf351b2372a3e0ada77113a9132b333 Mon Sep 17 00:00:00 2001 From: xiayingLIULI <88604496+xiayingLIULI@users.noreply.github.com> Date: Mon, 22 Aug 2022 00:42:00 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=20=E5=AF=B9=E7=B1=B3=E6=B8=B8=E7=A4=BEco?= =?UTF-8?q?okie=E8=BF=9B=E8=A1=8C=E5=88=A4=E6=96=AD=EF=BC=8C=E6=95=B4?= =?UTF-8?q?=E5=90=88=E7=B1=B3=E6=B8=B8=E7=A4=BE=E7=AD=BE=E5=88=B0=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/query_user/genshin_sign/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/genshin/query_user/genshin_sign/__init__.py b/plugins/genshin/query_user/genshin_sign/__init__.py index 18463bf4..5a6c2464 100644 --- a/plugins/genshin/query_user/genshin_sign/__init__.py +++ b/plugins/genshin/query_user/genshin_sign/__init__.py @@ -51,9 +51,9 @@ async def _(event: MessageEvent, cmd: Tuple[str, ...] = Command()): # await genshin_matcher.finish("请更新cookie!") if cmd == "原神我硬签": try: + await genshin_matcher.send("正在进行签到...", at_sender=True) msg = await genshin_sign(uid) return_data = await mihoyobbs_sign(event.user_id) - await genshin_matcher.send(return_data) logger.info( f"(USER {event.user_id}, " f"GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'}) UID:{uid} 原神签到" @@ -70,7 +70,7 @@ async def _(event: MessageEvent, cmd: Tuple[str, ...] = Command()): await u.clear_sign_time(uid) next_date = await Genshin.random_sign_time(uid) add_job(event.user_id, uid, next_date) - msg += f"\n因开启自动签到\n下一次签到时间为:{next_date.replace(microsecond=0)}" + msg += f"\n{return_data}\n因开启自动签到\n下一次签到时间为:{next_date.replace(microsecond=0)}" except Exception as e: msg = "原神签到失败..请尝试检查cookie或报告至管理员!" logger.info( From 6321a9e7e0b85adfd0946736b7a5c0224eb03615 Mon Sep 17 00:00:00 2001 From: LambdaYH Date: Mon, 22 Aug 2022 00:49:30 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E4=BD=BF=E7=94=A8gino=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C=E9=81=BF=E5=85=8D=E6=9E=84?= =?UTF-8?q?=E5=BB=BAsql=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=97=B6=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E9=9D=9E=E6=B3=95=E6=9F=A5=E8=AF=A2=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/_model.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/word_bank/_model.py b/plugins/word_bank/_model.py index 3759cd58..2eec7b00 100644 --- a/plugins/word_bank/_model.py +++ b/plugins/word_bank/_model.py @@ -234,16 +234,27 @@ class WordBank(db.Model): query = query.where(cls.word_scope == word_type) sql_text += f" and word_scope = {word_scope}" # 完全匹配 - if await query.where(((cls.word_type == 0) | (cls.word_type == 3)) & (cls.problem == problem)).gino.first(): + if await query.where( + ((cls.word_type == 0) | (cls.word_type == 3)) & (cls.problem == problem) + ).gino.first(): return query.where(cls.problem == problem) # 模糊匹配 - if await query.where((cls.word_type == 1) & (cls.problem.contains(problem))).gino.first(): + if await query.where( + (cls.word_type == 1) & (cls.problem.contains(problem)) + ).gino.first(): return query.where(cls.problem.contains(problem)) # 正则匹配 if await db.first( - db.text(sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;") + db.text( + sql_text + + f" and word_type = 2 and word_scope != 999 and :problem ~ problem;" + ), + problem=problem, ): - return sql_text + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;" + return ( + sql_text + + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;" + ) # if await db.first( # db.text(sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;") # ): @@ -458,4 +469,4 @@ class WordBank(db.Model): ) problem_list.append(problem) _tmp.append(q.problem) - return problem_list \ No newline at end of file + return problem_list From 27e97214bde78b230730405901efe69f80a69080 Mon Sep 17 00:00:00 2001 From: Cinte Date: Mon, 22 Aug 2022 09:49:33 +0800 Subject: [PATCH 12/21] =?UTF-8?q?=E4=BB=85=E4=BB=85=E6=98=AF=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=9B=BE=E7=89=87hash=E5=B0=B1=E5=B0=86=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8B=E8=BD=BD=E5=88=B0=E7=A3=81=E7=9B=98=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=9C=89=E4=BA=9B=E6=B5=AA=E8=B4=B9io=EF=BC=8C?= =?UTF-8?q?=E4=BA=8E=E6=98=AF=E6=94=B9=E6=88=90=E4=BA=86=E5=86=85=E5=AD=98?= =?UTF-8?q?=E4=B8=AD=E7=9B=B4=E6=8E=A5=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/_rule.py | 15 +++++++++------ plugins/word_bank/message_handle.py | 16 ++++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/plugins/word_bank/_rule.py b/plugins/word_bank/_rule.py index df0b784e..f55971bd 100644 --- a/plugins/word_bank/_rule.py +++ b/plugins/word_bank/_rule.py @@ -1,9 +1,10 @@ -import random +import imagehash +from PIL import Image +from io import BytesIO +from httpx import TimeoutException from nonebot.adapters.onebot.v11 import MessageEvent -from configs.path_config import TEMP_PATH -from utils.image_utils import get_img_hash from utils.utils import get_message_text, get_message_img, get_message_at from ._model import WordBank from utils.http_utils import AsyncHttpx @@ -13,11 +14,13 @@ async def check(event: MessageEvent) -> bool: text = get_message_text(event.message) img = get_message_img(event.message) at = get_message_at(event.message) - rand = random.randint(1, 100) problem = text if not text and len(img) == 1: - if await AsyncHttpx.download_file(img[0], TEMP_PATH / f"{event.user_id}_{rand}_word_bank_check.jpg"): - problem = str(get_img_hash(TEMP_PATH / f"{event.user_id}_{rand}_word_bank_check.jpg")) + try: + r = await AsyncHttpx.get(img[0]) + problem = str(imagehash.average_hash(Image.open(BytesIO(r.content)))) + except TimeoutException: + pass if at: temp = '' for seg in event.message: diff --git a/plugins/word_bank/message_handle.py b/plugins/word_bank/message_handle.py index af5a7973..da28bf2d 100644 --- a/plugins/word_bank/message_handle.py +++ b/plugins/word_bank/message_handle.py @@ -1,10 +1,12 @@ -import random +import imagehash +from PIL import Image +from io import BytesIO +from httpx import TimeoutException from services import logger -from utils.image_utils import get_img_hash from ._rule import check from ._model import WordBank -from configs.path_config import DATA_PATH, TEMP_PATH +from configs.path_config import DATA_PATH from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageEvent from utils.utils import get_message_img, get_message_text, get_message_at from nonebot import on_message @@ -25,9 +27,11 @@ async def _(event: MessageEvent): at = get_message_at(event.message) problem = None if not text and img and len(img) == 1: - rand = random.randint(1, 10000) - if await AsyncHttpx.download_file(img[0], TEMP_PATH / f"{event.user_id}_{rand}_word_bank.jpg"): - problem = str(get_img_hash(TEMP_PATH / f"{event.user_id}_{rand}_word_bank.jpg")) + try: + r = await AsyncHttpx.get(img[0]) + problem = str(imagehash.average_hash(Image.open(BytesIO(r.content)))) + except TimeoutException: + logger.error(f"下载 {img[0]} 下载超时..") elif at: temp = '' for seg in event.message: From 7ae883d921760f929b03cd611980fa06a33e5b94 Mon Sep 17 00:00:00 2001 From: Cinte Date: Mon, 22 Aug 2022 10:14:59 +0800 Subject: [PATCH 13/21] =?UTF-8?q?=E4=BD=BF=E7=94=A8check=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E7=9A=84problem=E8=80=8C=E4=B8=8D=E5=9C=A8message=5Fhandle?= =?UTF-8?q?=E4=B8=AD=E9=87=8D=E6=96=B0=E6=9E=84=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/_rule.py | 8 +++--- plugins/word_bank/message_handle.py | 39 +++-------------------------- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/plugins/word_bank/_rule.py b/plugins/word_bank/_rule.py index f55971bd..54498d6f 100644 --- a/plugins/word_bank/_rule.py +++ b/plugins/word_bank/_rule.py @@ -3,6 +3,7 @@ from PIL import Image from io import BytesIO from httpx import TimeoutException +from nonebot.typing import T_State from nonebot.adapters.onebot.v11 import MessageEvent from utils.utils import get_message_text, get_message_img, get_message_at @@ -10,7 +11,7 @@ from ._model import WordBank from utils.http_utils import AsyncHttpx -async def check(event: MessageEvent) -> bool: +async def check(event: MessageEvent, state: T_State) -> bool: text = get_message_text(event.message) img = get_message_img(event.message) at = get_message_at(event.message) @@ -31,6 +32,7 @@ async def check(event: MessageEvent) -> bool: elif seg.type == 'text': temp += seg.data["text"] problem = temp - if problem: - return await WordBank.check(event, problem) is not None + if problem and (await WordBank.check(event, problem) is not None): + state["problem"] = problem + return True return False diff --git a/plugins/word_bank/message_handle.py b/plugins/word_bank/message_handle.py index da28bf2d..5dc5b14a 100644 --- a/plugins/word_bank/message_handle.py +++ b/plugins/word_bank/message_handle.py @@ -1,16 +1,10 @@ -import imagehash -from PIL import Image -from io import BytesIO -from httpx import TimeoutException - from services import logger from ._rule import check from ._model import WordBank from configs.path_config import DATA_PATH from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageEvent -from utils.utils import get_message_img, get_message_text, get_message_at from nonebot import on_message -from utils.http_utils import AsyncHttpx +from nonebot.typing import T_State __zx_plugin_name__ = "词库问答回复操作 [Hidden]" @@ -21,37 +15,12 @@ message_handle = on_message(priority=6, block=True, rule=check) @message_handle.handle() -async def _(event: MessageEvent): - text = get_message_text(event.message) - img = get_message_img(event.message) - at = get_message_at(event.message) - problem = None - if not text and img and len(img) == 1: - try: - r = await AsyncHttpx.get(img[0]) - problem = str(imagehash.average_hash(Image.open(BytesIO(r.content)))) - except TimeoutException: - logger.error(f"下载 {img[0]} 下载超时..") - elif at: - temp = '' - for seg in event.message: - if seg.type == 'at': - temp += f"[at:{seg.data['qq']}]" - elif isinstance(seg, str): - temp += seg - elif seg.type == 'text': - temp += seg.data["text"] - problem = temp - elif text: - problem = text - if problem: +async def _(event: MessageEvent, state: T_State): + if problem := state.get("problem"): if msg := await WordBank.get_answer(event, problem): await message_handle.send(msg) logger.info( f"(USER {event.user_id}, GROUP " f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})" f" 触发词条 {problem}" - ) - - - + ) \ No newline at end of file From 1e57ddb9ee8d655d82dff6ad0bb861ffe711fa3c Mon Sep 17 00:00:00 2001 From: Cinte Date: Mon, 22 Aug 2022 11:14:04 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E5=A4=84=E7=90=86at=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=8E=A5=E7=A9=BA=E6=A0=BC=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=EF=BC=8Cproblem=E4=B8=AD=E5=85=81=E8=AE=B8=E5=8D=95=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E5=AD=97=E7=AC=A6=E5=8F=B7=20&=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E5=85=83=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/quotations.py | 2 +- plugins/word_bank/word_handle.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/quotations.py b/plugins/quotations.py index af4ee144..85fd3d9c 100755 --- a/plugins/quotations.py +++ b/plugins/quotations.py @@ -24,7 +24,7 @@ __plugin_settings__ = { } -quotations = on_regex("^[语录|二次元]$", priority=5, block=True) +quotations = on_regex("^(语录|二次元)$", priority=5, block=True) url = "https://international.v1.hitokoto.cn/?c=a" diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index 8802a2f0..7356d66b 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -25,7 +25,7 @@ usage: 更推荐使用id方式删除 问题回答支持的CQ:at, face, image 查看词条命令:群聊时为 群词条+全局词条,私聊时为 私聊词条+全局词条 - 添加词条正则:添加词条(模糊|正则|图片)?问\s*?(\S*)\s*?答\s?(\S*) + 添加词条正则:添加词条(模糊|正则|图片)?问\s*?(\S*\s?\S*)\s*?答\s?(\S*) 指令: 添加词条 ?[模糊|正则|图片]问...答...:添加问答词条,可重复添加相同问题的不同回答 删除词条 [问题/下标] ?[下标]:删除指定词条指定或全部回答 @@ -49,7 +49,7 @@ __plugin_superuser_usage__ = r""" usage: 在私聊中超级用户额外设置 指令: - (全局|私聊)?添加词条\s*?(模糊|正则|图片)?问\s*?(\S*)\s*?答\s?(\S*):添加问答词条,可重复添加相同问题的不同回答 + (全局|私聊)?添加词条\s*?(模糊|正则|图片)?问\s*?(\S*\s?\S*)\s*?答\s?(\S*):添加问答词条,可重复添加相同问题的不同回答 全局添加词条 私聊添加词条 (私聊情况下)删除词条: 删除私聊词条 @@ -76,7 +76,7 @@ data_dir = DATA_PATH / "word_bank" data_dir.mkdir(parents=True, exist_ok=True) add_word = on_regex( - r"^(全局|私聊)?添加词条\s*?(模糊|正则|图片)?问\s*?(\S*)\s*?答\s?(\S*)", priority=5, block=True + r"^(全局|私聊)?添加词条\s*?(模糊|正则|图片)?问\s*?(\S*\s?\S*)\s*?答\s?(\S*)", priority=5, block=True ) delete_word_matcher = on_command("删除词条", aliases={'删除全局词条'}, priority=5, block=True) @@ -117,7 +117,10 @@ async def _( answer = event.message[index:] answer[0] = str(answer[0])[str(answer[0]).index('答')+1:] _problem[0] = str(_problem[0])[str(_problem[0]).index('问')+1:] - _problem.append(seg.data['text'][:seg.data['text'].index('答')]) + if _problem[-1].type == 'at' and seg.data['text'][:seg.data['text'].index('答')].lstrip(): + _problem.append(seg.data['text'][:seg.data['text'].index('答')]) + else: + _problem.append(seg.data['text'][:seg.data['text'].index('答')].lstrip()) temp = '' for g in _problem: if isinstance(g, str): From 52d23c4a8d153fc87d09ca0a8e3b771120be5a5f Mon Sep 17 00:00:00 2001 From: xiayingLIULI <88604496+xiayingLIULI@users.noreply.github.com> Date: Mon, 22 Aug 2022 11:44:21 +0800 Subject: [PATCH 15/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=83=BD=E5=9C=A8?= =?UTF-8?q?=E7=BE=A4=E8=81=8A=E4=B8=AD=E6=9F=A5=E7=9C=8B=E6=88=91=E7=9A=84?= =?UTF-8?q?cookie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/query_user/genshin_sign/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/genshin/query_user/genshin_sign/__init__.py b/plugins/genshin/query_user/genshin_sign/__init__.py index 5a6c2464..99585662 100644 --- a/plugins/genshin/query_user/genshin_sign/__init__.py +++ b/plugins/genshin/query_user/genshin_sign/__init__.py @@ -44,6 +44,8 @@ async def _(event: MessageEvent, cmd: Tuple[str, ...] = Command()): uid = await Genshin.get_user_uid(event.user_id) if cmd == "查看我的cookie": my_cookie = await Genshin.get_user_cookie(uid, True) + if isinstance(event, GroupMessageEvent): + await genshin_matcher.finish("请私聊查看您的cookie!") await genshin_matcher.finish("您的cookie为" + my_cookie) if not uid or not await Genshin.get_user_cookie(uid, True): await genshin_matcher.finish("请先绑定uid和cookie!") From cc2645aa9d66ddb6d29aa8076b33cd84ba9f5061 Mon Sep 17 00:00:00 2001 From: Cinte Date: Mon, 22 Aug 2022 12:34:21 +0800 Subject: [PATCH 16/21] Update word_handle.py --- plugins/word_bank/word_handle.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index 7356d66b..c84cc5bc 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -117,10 +117,11 @@ async def _( answer = event.message[index:] answer[0] = str(answer[0])[str(answer[0]).index('答')+1:] _problem[0] = str(_problem[0])[str(_problem[0]).index('问')+1:] - if _problem[-1].type == 'at' and seg.data['text'][:seg.data['text'].index('答')].lstrip(): - _problem.append(seg.data['text'][:seg.data['text'].index('答')]) - else: - _problem.append(seg.data['text'][:seg.data['text'].index('答')].lstrip()) + if _problem[-1].type == 'at': + if seg.data['text'][:seg.data['text'].index('答')].lstrip(): + _problem.append(seg.data['text'][:seg.data['text'].index('答')]) + else: + _problem.append(seg.data['text'][:seg.data['text'].index('答')].lstrip()) temp = '' for g in _problem: if isinstance(g, str): From f7aecf8eed34607bddbf8f2b70969c6f310df0ef Mon Sep 17 00:00:00 2001 From: Cinte Date: Mon, 22 Aug 2022 12:37:06 +0800 Subject: [PATCH 17/21] Update word_handle.py --- plugins/word_bank/word_handle.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index c84cc5bc..357e296d 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -117,11 +117,8 @@ async def _( answer = event.message[index:] answer[0] = str(answer[0])[str(answer[0]).index('答')+1:] _problem[0] = str(_problem[0])[str(_problem[0]).index('问')+1:] - if _problem[-1].type == 'at': - if seg.data['text'][:seg.data['text'].index('答')].lstrip(): - _problem.append(seg.data['text'][:seg.data['text'].index('答')]) - else: - _problem.append(seg.data['text'][:seg.data['text'].index('答')].lstrip()) + if _problem[-1].type != 'at' or seg.data['text'][:seg.data['text'].index('答')].lstrip(): + _problem.append(seg.data['text'][:seg.data['text'].index('答')]) temp = '' for g in _problem: if isinstance(g, str): From e70a85400f349a5f26795784310d50a789d3437c Mon Sep 17 00:00:00 2001 From: Cinte Date: Mon, 22 Aug 2022 12:56:35 +0800 Subject: [PATCH 18/21] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E8=AF=8D=E6=9D=A1?= =?UTF-8?q?=E7=9A=84id=E8=8C=83=E5=9B=B4=E5=88=A4=E6=96=AD=E5=B0=91?= =?UTF-8?q?=E4=BA=86=E4=B8=AA=E7=AD=89=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/word_handle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/word_bank/word_handle.py b/plugins/word_bank/word_handle.py index 357e296d..8aa44b54 100644 --- a/plugins/word_bank/word_handle.py +++ b/plugins/word_bank/word_handle.py @@ -247,7 +247,7 @@ async def _(bot: Bot, event: GroupMessageEvent, arg: Message = CommandArg()): not is_number(id_) or int(id_) < 0 or int(id_) - > len(await WordBank.get_group_all_problem(event.group_id)) + >= len(await WordBank.get_group_all_problem(event.group_id)) ): await show_word_matcher.finish("id必须为数字且在范围内") id_ = int(id_) @@ -257,7 +257,7 @@ async def _(bot: Bot, event: GroupMessageEvent, arg: Message = CommandArg()): not is_number(gid) or int(gid) < 0 or int(gid) - > len(await WordBank.get_problem_by_scope(0)) + >= len(await WordBank.get_problem_by_scope(0)) ): await show_word_matcher.finish("gid必须为数字且在范围内") gid = int(gid) From e73c50982350afa2e68629357d0942061fa74385 Mon Sep 17 00:00:00 2001 From: xiayingLIULI <88604496+xiayingLIULI@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:33:49 +0800 Subject: [PATCH 19/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B1=B3=E6=B8=B8?= =?UTF-8?q?=E7=A4=BE=E7=AD=BE=E5=88=B0=E5=9C=A8=E6=97=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?cookie=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/query_user/mihoyobbs_sign/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/genshin/query_user/mihoyobbs_sign/__init__.py b/plugins/genshin/query_user/mihoyobbs_sign/__init__.py index 8e61f828..43e59352 100644 --- a/plugins/genshin/query_user/mihoyobbs_sign/__init__.py +++ b/plugins/genshin/query_user/mihoyobbs_sign/__init__.py @@ -38,16 +38,18 @@ mihoyobbs_matcher = on_command( @mihoyobbs_matcher.handle() async def _(event: MessageEvent, cmd: Tuple[str, ...] = Command()): - await mihoyobbs_matcher.send("提交米游社签到申请") + await mihoyobbs_matcher.send("提交米游社签到申请", at_sender=True) return_data = await mihoyobbs_sign(event.user_id) if return_data: - await mihoyobbs_matcher.finish(return_data) + await mihoyobbs_matcher.finish(return_data, at_sender=True) else: - await mihoyobbs_matcher.finish("米游社签到失败,请查看控制台输出") + await mihoyobbs_matcher.finish("米游社签到失败,请查看控制台输出", at_sender=True) async def mihoyobbs_sign(user_id): uid = await Genshin.get_user_uid(user_id) + if not uid: + await mihoyobbs_matcher.finish("请先绑定uid和cookie!", at_sender=True) stuid = await Genshin.get_stuid(uid) stoken = await Genshin.get_stoken(uid) cookie = await Genshin.get_user_cookie(uid) From 1dc8cb2a9809a6bcec00f91161c784da3c47156c Mon Sep 17 00:00:00 2001 From: xiayingLIULI <88604496+xiayingLIULI@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:45:04 +0800 Subject: [PATCH 20/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=B1=B3=E6=B8=B8?= =?UTF-8?q?=E7=A4=BE=E7=AD=BE=E5=88=B0=E5=9C=A8=E6=97=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?cookie=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/query_user/mihoyobbs_sign/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/genshin/query_user/mihoyobbs_sign/__init__.py b/plugins/genshin/query_user/mihoyobbs_sign/__init__.py index 43e59352..4298183c 100644 --- a/plugins/genshin/query_user/mihoyobbs_sign/__init__.py +++ b/plugins/genshin/query_user/mihoyobbs_sign/__init__.py @@ -48,7 +48,7 @@ async def _(event: MessageEvent, cmd: Tuple[str, ...] = Command()): async def mihoyobbs_sign(user_id): uid = await Genshin.get_user_uid(user_id) - if not uid: + if not uid or not await Genshin.get_user_cookie(uid, True): await mihoyobbs_matcher.finish("请先绑定uid和cookie!", at_sender=True) stuid = await Genshin.get_stuid(uid) stoken = await Genshin.get_stoken(uid) From 09ce812faf7dbe1993c00a2bad2c684f127eca64 Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Mon, 22 Aug 2022 20:39:03 +0800 Subject: [PATCH 21/21] Update __init__.py --- plugins/genshin/query_user/bind/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/genshin/query_user/bind/__init__.py b/plugins/genshin/query_user/bind/__init__.py index 38a8ac74..cc77b022 100644 --- a/plugins/genshin/query_user/bind/__init__.py +++ b/plugins/genshin/query_user/bind/__init__.py @@ -94,7 +94,7 @@ async def _(event: MessageEvent, cmd: Tuple[str, ...] = Command(), arg: Message cookie_json = json.loads(cookie) print(cookie_json) if 'login_ticket' not in cookie_json: - await bind.finish("请发送正确的cookie!") + await bind.finish("请发送正确完整的cookie!") login_ticket = cookie_json['login_ticket'] # try: res = await AsyncHttpx.get(url=bbs_Cookie_url.format(login_ticket))