From af246df22201a3246fc680cd60f5089daa85b049 Mon Sep 17 00:00:00 2001 From: suyiiyii Date: Fri, 13 Sep 2024 00:35:14 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BF=BA=E5=8F=88=E6=9D=A5?= =?UTF-8?q?=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93=E5=93=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_bison/config/db_model.py | 14 ++++++++++++-- ...22_add_cookie.py => ef796b74b0fe_add_cookie.py} | 9 +++++---- 2 files changed, 17 insertions(+), 6 deletions(-) rename nonebot_bison/config/migrations/{be215495b122_add_cookie.py => ef796b74b0fe_add_cookie.py} (90%) diff --git a/nonebot_bison/config/db_model.py b/nonebot_bison/config/db_model.py index fcd33bc..54ea825 100644 --- a/nonebot_bison/config/db_model.py +++ b/nonebot_bison/config/db_model.py @@ -79,14 +79,24 @@ class Cookie(Model): # Cookie 当前的状态 status: Mapped[str] = mapped_column(String(20), default="") # 使用一次之后,需要的冷却时间 - cd: Mapped[int] = mapped_column(default=0) - # 是否是通用 Cookie,默认用于匿名 Cookie + cd_milliseconds: Mapped[int] = mapped_column(default=0) + # 是否是通用 Cookie(对所有Target都有效) is_universal: Mapped[bool] = mapped_column(default=False) + # 是否是匿名 Cookie + is_anonymous: Mapped[bool] = mapped_column(default=False) # 标签,扩展用 tags: Mapped[dict[str, Any]] = mapped_column(JSON().with_variant(JSONB, "postgresql"), default={}) targets: Mapped[list["CookieTarget"]] = relationship(back_populates="cookie") + @property + def cd(self) -> datetime.timedelta: + return datetime.timedelta(milliseconds=self.cd_milliseconds) + + @cd.setter + def cd(self, value: datetime.timedelta): + self.cd_milliseconds = int(value.total_seconds() * 1000) + class CookieTarget(Model): id: Mapped[int] = mapped_column(primary_key=True) diff --git a/nonebot_bison/config/migrations/be215495b122_add_cookie.py b/nonebot_bison/config/migrations/ef796b74b0fe_add_cookie.py similarity index 90% rename from nonebot_bison/config/migrations/be215495b122_add_cookie.py rename to nonebot_bison/config/migrations/ef796b74b0fe_add_cookie.py index 87e7bb1..01d5d4a 100644 --- a/nonebot_bison/config/migrations/be215495b122_add_cookie.py +++ b/nonebot_bison/config/migrations/ef796b74b0fe_add_cookie.py @@ -1,8 +1,8 @@ """empty message -Revision ID: be215495b122 +Revision ID: ef796b74b0fe Revises: f9baef347cc8 -Create Date: 2024-09-08 18:12:43.540818 +Create Date: 2024-09-13 00:34:08.601438 """ @@ -12,7 +12,7 @@ from sqlalchemy import Text from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. -revision = "be215495b122" +revision = "ef796b74b0fe" down_revision = "f9baef347cc8" branch_labels = None depends_on = None @@ -27,8 +27,9 @@ def upgrade() -> None: sa.Column("content", sa.String(length=1024), nullable=False), sa.Column("last_usage", sa.DateTime(), nullable=False), sa.Column("status", sa.String(length=20), nullable=False), - sa.Column("cd", sa.Integer(), nullable=False), + sa.Column("cd_milliseconds", sa.Integer(), nullable=False), sa.Column("is_universal", sa.Boolean(), nullable=False), + sa.Column("is_anonymous", sa.Boolean(), nullable=False), sa.Column("tags", sa.JSON().with_variant(postgresql.JSONB(astext_type=Text()), "postgresql"), nullable=False), sa.PrimaryKeyConstraint("id", name=op.f("pk_nonebot_bison_cookie")), )