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()
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
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:
bool: True if the string is a channel / False if this is not a channel
"""
try:
if channelToCheck is None:
if channel_to_check is None:
return False
pattern = fr'^#'
isChannel = findall(pattern, channelToCheck)
isChannel = findall(pattern, channel_to_check)
if not isChannel:
return False
else:
return True
except TypeError as te:
self.Logs.error(f'TypeError: [{channelToCheck}] - {te}')
self.Logs.error(f'TypeError: [{channel_to_check}] - {te}')
except Exception as err:
self.Logs.error(f'Error Not defined: {err}')

View File

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