mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +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
|
||||
|
||||
* 重写帮助,删除 `详细帮助` 命令
|
||||
|
||||
@ -25,6 +25,5 @@ withdraw_msg = on_command("撤回", priority=5, block=True)
|
||||
|
||||
@withdraw_msg.handle()
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
r = re.search(r"\[CQ:reply,id=(-?\d*)]", event.raw_message)
|
||||
if r:
|
||||
await bot.delete_msg(message_id=int(r.group(1)))
|
||||
if event.reply:
|
||||
await bot.delete_msg(message_id=event.reply.message_id)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
from configs.config import Config
|
||||
from utils.utils import GDict
|
||||
import nonebot
|
||||
|
||||
Config.add_plugin_config(
|
||||
@ -10,4 +11,6 @@ Config.add_plugin_config(
|
||||
default_value=5
|
||||
)
|
||||
|
||||
GDict['run_sql'].append("ALTER TABLE word_bank2 ADD to_me VARCHAR(255);")
|
||||
|
||||
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:
|
||||
return "指定回答下标id必须为数字且在范围内"
|
||||
index = int(index)
|
||||
await WordBank.delete_group_problem(problem, group_id, index, word_scope)
|
||||
return "删除词条成功"
|
||||
if await WordBank.delete_group_problem(problem, group_id, index, word_scope):
|
||||
return "删除词条成功"
|
||||
return "词条不存在"
|
||||
if type_ == "update":
|
||||
replace_str = params[1]
|
||||
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) # 回答
|
||||
placeholder = db.Column(db.String()) # 占位符
|
||||
image_path = db.Column(db.String()) # 使用图片作为问题时图片存储的路径
|
||||
to_me = db.Column(db.String()) # 使用图片作为问题时图片存储的路径
|
||||
create_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,
|
||||
problem: Union[str, Message],
|
||||
answer: Union[str, Message],
|
||||
to_me_nickname: str = None
|
||||
):
|
||||
"""
|
||||
说明:
|
||||
@ -96,6 +98,7 @@ class WordBank(db.Model):
|
||||
:param word_type: 词条类型,
|
||||
:param problem: 问题
|
||||
:param answer: 回答
|
||||
:param to_me_nickname: at真寻名称
|
||||
"""
|
||||
# 对图片做额外处理
|
||||
image_path = None
|
||||
@ -122,6 +125,7 @@ class WordBank(db.Model):
|
||||
placeholder=",".join(_list),
|
||||
create_time=datetime.now().replace(microsecond=0),
|
||||
update_time=datetime.now().replace(microsecond=0),
|
||||
to_me=to_me_nickname
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@ -203,6 +207,7 @@ class WordBank(db.Model):
|
||||
return MessageTemplate(temp_answer, Message).format(*seg_list)
|
||||
return answer
|
||||
|
||||
|
||||
@classmethod
|
||||
async def check(
|
||||
cls,
|
||||
@ -366,25 +371,28 @@ class WordBank(db.Model):
|
||||
:param index: 回答下标
|
||||
:param word_scope: 词条范围
|
||||
"""
|
||||
if index is not None:
|
||||
if group_id:
|
||||
query = await cls.query.where(
|
||||
(cls.group_id == group_id) & (cls.problem == problem)
|
||||
).gino.all()
|
||||
if await cls.exists(None, group_id, problem, None, word_scope):
|
||||
if index is not None:
|
||||
if group_id:
|
||||
query = await cls.query.where(
|
||||
(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:
|
||||
query = await cls.query.where(
|
||||
(cls.word_scope == 0) & (cls.problem == problem)
|
||||
).gino.all()
|
||||
await query[index].delete()
|
||||
else:
|
||||
if group_id:
|
||||
await WordBank.delete.where(
|
||||
(cls.group_id == group_id) & (cls.problem == problem)
|
||||
).gino.status()
|
||||
else:
|
||||
await WordBank.delete.where(
|
||||
(cls.word_scope == word_scope) & (cls.problem == problem)
|
||||
).gino.status()
|
||||
if group_id:
|
||||
await WordBank.delete.where(
|
||||
(cls.group_id == group_id) & (cls.problem == problem)
|
||||
).gino.status()
|
||||
else:
|
||||
await WordBank.delete.where(
|
||||
(cls.word_scope == word_scope) & (cls.problem == problem)
|
||||
).gino.status()
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def update_group_problem(
|
||||
|
||||
@ -4,14 +4,14 @@ from io import BytesIO
|
||||
from services.log import logger
|
||||
|
||||
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 ._model import WordBank
|
||||
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)
|
||||
img = get_message_img(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':
|
||||
temp += seg.data["text"]
|
||||
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):
|
||||
state["problem"] = problem
|
||||
return True
|
||||
|
||||
@ -139,6 +139,7 @@ async def _(
|
||||
|
||||
@add_word.got("problem_image", prompt="请发送该回答设置的问题图片")
|
||||
async def _(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
word_scope: Optional[str] = ArgStr("word_scope"),
|
||||
word_type: Optional[str] = ArgStr("word_type"),
|
||||
@ -152,13 +153,19 @@ async def _(
|
||||
re.compile(problem)
|
||||
except re.error:
|
||||
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(
|
||||
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,
|
||||
type2int[word_type] if word_type else 0,
|
||||
problem or problem_image,
|
||||
answer,
|
||||
nickname[0] if nickname else None
|
||||
)
|
||||
except Exception as e:
|
||||
if isinstance(e, FinishedException):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user