mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
修复新用户无法添加待办的bug
修复用户输入为空仍然新建待办的bug
This commit is contained in:
parent
1d42541475
commit
4db13c6732
2 changed files with 39 additions and 4 deletions
|
|
@ -35,18 +35,26 @@ class ToDoList(Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def insert_todo_list(cls, user_id: str | None, content: str | None):
|
async def insert_todo_list(cls, user_id: str | None, content: str | None) -> bool:
|
||||||
|
|
||||||
|
is_user = await UserList.get_user_data(user_id)
|
||||||
|
if not is_user:
|
||||||
|
await UserList.insert_user(user_id)
|
||||||
|
|
||||||
|
if content.lstrip(" ") == "":
|
||||||
|
return False
|
||||||
data = {
|
data = {
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"content": content
|
"content": content
|
||||||
}
|
}
|
||||||
await cls.create(**data)
|
await cls.create(**data)
|
||||||
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def delete_user_todo(cls, user_id: str | None, del_line_num: int | None) -> int:
|
async def delete_user_todo(cls, user_id: str | None, del_line_num: int | None) -> int:
|
||||||
todo_table = await cls._get_data(user_id)
|
todo_table = await cls._get_data(user_id)
|
||||||
|
|
||||||
if todo_table is None:
|
if not todo_table:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
max_length = len(todo_table)
|
max_length = len(todo_table)
|
||||||
|
|
@ -58,3 +66,27 @@ class ToDoList(Model):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
class UserList(Model):
|
||||||
|
user_id = fields.CharField(max_length=100, description="用户member_openid")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
table = "user_list"
|
||||||
|
table_description = "用户表"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def get_user_data(cls, user_id: str | None) -> list | None:
|
||||||
|
if not user_id:
|
||||||
|
print("用户id为空")
|
||||||
|
else:
|
||||||
|
return (
|
||||||
|
await cls.filter(user_id=user_id).order_by("id").values_list("user_id")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def insert_user(cls, user_id: str | None):
|
||||||
|
data = {
|
||||||
|
"user_id": user_id
|
||||||
|
}
|
||||||
|
await cls.create(**data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,11 @@ async def insert_todo_list(message: MessageEvent):
|
||||||
member_openid = message.get_user_id()
|
member_openid = message.get_user_id()
|
||||||
content = message.get_plaintext().replace("/新建待办", "").strip(" ")
|
content = message.get_plaintext().replace("/新建待办", "").strip(" ")
|
||||||
# insert_user_todo_list(member_openid, content)
|
# insert_user_todo_list(member_openid, content)
|
||||||
await ToDoList.insert_todo_list(member_openid, content)
|
success = await ToDoList.insert_todo_list(member_openid, content)
|
||||||
|
if success:
|
||||||
await insert_todo.finish("成功添加待办,今后也要加油哦(ง •_•)ง")
|
await insert_todo.finish("成功添加待办,今后也要加油哦(ง •_•)ง")
|
||||||
|
else:
|
||||||
|
await insert_todo.finish("\n请输入 /新建待办+待办内容 哦")
|
||||||
|
|
||||||
|
|
||||||
delete_todo = on_command("删除待办", rule=to_me(), priority=10, block=True)
|
delete_todo = on_command("删除待办", rule=to_me(), priority=10, block=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue