Skip to content

Commit

Permalink
分离repo层
Browse files Browse the repository at this point in the history
  • Loading branch information
ssttkkl committed Nov 26, 2023
1 parent 118a94c commit 67dbffc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions nonebot_plugin_nagabus/data/naga_cookies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from collections.abc import Mapping

from ..datastore import plugin_data


async def get_naga_cookies() -> dict:
return await plugin_data.config.get("naga_cookies", {})


async def set_naga_cookies(cookies: Mapping[str, str]):
await plugin_data.config.set("naga_cookies", cookies)
6 changes: 3 additions & 3 deletions nonebot_plugin_nagabus/naga/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from ..config import conf
from ..utils.tz import TZ_TOKYO
from .fake_api import FakeNagaApi
from ..datastore import plugin_data
from .utils import model_type_to_str
from ..data.mjs import get_majsoul_paipu
from .api import NagaApi, OrderReportList
from ..data.naga_cookies import get_naga_cookies, set_naga_cookies
from .errors import (
OrderError,
InvalidGameError,
Expand Down Expand Up @@ -120,14 +120,14 @@ def __init__(self):
self._order_report = ObservableOrderReport(self.api)

async def start(self):
cookies_obj = await plugin_data.config.get("naga_cookies", {})
cookies_obj = await get_naga_cookies()
self.cookies = Cookies(cookies_obj)

async def close(self):
await self.api.close()

async def set_cookies(self, cookies: Mapping[str, str]):
await plugin_data.config.set("naga_cookies", cookies)
await set_naga_cookies(cookies)
self.cookies = Cookies(dict(cookies))
logger.info(
f"naga_cookies set to {'; '.join(f'{kv[0]}={kv[1]}' for kv in cookies.items())}"
Expand Down

0 comments on commit 67dbffc

Please sign in to comment.