mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
词条模糊匹配使用contains方法
This commit is contained in:
parent
d183903917
commit
2051e8183c
@ -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
|
# 纯cos,较慢:https://picture.yinux.workers.dev
|
||||||
# 比较杂,有福利姬,较快:https://api.jrsgslb.cn/cos/url.php?return=img
|
# 比较杂,有福利姬,较快:https://api.jrsgslb.cn/cos/url.php?return=img
|
||||||
@ -44,7 +44,7 @@ url = "https://picture.yinux.workers.dev/"
|
|||||||
|
|
||||||
|
|
||||||
@coser.handle()
|
@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
|
num = reg_group[0] or 1
|
||||||
for _ in range(int(num)):
|
for _ in range(int(num)):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from nonebot import on_command
|
from nonebot import on_regex
|
||||||
from services.log import logger
|
from services.log import logger
|
||||||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent
|
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent
|
||||||
from nonebot.typing import T_State
|
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"
|
url = "https://international.v1.hitokoto.cn/?c=a"
|
||||||
|
|
||||||
|
|||||||
@ -236,17 +236,19 @@ class WordBank(db.Model):
|
|||||||
# 完全匹配
|
# 完全匹配
|
||||||
if await query.where(cls.problem == problem).gino.first():
|
if await query.where(cls.problem == problem).gino.first():
|
||||||
return query.where(cls.problem == problem)
|
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(
|
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;")
|
||||||
):
|
):
|
||||||
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(
|
||||||
if await db.first(
|
# db.text(sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;")
|
||||||
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 sql_text + f" and word_type = 1 and word_scope != 999 and '{problem}' ~ problem;"
|
# return None
|
||||||
return None
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_answer(
|
async def get_answer(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user