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