词条模糊匹配使用contains方法

This commit is contained in:
HibiKier 2022-08-21 18:32:24 +08:00
parent d183903917
commit 2051e8183c
3 changed files with 12 additions and 10 deletions

View File

@ -36,7 +36,7 @@ __plugin_configs__ = {
},
}
coser = on_regex(r"^(\d?)连?(cos|COS|coser|括丝)$", priority=5, block=True)
coser = on_regex(r"^(\d)?连?(cos|COS|coser|括丝)$", priority=5, block=True)
# 纯cos较慢:https://picture.yinux.workers.dev
# 比较杂,有福利姬,较快:https://api.jrsgslb.cn/cos/url.php?return=img
@ -44,7 +44,7 @@ url = "https://picture.yinux.workers.dev/"
@coser.handle()
async def _(bot: Bot, event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()):
async def _(event: MessageEvent, reg_group: Tuple[Any, ...] = RegexGroup()):
num = reg_group[0] or 1
for _ in range(int(num)):
try:

View File

@ -1,4 +1,4 @@
from nonebot import on_command
from nonebot import on_regex
from services.log import logger
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent
from nonebot.typing import T_State
@ -24,7 +24,7 @@ __plugin_settings__ = {
}
quotations = on_command("语录", aliases={"二次元", "二次元语录"}, priority=5, block=True)
quotations = on_regex("^[语录|二次元]$", priority=5, block=True)
url = "https://international.v1.hitokoto.cn/?c=a"

View File

@ -236,17 +236,19 @@ class WordBank(db.Model):
# 完全匹配
if await query.where(cls.problem == problem).gino.first():
return query.where(cls.problem == problem)
# 模糊匹配
if await query.where(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;")
):
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
# 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(