updating namings in user.py and channel.py to stay coherent

This commit is contained in:
adator
2025-08-09 03:53:57 +02:00
parent f3fe3c43cb
commit 5629dcfde6
2 changed files with 40 additions and 41 deletions

View File

@@ -185,29 +185,29 @@ class Channel:
return channel_obj.to_dict() return channel_obj.to_dict()
def Is_Channel(self, channelToCheck: str) -> bool: def Is_Channel(self, channel_to_check: str) -> bool:
"""Check if the string has the # caractere and return True if this is a channel """Check if the string has the # caractere and return True if this is a channel
Args: Args:
channelToCheck (str): The string to test if it is a channel or not channel_to_check (str): The string to test if it is a channel or not
Returns: Returns:
bool: True if the string is a channel / False if this is not a channel bool: True if the string is a channel / False if this is not a channel
""" """
try: try:
if channelToCheck is None: if channel_to_check is None:
return False return False
pattern = fr'^#' pattern = fr'^#'
isChannel = findall(pattern, channelToCheck) isChannel = findall(pattern, channel_to_check)
if not isChannel: if not isChannel:
return False return False
else: else:
return True return True
except TypeError as te: except TypeError as te:
self.Logs.error(f'TypeError: [{channelToCheck}] - {te}') self.Logs.error(f'TypeError: [{channel_to_check}] - {te}')
except Exception as err: except Exception as err:
self.Logs.error(f'Error Not defined: {err}') self.Logs.error(f'Error Not defined: {err}')

View File

@@ -18,7 +18,7 @@ class User:
return None return None
def insert(self, newUser: 'MUser') -> bool: def insert(self, new_user: 'MUser') -> bool:
"""Insert a new User object """Insert a new User object
Args: Args:
@@ -28,32 +28,32 @@ class User:
bool: True if inserted bool: True if inserted
""" """
userObj = self.get_User(newUser.uid) user_obj = self.get_User(new_user.uid)
if not userObj is None: if not user_obj is None:
# User already created return False # User already created return False
return False return False
self.UID_DB.append(newUser) self.UID_DB.append(new_user)
return True return True
def update_nickname(self, uid: str, newNickname: str) -> bool: def update_nickname(self, uid: str, new_nickname: str) -> bool:
"""Update the nickname starting from the UID """Update the nickname starting from the UID
Args: Args:
uid (str): UID of the user uid (str): UID of the user
newNickname (str): New nickname new_nickname (str): New nickname
Returns: Returns:
bool: True if updated bool: True if updated
""" """
userObj = self.get_User(uidornickname=uid) user_obj = self.get_User(uidornickname=uid)
if userObj is None: if user_obj is None:
return False return False
userObj.nickname = newNickname user_obj.nickname = new_nickname
return True return True
@@ -68,16 +68,16 @@ class User:
bool: True if user mode has been updaed bool: True if user mode has been updaed
""" """
response = True response = True
userObj = self.get_User(uidornickname=uidornickname) user_obj = self.get_User(uidornickname=uidornickname)
if userObj is None: if user_obj is None:
return False return False
action = modes[0] action = modes[0]
new_modes = modes[1:] new_modes = modes[1:]
existing_umodes = userObj.umodes existing_umodes = user_obj.umodes
umodes = userObj.umodes umodes = user_obj.umodes
if action == '+': if action == '+':
@@ -96,7 +96,7 @@ class User:
final_umodes_liste = [x for x in self.Base.Settings.PROTOCTL_USER_MODES if x in liste_umodes] final_umodes_liste = [x for x in self.Base.Settings.PROTOCTL_USER_MODES if x in liste_umodes]
final_umodes = ''.join(final_umodes_liste) final_umodes = ''.join(final_umodes_liste)
userObj.umodes = f"+{final_umodes}" user_obj.umodes = f"+{final_umodes}"
return response return response
@@ -110,16 +110,16 @@ class User:
bool: True if deleted bool: True if deleted
""" """
userObj = self.get_User(uidornickname=uid) user_obj = self.get_User(uidornickname=uid)
if userObj is None: if user_obj is None:
return False return False
self.UID_DB.remove(userObj) self.UID_DB.remove(user_obj)
return True return True
def get_User(self, uidornickname: str) -> Union['MUser', None]: def get_User(self, uidornickname: str) -> Optional['MUser']:
"""Get The User Object model """Get The User Object model
Args: Args:
@@ -128,16 +128,15 @@ class User:
Returns: Returns:
UserModel|None: The UserModel Object | None UserModel|None: The UserModel Object | None
""" """
User = None
for record in self.UID_DB: for record in self.UID_DB:
if record.uid == uidornickname: if record.uid == uidornickname:
User = record return record
elif record.nickname == uidornickname: elif record.nickname == uidornickname:
User = record return record
return User return None
def get_uid(self, uidornickname:str) -> Union[str, None]: def get_uid(self, uidornickname:str) -> Optional[str]:
"""Get the UID of the user starting from the UID or the Nickname """Get the UID of the user starting from the UID or the Nickname
Args: Args:
@@ -147,14 +146,14 @@ class User:
str|None: Return the UID str|None: Return the UID
""" """
userObj = self.get_User(uidornickname=uidornickname) user_obj = self.get_User(uidornickname=uidornickname)
if userObj is None: if user_obj is None:
return None return None
return userObj.uid return user_obj.uid
def get_nickname(self, uidornickname:str) -> Union[str, None]: def get_nickname(self, uidornickname:str) -> Optional[str]:
"""Get the Nickname starting from UID or the nickname """Get the Nickname starting from UID or the nickname
Args: Args:
@@ -163,12 +162,12 @@ class User:
Returns: Returns:
str|None: the nickname str|None: the nickname
""" """
userObj = self.get_User(uidornickname=uidornickname) user_obj = self.get_User(uidornickname=uidornickname)
if userObj is None: if user_obj is None:
return None return None
return userObj.nickname return user_obj.nickname
def get_user_asdict(self, uidornickname: str) -> Optional[dict[str, Any]]: def get_user_asdict(self, uidornickname: str) -> Optional[dict[str, Any]]:
"""Transform User Object to a dictionary """Transform User Object to a dictionary
@@ -179,12 +178,12 @@ class User:
Returns: Returns:
Union[dict[str, any], None]: User Object as a dictionary or None Union[dict[str, any], None]: User Object as a dictionary or None
""" """
userObj = self.get_User(uidornickname=uidornickname) user_obj = self.get_User(uidornickname=uidornickname)
if userObj is None: if user_obj is None:
return None return None
return userObj.to_dict() return user_obj.to_dict()
def is_exist(self, uidornikname: str) -> bool: def is_exist(self, uidornikname: str) -> bool:
"""Check if the UID or the nickname exist in the USER DB """Check if the UID or the nickname exist in the USER DB
@@ -195,14 +194,14 @@ class User:
Returns: Returns:
bool: True if exist bool: True if exist
""" """
userObj = self.get_User(uidornickname=uidornikname) user_obj = self.get_User(uidornickname=uidornikname)
if userObj is None: if user_obj is None:
return False return False
return True return True
def clean_uid(self, uid: str) -> Union[str, None]: def clean_uid(self, uid: str) -> Optional[str]:
"""Clean UID by removing @ / % / + / ~ / * / : """Clean UID by removing @ / % / + / ~ / * / :
Args: Args: