Adding some comments, editing methods names (admin.py)

This commit is contained in:
adator85
2025-08-15 16:14:35 +02:00
parent 6b22d786e3
commit 9e255e806d
3 changed files with 82 additions and 42 deletions

View File

@@ -10,62 +10,78 @@ class Admin:
self.Logs = base.logs self.Logs = base.logs
def insert(self, new_admin: df.MAdmin) -> bool: def insert(self, new_admin: df.MAdmin) -> bool:
"""Insert a new admin object model
result = False Args:
exist = False new_admin (MAdmin): The new admin object model to insert
Returns:
bool: True if it was inserted
"""
for record in self.UID_ADMIN_DB: for record in self.UID_ADMIN_DB:
if record.uid == new_admin.uid: if record.uid == new_admin.uid:
# If the admin exist then return False and do not go further # If the admin exist then return False and do not go further
exist = True
self.Logs.debug(f'{record.uid} already exist') self.Logs.debug(f'{record.uid} already exist')
return result return False
if not exist:
self.UID_ADMIN_DB.append(new_admin) self.UID_ADMIN_DB.append(new_admin)
result = True self.Logs.debug(f'A new admin ({new_admin.nickname}) has been created')
self.Logs.debug(f'UID ({new_admin.uid}) has been created') return True
if not result:
self.Logs.critical(f'The User Object was not inserted {new_admin}')
return result
def update_nickname(self, uid: str, new_admin_nickname: str) -> bool: def update_nickname(self, uid: str, new_admin_nickname: str) -> bool:
"""Update nickname of an admin
result = False Args:
uid (str): The Admin UID
new_admin_nickname (str): The new nickname of the admin
Returns:
bool: True if the nickname has been updated.
"""
for record in self.UID_ADMIN_DB: for record in self.UID_ADMIN_DB:
if record.uid == uid: if record.uid == uid:
# If the admin exist, update and do not go further # If the admin exist, update and do not go further
record.nickname = new_admin_nickname record.nickname = new_admin_nickname
result = True
self.Logs.debug(f'UID ({record.uid}) has been updated with new nickname {new_admin_nickname}') self.Logs.debug(f'UID ({record.uid}) has been updated with new nickname {new_admin_nickname}')
return result return True
if not result:
self.Logs.debug(f'The new nickname {new_admin_nickname} was not updated, uid = {uid} - The Client is not an admin') self.Logs.debug(f'The new nickname {new_admin_nickname} was not updated, uid = {uid} - The Client is not an admin')
return False
return result
def update_level(self, nickname: str, new_admin_level: int) -> bool: def update_level(self, nickname: str, new_admin_level: int) -> bool:
"""Update the admin level
result = False Args:
nickname (str): The admin nickname
new_admin_level (int): The new level of the admin
Returns:
bool: True if the admin level has been updated
"""
for record in self.UID_ADMIN_DB: for record in self.UID_ADMIN_DB:
if record.nickname == nickname: if record.nickname == nickname:
# If the admin exist, update and do not go further # If the admin exist, update and do not go further
record.level = new_admin_level record.level = new_admin_level
result = True
self.Logs.debug(f'Admin ({record.nickname}) has been updated with new level {new_admin_level}') self.Logs.debug(f'Admin ({record.nickname}) has been updated with new level {new_admin_level}')
return result return True
if not result:
self.Logs.debug(f'The new level {new_admin_level} was not updated, nickname = {nickname} - The Client is not an admin') self.Logs.debug(f'The new level {new_admin_level} was not updated, nickname = {nickname} - The Client is not an admin')
return result return False
def delete(self, uidornickname: str) -> bool: def delete(self, uidornickname: str) -> bool:
"""Delete admin
Args:
uidornickname (str): The UID or nickname of the admin
Returns:
bool: True if the admin has been deleted
"""
for record in self.UID_ADMIN_DB: for record in self.UID_ADMIN_DB:
if record.uid == uidornickname: if record.uid == uidornickname:
@@ -73,40 +89,64 @@ class Admin:
self.UID_ADMIN_DB.remove(record) self.UID_ADMIN_DB.remove(record)
self.Logs.debug(f'UID ({record.uid}) has been deleted') self.Logs.debug(f'UID ({record.uid}) has been deleted')
return True return True
if record.nickname == uidornickname: if record.nickname.lower() == uidornickname.lower():
# If the admin exist, delete and do not go further # If the admin exist, delete and do not go further
self.UID_ADMIN_DB.remove(record) self.UID_ADMIN_DB.remove(record)
self.Logs.debug(f'nickname ({record.nickname}) has been deleted') self.Logs.debug(f'nickname ({record.nickname}) has been deleted')
return True return True
self.Logs.critical(f'The UID {uidornickname} was not deleted') self.Logs.debug(f'The UID {uidornickname} was not deleted')
return False return False
def get_Admin(self, uidornickname: str) -> Optional[df.MAdmin]: def get_admin(self, uidornickname: str) -> Optional[df.MAdmin]:
"""Get the admin object model
Args:
uidornickname (str): UID or Nickname of the admin
Returns:
Optional[MAdmin]: The MAdmin object model if exist
"""
for record in self.UID_ADMIN_DB: for record in self.UID_ADMIN_DB:
if record.uid == uidornickname: if record.uid == uidornickname:
return record return record
elif record.nickname == uidornickname: elif record.nickname.lower() == uidornickname.lower():
return record return record
return None return None
def get_uid(self, uidornickname:str) -> Optional[str]: def get_uid(self, uidornickname:str) -> Optional[str]:
"""Get the UID of the admin
Args:
uidornickname (str): The UID or nickname of the admin
Returns:
Optional[str]: The UID of the admin
"""
for record in self.UID_ADMIN_DB: for record in self.UID_ADMIN_DB:
if record.uid == uidornickname: if record.uid == uidornickname:
return record.uid return record.uid
if record.nickname == uidornickname: if record.nickname.lower() == uidornickname.lower():
return record.uid return record.uid
return None return None
def get_nickname(self, uidornickname:str) -> Optional[str]: def get_nickname(self, uidornickname:str) -> Optional[str]:
"""Get the nickname of the admin
Args:
uidornickname (str): The UID or the nickname of the admin
Returns:
Optional[str]: The nickname of the admin
"""
for record in self.UID_ADMIN_DB: for record in self.UID_ADMIN_DB:
if record.nickname == uidornickname: if record.nickname.lower() == uidornickname.lower():
return record.nickname return record.nickname
if record.uid == uidornickname: if record.uid == uidornickname:
return record.nickname return record.nickname

View File

@@ -355,7 +355,7 @@ class Irc:
# Check if the nickname is an admin # Check if the nickname is an admin
p = self.Protocol p = self.Protocol
admin_obj = self.Admin.get_Admin(nickname) admin_obj = self.Admin.get_admin(nickname)
dnickname = self.Config.SERVICE_NICKNAME dnickname = self.Config.SERVICE_NICKNAME
color_bold = self.Config.COLORS.bold color_bold = self.Config.COLORS.bold
color_nogc = self.Config.COLORS.nogc color_nogc = self.Config.COLORS.nogc
@@ -413,7 +413,7 @@ class Irc:
def generate_help_menu_bakcup(self, nickname: str) -> None: def generate_help_menu_bakcup(self, nickname: str) -> None:
# Check if the nickname is an admin # Check if the nickname is an admin
admin_obj = self.Admin.get_Admin(nickname) admin_obj = self.Admin.get_admin(nickname)
dnickname = self.Config.SERVICE_NICKNAME dnickname = self.Config.SERVICE_NICKNAME
color_bold = self.Config.COLORS.bold color_bold = self.Config.COLORS.bold
color_nogc = self.Config.COLORS.nogc color_nogc = self.Config.COLORS.nogc
@@ -447,7 +447,7 @@ class Irc:
def is_cmd_allowed(self, nickname: str, command_name: str) -> bool: def is_cmd_allowed(self, nickname: str, command_name: str) -> bool:
admin_obj = self.Admin.get_Admin(nickname) admin_obj = self.Admin.get_admin(nickname)
current_level = 0 current_level = 0
if admin_obj is not None: if admin_obj is not None:
@@ -769,7 +769,7 @@ class Irc:
def delete_db_admin(self, uid:str) -> None: def delete_db_admin(self, uid:str) -> None:
if self.Admin.get_Admin(uid) is None: if self.Admin.get_admin(uid) is None:
return None return None
if not self.Admin.delete(uid): if not self.Admin.delete(uid):
@@ -1209,7 +1209,7 @@ class Irc:
user_to_edit = cmd[1] user_to_edit = cmd[1]
user_password = self.Loader.Utils.hash_password(cmd[2]) user_password = self.Loader.Utils.hash_password(cmd[2])
get_admin = self.Admin.get_Admin(fromuser) get_admin = self.Admin.get_admin(fromuser)
if get_admin is None: if get_admin is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"This user {fromuser} has no Admin access") self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"This user {fromuser} has no Admin access")
return None return None
@@ -1273,7 +1273,7 @@ class Irc:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"{self.Config.SERVICE_PREFIX}delaccess [USER] [CONFIRMUSER]") self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"{self.Config.SERVICE_PREFIX}delaccess [USER] [CONFIRMUSER]")
return None return None
get_admin = self.Admin.get_Admin(fromuser) get_admin = self.Admin.get_admin(fromuser)
if get_admin is None: if get_admin is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"This user {fromuser} has no admin access") self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"This user {fromuser} has no admin access")

View File

@@ -287,7 +287,7 @@ class Votekick():
case 'activate': case 'activate':
try: try:
# vote activate #channel # vote activate #channel
if self.Admin.get_Admin(fromuser) is None: if self.Admin.get_admin(fromuser) is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' :Your are not allowed to execute this command') self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' :Your are not allowed to execute this command')
return None return None
@@ -321,7 +321,7 @@ class Votekick():
case 'deactivate': case 'deactivate':
try: try:
# vote deactivate #channel # vote deactivate #channel
if self.Admin.get_Admin(fromuser) is None: if self.Admin.get_admin(fromuser) is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f" Your are not allowed to execute this command") self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f" Your are not allowed to execute this command")
return None return None
@@ -392,7 +392,7 @@ class Votekick():
case 'cancel': case 'cancel':
try: try:
# vote cancel # vote cancel
if self.Admin.get_Admin(fromuser) is None: if self.Admin.get_admin(fromuser) is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' Your are not allowed to execute this command') self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' Your are not allowed to execute this command')
return None return None
@@ -430,7 +430,7 @@ class Votekick():
case 'submit': case 'submit':
try: try:
# vote submit nickname # vote submit nickname
if self.Admin.get_Admin(fromuser) is None: if self.Admin.get_admin(fromuser) is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' Your are not allowed to execute this command') self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' Your are not allowed to execute this command')
return None return None
@@ -508,7 +508,7 @@ class Votekick():
case 'verdict': case 'verdict':
try: try:
# vote verdict # vote verdict
if self.Admin.get_Admin(fromuser) is None: if self.Admin.get_admin(fromuser) is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f'Your are not allowed to execute this command') self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f'Your are not allowed to execute this command')
return None return None