This commit is contained in:
DarkCat09 2022-10-05 19:59:28 +04:00
parent 0e9aac19b2
commit 91627a8af9

View file

@ -54,7 +54,8 @@ class Client:
username: str, username: str,
md5: str, md5: str,
code: Optional[int] = None, code: Optional[int] = None,
sessions_dir: str = '~'): sessions_dir: str = '~',
**custom_args):
"""Log in to an Aternos account with """Log in to an Aternos account with
a username and a hashed password a username and a hashed password
@ -65,6 +66,8 @@ class Client:
code (Optional[int]): 2FA code code (Optional[int]): 2FA code
sessions_dir (str): Path to the directory sessions_dir (str): Path to the directory
where session will be automatically saved where session will be automatically saved
**custom_args (tuple, optional): Keyword arguments
which will be passed to CloudScraper `__init__`
Raises: Raises:
CredentialsError: If the API didn't CredentialsError: If the API didn't
@ -73,6 +76,9 @@ class Client:
atconn = AternosConnect() atconn = AternosConnect()
if len(custom_args) > 0:
atconn.add_args(**custom_args)
filename = cls.session_file( filename = cls.session_file(
username, sessions_dir username, sessions_dir
) )
@ -122,7 +128,8 @@ class Client:
username: str, username: str,
password: str, password: str,
code: Optional[int] = None, code: Optional[int] = None,
sessions_dir: str = '~'): sessions_dir: str = '~',
**custom_args):
"""Log in to Aternos with a username and a plain password """Log in to Aternos with a username and a plain password
@ -132,41 +139,54 @@ class Client:
code (Optional[int]): 2FA code code (Optional[int]): 2FA code
sessions_dir (str): Path to the directory sessions_dir (str): Path to the directory
where session will be automatically saved where session will be automatically saved
**custom_args (tuple, optional): Keyword arguments
which will be passed to CloudScraper `__init__`
""" """
md5 = Client.md5encode(password) md5 = Client.md5encode(password)
return cls.from_hashed( return cls.from_hashed(
username, md5, code, username, md5, code,
sessions_dir sessions_dir, **custom_args
) )
@classmethod @classmethod
def from_session( def from_session(
cls, cls,
session: str, session: str,
servers: Optional[List[str]] = None): servers: Optional[List[str]] = None,
**custom_args):
"""Log in to Aternos using a session cookie value """Log in to Aternos using a session cookie value
Args: Args:
session (str): Value of ATERNOS_SESSION cookie session (str): Value of ATERNOS_SESSION cookie
**custom_args (tuple, optional): Keyword arguments
which will be passed to CloudScraper `__init__`
""" """
atconn = AternosConnect() atconn = AternosConnect()
atconn.add_args(**custom_args)
atconn.session.cookies['ATERNOS_SESSION'] = session atconn.session.cookies['ATERNOS_SESSION'] = session
atconn.parse_token() atconn.parse_token()
atconn.generate_sec() atconn.generate_sec()
return cls(atconn, servers) return cls(atconn, servers)
@classmethod @classmethod
def restore_session(cls, file: str = '~/.aternos'): def restore_session(
cls,
file: str = '~/.aternos',
**custom_args):
"""Log in to Aternos using """Log in to Aternos using
a saved ATERNOS_SESSION cookie a saved ATERNOS_SESSION cookie
Args: Args:
file (str, optional): File where a session cookie was saved file (str, optional): File where a session cookie was saved
**custom_args (tuple, optional): Keyword arguments
which will be passed to CloudScraper `__init__`
""" """
file = os.path.expanduser(file) file = os.path.expanduser(file)
@ -191,10 +211,14 @@ class Client:
if len(saved) > 1: if len(saved) > 1:
obj = cls.from_session( obj = cls.from_session(
session=session, session=session,
servers=saved[1:] servers=saved[1:],
**custom_args
) )
else: else:
obj = cls.from_session(session) obj = cls.from_session(
session,
**custom_args
)
obj.saved_session = file obj.saved_session = file