Skip to content

Commit

Permalink
Documentation for mojang.session.UserSession class
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucino772 committed Mar 25, 2021
1 parent 5e9c091 commit d0b590a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/PyMojang/UserSession.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Mojang - User Session
===

::: mojang.session.UserSession
handler: python
rendering:
show_root_heading: true
show_source: true
39 changes: 36 additions & 3 deletions mojang/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@


class UserSession(UserProfile):
"""This class represent a Mojang authenticated user
Attributes:
name (str): The player name
uuid (str): The player uuid
is_legacy (str): True if user has not migrated to mojang account
is_demo (str): True if user has not paid
names (str): The player name history
created_at (datetime): The player date of creation
name_change_allowed (str): True if player can change name
skins (str): The list of skins
capes (str): The list of capes
"""

def __init__(self, access_token: str, client_token: str):
super().__init__()
Expand Down Expand Up @@ -41,33 +54,53 @@ def _fetch_data(self):
self.capes = data['capes']

def close(self):
"""Close current session"""
yggdrasil.invalidate_token(self.__access_token, self.__client_token)
self.__access_token = None
self.__client_token = None

# Security
@property
def secure(self):
def secure(self) -> bool:
"""Return if user IP is verified"""
return security.is_user_ip_secure(self.__access_token)

@property
def challenges(self):
def challenges(self) -> list:
"""Return the list of challenges to verify user IP"""
return security.get_user_challenges(self.__access_token)

def verify(self, answers: list):
def verify(self, answers: list) -> bool:
"""Verify user IP
Args:
answers (list): The answers to verify the IP
"""
return security.verify_user_ip(self.__access_token, answers)

# Name
def change_name(self, name: str):
"""Change user name, and update profile data
Args:
name (str): The new user name
"""
session.change_user_name(self.__access_token, name)
self._fetch_data()

# Skin
def change_skin(self, path: str, variant='classic'):
"""Change user skin, and update profile data
Args:
path (str): The path to the skin
variant (str, optional): The skin variant, either `classic` or `slim`
"""
session.change_user_skin(self.__access_token, path, variant)
self._fetch_data()

def reset_skin(self):
"""Reset user skin, and update profile data"""
session.reset_user_skin(self.__access_token, self.uuid)
self._fetch_data()

0 comments on commit d0b590a

Please sign in to comment.