mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
词条问题支持真寻的昵称开头与at真寻开头并优化回复
This commit is contained in:
parent
f496ce4861
commit
b59699dabe
@ -296,6 +296,10 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
|
|||||||
|
|
||||||
## 更新
|
## 更新
|
||||||
|
|
||||||
|
### 2022/12/11
|
||||||
|
|
||||||
|
* 词条问题支持真寻的昵称开头与at真寻开头并优化回复
|
||||||
|
|
||||||
### 2022/12/10
|
### 2022/12/10
|
||||||
|
|
||||||
* 重写帮助,删除 `详细帮助` 命令
|
* 重写帮助,删除 `详细帮助` 命令
|
||||||
|
|||||||
@ -25,6 +25,5 @@ withdraw_msg = on_command("撤回", priority=5, block=True)
|
|||||||
|
|
||||||
@withdraw_msg.handle()
|
@withdraw_msg.handle()
|
||||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||||
r = re.search(r"\[CQ:reply,id=(-?\d*)]", event.raw_message)
|
if event.reply:
|
||||||
if r:
|
await bot.delete_msg(message_id=event.reply.message_id)
|
||||||
await bot.delete_msg(message_id=int(r.group(1)))
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from configs.config import Config
|
from configs.config import Config
|
||||||
|
from utils.utils import GDict
|
||||||
import nonebot
|
import nonebot
|
||||||
|
|
||||||
Config.add_plugin_config(
|
Config.add_plugin_config(
|
||||||
@ -10,4 +11,6 @@ Config.add_plugin_config(
|
|||||||
default_value=5
|
default_value=5
|
||||||
)
|
)
|
||||||
|
|
||||||
|
GDict['run_sql'].append("ALTER TABLE word_bank2 ADD to_me VARCHAR(255);")
|
||||||
|
|
||||||
nonebot.load_plugins("plugins/word_bank")
|
nonebot.load_plugins("plugins/word_bank")
|
||||||
|
|||||||
@ -84,8 +84,9 @@ async def word_handle(params: str, group_id: Optional[int], type_: str, word_sco
|
|||||||
if not is_number(index) or int(index) < 0 or int(index) > answer_num:
|
if not is_number(index) or int(index) < 0 or int(index) > answer_num:
|
||||||
return "指定回答下标id必须为数字且在范围内"
|
return "指定回答下标id必须为数字且在范围内"
|
||||||
index = int(index)
|
index = int(index)
|
||||||
await WordBank.delete_group_problem(problem, group_id, index, word_scope)
|
if await WordBank.delete_group_problem(problem, group_id, index, word_scope):
|
||||||
return "删除词条成功"
|
return "删除词条成功"
|
||||||
|
return "词条不存在"
|
||||||
if type_ == "update":
|
if type_ == "update":
|
||||||
replace_str = params[1]
|
replace_str = params[1]
|
||||||
await WordBank.update_group_problem(problem, replace_str, group_id, word_scope=word_scope)
|
await WordBank.update_group_problem(problem, replace_str, group_id, word_scope=word_scope)
|
||||||
|
|||||||
@ -39,6 +39,7 @@ class WordBank(db.Model):
|
|||||||
answer = db.Column(db.String(), nullable=False) # 回答
|
answer = db.Column(db.String(), nullable=False) # 回答
|
||||||
placeholder = db.Column(db.String()) # 占位符
|
placeholder = db.Column(db.String()) # 占位符
|
||||||
image_path = db.Column(db.String()) # 使用图片作为问题时图片存储的路径
|
image_path = db.Column(db.String()) # 使用图片作为问题时图片存储的路径
|
||||||
|
to_me = db.Column(db.String()) # 使用图片作为问题时图片存储的路径
|
||||||
create_time = db.Column(db.DateTime(), nullable=False)
|
create_time = db.Column(db.DateTime(), nullable=False)
|
||||||
update_time = db.Column(db.DateTime(), nullable=False)
|
update_time = db.Column(db.DateTime(), nullable=False)
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ class WordBank(db.Model):
|
|||||||
word_type: int,
|
word_type: int,
|
||||||
problem: Union[str, Message],
|
problem: Union[str, Message],
|
||||||
answer: Union[str, Message],
|
answer: Union[str, Message],
|
||||||
|
to_me_nickname: str = None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
@ -96,6 +98,7 @@ class WordBank(db.Model):
|
|||||||
:param word_type: 词条类型,
|
:param word_type: 词条类型,
|
||||||
:param problem: 问题
|
:param problem: 问题
|
||||||
:param answer: 回答
|
:param answer: 回答
|
||||||
|
:param to_me_nickname: at真寻名称
|
||||||
"""
|
"""
|
||||||
# 对图片做额外处理
|
# 对图片做额外处理
|
||||||
image_path = None
|
image_path = None
|
||||||
@ -122,6 +125,7 @@ class WordBank(db.Model):
|
|||||||
placeholder=",".join(_list),
|
placeholder=",".join(_list),
|
||||||
create_time=datetime.now().replace(microsecond=0),
|
create_time=datetime.now().replace(microsecond=0),
|
||||||
update_time=datetime.now().replace(microsecond=0),
|
update_time=datetime.now().replace(microsecond=0),
|
||||||
|
to_me=to_me_nickname
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -203,6 +207,7 @@ class WordBank(db.Model):
|
|||||||
return MessageTemplate(temp_answer, Message).format(*seg_list)
|
return MessageTemplate(temp_answer, Message).format(*seg_list)
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def check(
|
async def check(
|
||||||
cls,
|
cls,
|
||||||
@ -366,25 +371,28 @@ class WordBank(db.Model):
|
|||||||
:param index: 回答下标
|
:param index: 回答下标
|
||||||
:param word_scope: 词条范围
|
:param word_scope: 词条范围
|
||||||
"""
|
"""
|
||||||
if index is not None:
|
if await cls.exists(None, group_id, problem, None, word_scope):
|
||||||
if group_id:
|
if index is not None:
|
||||||
query = await cls.query.where(
|
if group_id:
|
||||||
(cls.group_id == group_id) & (cls.problem == problem)
|
query = await cls.query.where(
|
||||||
).gino.all()
|
(cls.group_id == group_id) & (cls.problem == problem)
|
||||||
|
).gino.all()
|
||||||
|
else:
|
||||||
|
query = await cls.query.where(
|
||||||
|
(cls.word_scope == 0) & (cls.problem == problem)
|
||||||
|
).gino.all()
|
||||||
|
await query[index].delete()
|
||||||
else:
|
else:
|
||||||
query = await cls.query.where(
|
if group_id:
|
||||||
(cls.word_scope == 0) & (cls.problem == problem)
|
await WordBank.delete.where(
|
||||||
).gino.all()
|
(cls.group_id == group_id) & (cls.problem == problem)
|
||||||
await query[index].delete()
|
).gino.status()
|
||||||
else:
|
else:
|
||||||
if group_id:
|
await WordBank.delete.where(
|
||||||
await WordBank.delete.where(
|
(cls.word_scope == word_scope) & (cls.problem == problem)
|
||||||
(cls.group_id == group_id) & (cls.problem == problem)
|
).gino.status()
|
||||||
).gino.status()
|
return True
|
||||||
else:
|
return False
|
||||||
await WordBank.delete.where(
|
|
||||||
(cls.word_scope == word_scope) & (cls.problem == problem)
|
|
||||||
).gino.status()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def update_group_problem(
|
async def update_group_problem(
|
||||||
|
|||||||
@ -4,14 +4,14 @@ from io import BytesIO
|
|||||||
from services.log import logger
|
from services.log import logger
|
||||||
|
|
||||||
from nonebot.typing import T_State
|
from nonebot.typing import T_State
|
||||||
from nonebot.adapters.onebot.v11 import MessageEvent
|
from nonebot.adapters.onebot.v11 import MessageEvent, Bot
|
||||||
|
|
||||||
from utils.utils import get_message_text, get_message_img, get_message_at
|
from utils.utils import get_message_text, get_message_img, get_message_at
|
||||||
from ._model import WordBank
|
from ._model import WordBank
|
||||||
from utils.http_utils import AsyncHttpx
|
from utils.http_utils import AsyncHttpx
|
||||||
|
|
||||||
|
|
||||||
async def check(event: MessageEvent, state: T_State) -> bool:
|
async def check(bot: Bot, event: MessageEvent, state: T_State) -> bool:
|
||||||
text = get_message_text(event.message)
|
text = get_message_text(event.message)
|
||||||
img = get_message_img(event.message)
|
img = get_message_img(event.message)
|
||||||
at = get_message_at(event.message)
|
at = get_message_at(event.message)
|
||||||
@ -30,6 +30,13 @@ async def check(event: MessageEvent, state: T_State) -> bool:
|
|||||||
elif seg.type == 'text':
|
elif seg.type == 'text':
|
||||||
temp += seg.data["text"]
|
temp += seg.data["text"]
|
||||||
problem = temp
|
problem = temp
|
||||||
|
if event.to_me and bot.config.nickname:
|
||||||
|
if str(event.original_message).startswith("[CQ:at"):
|
||||||
|
problem = f"[at:{bot.self_id}]" + problem
|
||||||
|
else:
|
||||||
|
if problem and bot.config.nickname:
|
||||||
|
nickname = [nk for nk in bot.config.nickname if str(event.original_message).startswith(nk)]
|
||||||
|
problem = nickname[0] + problem if nickname else problem
|
||||||
if problem and (await WordBank.check(event, problem) is not None):
|
if problem and (await WordBank.check(event, problem) is not None):
|
||||||
state["problem"] = problem
|
state["problem"] = problem
|
||||||
return True
|
return True
|
||||||
|
|||||||
@ -139,6 +139,7 @@ async def _(
|
|||||||
|
|
||||||
@add_word.got("problem_image", prompt="请发送该回答设置的问题图片")
|
@add_word.got("problem_image", prompt="请发送该回答设置的问题图片")
|
||||||
async def _(
|
async def _(
|
||||||
|
bot: Bot,
|
||||||
event: MessageEvent,
|
event: MessageEvent,
|
||||||
word_scope: Optional[str] = ArgStr("word_scope"),
|
word_scope: Optional[str] = ArgStr("word_scope"),
|
||||||
word_type: Optional[str] = ArgStr("word_type"),
|
word_type: Optional[str] = ArgStr("word_type"),
|
||||||
@ -152,13 +153,19 @@ async def _(
|
|||||||
re.compile(problem)
|
re.compile(problem)
|
||||||
except re.error:
|
except re.error:
|
||||||
await add_word.finish(f"添加词条失败,正则表达式 {problem} 非法!")
|
await add_word.finish(f"添加词条失败,正则表达式 {problem} 非法!")
|
||||||
|
if str(event.user_id) in bot.config.superusers and isinstance(event, PrivateMessageEvent):
|
||||||
|
word_scope = "私聊"
|
||||||
|
nickname = None
|
||||||
|
if problem and bot.config.nickname:
|
||||||
|
nickname = [nk for nk in bot.config.nickname if problem.startswith(nk)]
|
||||||
await WordBank.add_problem_answer(
|
await WordBank.add_problem_answer(
|
||||||
event.user_id,
|
event.user_id,
|
||||||
event.group_id if isinstance(event, GroupMessageEvent) and (not word_scope or word_scope == '1') else 0,
|
event.group_id if isinstance(event, GroupMessageEvent) and (not word_scope or word_scope == '私聊') else 0,
|
||||||
scope2int[word_scope] if word_scope else 1,
|
scope2int[word_scope] if word_scope else 1,
|
||||||
type2int[word_type] if word_type else 0,
|
type2int[word_type] if word_type else 0,
|
||||||
problem or problem_image,
|
problem or problem_image,
|
||||||
answer,
|
answer,
|
||||||
|
nickname[0] if nickname else None
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if isinstance(e, FinishedException):
|
if isinstance(e, FinishedException):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user