Skip to content

Commit

Permalink
feat: configを使うように
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed May 28, 2022
1 parent 0b253bb commit b14f5e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions mipac/client.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from typing import Optional
from mipac.config import Config
from mipac.http import HTTPClient
from mipac.manager.client import ClientActions


class Client:
def __init__(self, url: str, token: str):
def __init__(self, url: str, token: str, *, config:Optional[Config]=None):
self.__url: str = url
self.__token: str = token
self.__config: Config = config if config else Config()
self.http: HTTPClient = HTTPClient(url, token)

@property
def action(self):
return ClientActions(self.http)
return ClientActions(self.http, self.__config)

async def close_session(self):
await self.http.close_session()
4 changes: 3 additions & 1 deletion mipac/manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

if TYPE_CHECKING:
from mipac.models.user import User
from mipac.config import Config

__all__ = ('ClientActions',)


class ClientActions:
def __init__(self, session: HTTPClient):
def __init__(self, session: HTTPClient, config: Config):
self.__session: HTTPClient = session
self.note: NoteManager = NoteManager(session=session, client=self)
self.chat: ChatManager = ChatManager(session=session, client=self)
Expand All @@ -29,6 +30,7 @@ def __init__(self, session: HTTPClient):
session=session, client=self
)
self.chart: ChartManager = ChartManager(session=session, client=self)
self._config: Config = config

def _create_user_instance(self, user: User) -> UserManager:
return UserManager(session=self.__session, client=self, user=user)
Expand Down
2 changes: 1 addition & 1 deletion mipac/manager/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def add(
category: Optional[str] = None,
aliases: Optional[List[str]] = None
) -> bool:
if config.is_ayuskey: # TODO: どうにかする
if self.__client._config.is_ayuskey:
data = {
'name': name,
'url': url,
Expand Down

0 comments on commit b14f5e8

Please sign in to comment.