mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
Adding some comments, editing methods names (admin.py)
This commit is contained in:
@@ -10,62 +10,78 @@ class Admin:
|
||||
self.Logs = base.logs
|
||||
|
||||
def insert(self, new_admin: df.MAdmin) -> bool:
|
||||
"""Insert a new admin object model
|
||||
|
||||
result = False
|
||||
exist = False
|
||||
Args:
|
||||
new_admin (MAdmin): The new admin object model to insert
|
||||
|
||||
Returns:
|
||||
bool: True if it was inserted
|
||||
"""
|
||||
|
||||
for record in self.UID_ADMIN_DB:
|
||||
if record.uid == new_admin.uid:
|
||||
# If the admin exist then return False and do not go further
|
||||
exist = True
|
||||
self.Logs.debug(f'{record.uid} already exist')
|
||||
return result
|
||||
return False
|
||||
|
||||
if not exist:
|
||||
self.UID_ADMIN_DB.append(new_admin)
|
||||
result = True
|
||||
self.Logs.debug(f'UID ({new_admin.uid}) has been created')
|
||||
|
||||
if not result:
|
||||
self.Logs.critical(f'The User Object was not inserted {new_admin}')
|
||||
|
||||
return result
|
||||
self.Logs.debug(f'A new admin ({new_admin.nickname}) has been created')
|
||||
return True
|
||||
|
||||
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:
|
||||
if record.uid == uid:
|
||||
# If the admin exist, update and do not go further
|
||||
record.nickname = new_admin_nickname
|
||||
result = True
|
||||
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')
|
||||
|
||||
return result
|
||||
return False
|
||||
|
||||
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:
|
||||
if record.nickname == nickname:
|
||||
# If the admin exist, update and do not go further
|
||||
record.level = new_admin_level
|
||||
result = True
|
||||
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')
|
||||
|
||||
return result
|
||||
return False
|
||||
|
||||
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:
|
||||
if record.uid == uidornickname:
|
||||
@@ -73,40 +89,64 @@ class Admin:
|
||||
self.UID_ADMIN_DB.remove(record)
|
||||
self.Logs.debug(f'UID ({record.uid}) has been deleted')
|
||||
return True
|
||||
if record.nickname == uidornickname:
|
||||
if record.nickname.lower() == uidornickname.lower():
|
||||
# If the admin exist, delete and do not go further
|
||||
self.UID_ADMIN_DB.remove(record)
|
||||
self.Logs.debug(f'nickname ({record.nickname}) has been deleted')
|
||||
return True
|
||||
|
||||
self.Logs.critical(f'The UID {uidornickname} was not deleted')
|
||||
self.Logs.debug(f'The UID {uidornickname} was not deleted')
|
||||
|
||||
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:
|
||||
if record.uid == uidornickname:
|
||||
return record
|
||||
elif record.nickname == uidornickname:
|
||||
elif record.nickname.lower() == uidornickname.lower():
|
||||
return record
|
||||
|
||||
return None
|
||||
|
||||
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:
|
||||
if record.uid == uidornickname:
|
||||
return record.uid
|
||||
if record.nickname == uidornickname:
|
||||
if record.nickname.lower() == uidornickname.lower():
|
||||
return record.uid
|
||||
|
||||
return None
|
||||
|
||||
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:
|
||||
if record.nickname == uidornickname:
|
||||
if record.nickname.lower() == uidornickname.lower():
|
||||
return record.nickname
|
||||
if record.uid == uidornickname:
|
||||
return record.nickname
|
||||
|
||||
12
core/irc.py
12
core/irc.py
@@ -355,7 +355,7 @@ class Irc:
|
||||
|
||||
# Check if the nickname is an admin
|
||||
p = self.Protocol
|
||||
admin_obj = self.Admin.get_Admin(nickname)
|
||||
admin_obj = self.Admin.get_admin(nickname)
|
||||
dnickname = self.Config.SERVICE_NICKNAME
|
||||
color_bold = self.Config.COLORS.bold
|
||||
color_nogc = self.Config.COLORS.nogc
|
||||
@@ -413,7 +413,7 @@ class Irc:
|
||||
def generate_help_menu_bakcup(self, nickname: str) -> None:
|
||||
|
||||
# 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
|
||||
color_bold = self.Config.COLORS.bold
|
||||
color_nogc = self.Config.COLORS.nogc
|
||||
@@ -447,7 +447,7 @@ class Irc:
|
||||
|
||||
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
|
||||
|
||||
if admin_obj is not None:
|
||||
@@ -769,7 +769,7 @@ class Irc:
|
||||
|
||||
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
|
||||
|
||||
if not self.Admin.delete(uid):
|
||||
@@ -1209,7 +1209,7 @@ class Irc:
|
||||
user_to_edit = cmd[1]
|
||||
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:
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"This user {fromuser} has no Admin access")
|
||||
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]")
|
||||
return None
|
||||
|
||||
get_admin = self.Admin.get_Admin(fromuser)
|
||||
get_admin = self.Admin.get_admin(fromuser)
|
||||
|
||||
if get_admin is None:
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"This user {fromuser} has no admin access")
|
||||
|
||||
@@ -287,7 +287,7 @@ class Votekick():
|
||||
case 'activate':
|
||||
try:
|
||||
# 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')
|
||||
return None
|
||||
|
||||
@@ -321,7 +321,7 @@ class Votekick():
|
||||
case 'deactivate':
|
||||
try:
|
||||
# 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")
|
||||
return None
|
||||
|
||||
@@ -392,7 +392,7 @@ class Votekick():
|
||||
case 'cancel':
|
||||
try:
|
||||
# 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')
|
||||
return None
|
||||
|
||||
@@ -430,7 +430,7 @@ class Votekick():
|
||||
case 'submit':
|
||||
try:
|
||||
# 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')
|
||||
return None
|
||||
|
||||
@@ -508,7 +508,7 @@ class Votekick():
|
||||
case 'verdict':
|
||||
try:
|
||||
# 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')
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user