mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 03:46:10 +08:00
update
This commit is contained in:
parent
d80c71d4a1
commit
06e4c9ec1b
@ -1,6 +1,7 @@
|
||||
import os
|
||||
from collections import defaultdict
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from typing import DefaultDict, Literal, Mapping, TypedDict
|
||||
|
||||
import nonebot
|
||||
@ -53,18 +54,24 @@ class ConfigContent(TypedDict):
|
||||
|
||||
|
||||
class Config(metaclass=Singleton):
|
||||
"Dropping it!"
|
||||
|
||||
migrate_version = 2
|
||||
|
||||
def __init__(self):
|
||||
self.db = TinyDB(get_config_path(), encoding="utf-8")
|
||||
self.kv_config = self.db.table("kv")
|
||||
self.user_target = self.db.table("user_target")
|
||||
self.target_user_cache: dict[str, defaultdict[Target, list[User]]] = {}
|
||||
self.target_user_cat_cache = {}
|
||||
self.target_user_tag_cache = {}
|
||||
self.target_list = {}
|
||||
self.next_index: DefaultDict[str, int] = defaultdict(lambda: 0)
|
||||
path = get_config_path()
|
||||
if Path(path).exists():
|
||||
self.available = True
|
||||
self.db = TinyDB(get_config_path(), encoding="utf-8")
|
||||
self.kv_config = self.db.table("kv")
|
||||
self.user_target = self.db.table("user_target")
|
||||
self.target_user_cache: dict[str, defaultdict[Target, list[User]]] = {}
|
||||
self.target_user_cat_cache = {}
|
||||
self.target_user_tag_cache = {}
|
||||
self.target_list = {}
|
||||
self.next_index: DefaultDict[str, int] = defaultdict(lambda: 0)
|
||||
else:
|
||||
self.available = False
|
||||
|
||||
def add_subscribe(
|
||||
self, user, user_type, target, target_name, target_type, cats, tags
|
||||
|
@ -8,11 +8,20 @@ from nonebot.log import logger
|
||||
from nonebot_plugin_datastore import PluginData, create_session, db
|
||||
from sqlalchemy.engine.base import Connection
|
||||
|
||||
from .config_legacy import ConfigContent, config
|
||||
from .db_model import Base
|
||||
|
||||
DATA = PluginData("bison")
|
||||
|
||||
|
||||
async def data_migrate():
|
||||
if config.available:
|
||||
logger.warning("You are still using legacy db, migrating to sqlite")
|
||||
all_subs: list[ConfigContent] = list(
|
||||
map(lambda item: ConfigContent(**item), config.get_all_subscribe().all())
|
||||
)
|
||||
|
||||
|
||||
@nonebot.get_driver().on_startup
|
||||
async def upgrade_db():
|
||||
alembic_cfg = Config()
|
||||
@ -35,3 +44,5 @@ async def upgrade_db():
|
||||
|
||||
async with engine.connect() as connection:
|
||||
await connection.run_sync(do_run_migration)
|
||||
|
||||
await data_migrate()
|
||||
|
@ -1,11 +1,11 @@
|
||||
import time
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Collection, Literal, Optional
|
||||
|
||||
import httpx
|
||||
from nonebot.log import logger
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
from ..plugin_config import plugin_config
|
||||
from ..post import Post
|
||||
|
@ -1,4 +1,4 @@
|
||||
from dataclasses import dataclass, field
|
||||
from dataclasses import field
|
||||
from functools import reduce
|
||||
from io import BytesIO
|
||||
from typing import Optional, Union
|
||||
@ -7,6 +7,7 @@ import httpx
|
||||
from nonebot.adapters.onebot.v11.message import Message, MessageSegment
|
||||
from nonebot.log import logger
|
||||
from PIL import Image
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
from .plugin_config import plugin_config
|
||||
from .utils import parse_text
|
||||
|
@ -1,6 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Callable, Literal, NamedTuple, NewType
|
||||
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
RawPost = NewType("RawPost", Any)
|
||||
Target = NewType("Target", str)
|
||||
Category = int
|
||||
|
Loading…
x
Reference in New Issue
Block a user