diff --git a/plugins/word_bank/_model.py b/plugins/word_bank/_model.py index 2eec7b00..b53f0879 100644 --- a/plugins/word_bank/_model.py +++ b/plugins/word_bank/_model.py @@ -237,12 +237,21 @@ class WordBank(db.Model): if await query.where( ((cls.word_type == 0) | (cls.word_type == 3)) & (cls.problem == problem) ).gino.first(): - return query.where(cls.problem == problem) + return query.where( + ((cls.word_type == 0) | (cls.word_type == 3)) & (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 = 1 and :problem like '%' || problem || '%';" + ), + problem=problem, + ): + return ( + sql_text + + f" and word_type = 1 and :problem like '%' || problem || '%';" + ) # 正则匹配 if await db.first( db.text( @@ -253,7 +262,7 @@ class WordBank(db.Model): ): return ( sql_text - + f" and word_type = 2 and word_scope != 999 and '{problem}' ~ problem;" + + 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;") @@ -281,7 +290,7 @@ class WordBank(db.Model): query = await cls.check(event, problem, word_scope, word_type) if query is not None: if isinstance(query, str): - answer_list = await db.all(db.text(query)) + answer_list = await db.all(db.text(query), problem=problem) answer = random.choice(answer_list) return ( await cls._format2answer(problem, answer[7], answer[1], answer[2]) diff --git a/plugins/word_bank/_rule.py b/plugins/word_bank/_rule.py index 54498d6f..63f5b741 100644 --- a/plugins/word_bank/_rule.py +++ b/plugins/word_bank/_rule.py @@ -27,8 +27,6 @@ async def check(event: MessageEvent, state: T_State) -> bool: 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