updating namings convension to stay coherent

This commit is contained in:
adator
2025-08-09 12:17:45 +02:00
parent 5629dcfde6
commit 1686c4a0b5
11 changed files with 113 additions and 132 deletions

View File

@@ -1,4 +1,4 @@
from typing import Optional, Union
from typing import Optional
from core.base import Base
import core.definition as df

View File

@@ -1,6 +1,5 @@
from re import findall
from typing import Any, Optional, Literal, TYPE_CHECKING
from core.classes import user
if TYPE_CHECKING:
from core.definition import MChannel
@@ -12,14 +11,14 @@ class Channel:
"""List that contains all the Channels objects (ChannelModel)
"""
def __init__(self, baseObj: 'Base') -> None:
def __init__(self, base: 'Base') -> None:
self.Logs = baseObj.logs
self.Base = baseObj
self.Logs = base.logs
self.Base = base
return None
def insert(self, newChan: 'MChannel') -> bool:
def insert(self, new_channel: 'MChannel') -> bool:
"""This method will insert a new channel and if the channel exist it will update the user list (uids)
Args:
@@ -31,17 +30,17 @@ class Channel:
result = False
exist = False
if not self.Is_Channel(newChan.name):
self.Logs.error(f"The channel {newChan.name} is not valid, channel must start with #")
if not self.Is_Channel(new_channel.name):
self.Logs.error(f"The channel {new_channel.name} is not valid, channel must start with #")
return False
for record in self.UID_CHANNEL_DB:
if record.name.lower() == newChan.name.lower():
if record.name.lower() == new_channel.name.lower():
# If the channel exist, update the user list and do not go further
exist = True
# self.Logs.debug(f'{record.name} already exist')
for user in newChan.uids:
for user in new_channel.uids:
record.uids.append(user)
# Supprimer les doublons
@@ -52,13 +51,13 @@ class Channel:
if not exist:
# If the channel don't exist, then create it
newChan.name = newChan.name.lower()
self.UID_CHANNEL_DB.append(newChan)
new_channel.name = new_channel.name.lower()
self.UID_CHANNEL_DB.append(new_channel)
result = True
# self.Logs.debug(f'New Channel Created: ({newChan})')
# self.Logs.debug(f'New Channel Created: ({new_channel})')
if not result:
self.Logs.critical(f'The Channel Object was not inserted {newChan}')
self.Logs.critical(f'The Channel Object was not inserted {new_channel}')
self.clean_channel()
@@ -66,12 +65,12 @@ class Channel:
def delete(self, channel_name: str) -> bool:
chanObj = self.get_Channel(channel_name)
chan_obj = self.get_Channel(channel_name)
if chanObj is None:
if chan_obj is None:
return False
self.UID_CHANNEL_DB.remove(chanObj)
self.UID_CHANNEL_DB.remove(chan_obj)
return True
@@ -79,14 +78,14 @@ class Channel:
try:
result = False
chanObj = self.get_Channel(channel_name.lower())
chan_obj = self.get_Channel(channel_name.lower())
if chanObj is None:
if chan_obj is None:
return result
for userid in chanObj.uids:
for userid in chan_obj.uids:
if self.Base.clean_uid(userid) == self.Base.clean_uid(uid):
chanObj.uids.remove(userid)
chan_obj.uids.remove(userid)
result = True
self.clean_channel()
@@ -103,7 +102,6 @@ class Channel:
for user_id in record.uids:
if self.Base.clean_uid(user_id) == self.Base.clean_uid(uid):
record.uids.remove(user_id)
# self.Logs.debug(f'The UID {uid} has been removed, here is the new object: {record}')
result = True
self.clean_channel()
@@ -115,19 +113,16 @@ class Channel:
def add_user_to_a_channel(self, channel_name: str, uid: str) -> bool:
try:
result = False
chanObj = self.get_Channel(channel_name)
chan_obj = self.get_Channel(channel_name)
self.Logs.debug(f"** {__name__}")
if chanObj is None:
if chan_obj is None:
result = self.insert(MChannel(channel_name, uids=[uid]))
# self.Logs.debug(f"** {__name__} - result: {result}")
# self.Logs.debug(f'New Channel Created: ({chanObj})')
return result
chanObj.uids.append(uid)
del_duplicates = list(set(chanObj.uids))
chanObj.uids = del_duplicates
# self.Logs.debug(f'New Channel Created: ({chanObj})')
chan_obj.uids.append(uid)
del_duplicates = list(set(chan_obj.uids))
chan_obj.uids = del_duplicates
return True
except Exception as err:
@@ -143,18 +138,16 @@ class Channel:
Returns:
bool: True if the user is present in the channel
"""
user_found = False
chan = self.get_Channel(channel_name=channel_name)
if chan is None:
return user_found
return False
clean_uid = self.Base.clean_uid(uid=uid)
for chan_uid in chan.uids:
if self.Base.clean_uid(chan_uid) == clean_uid:
user_found = True
break
return True
return user_found
return False
def clean_channel(self) -> None:
"""Remove Channels if empty
@@ -163,7 +156,7 @@ class Channel:
for record in self.UID_CHANNEL_DB:
if not record.uids:
self.UID_CHANNEL_DB.remove(record)
# self.Logs.debug(f'The Channel {record.name} has been removed, here is the new object: {record}')
return None
except Exception as err:
self.Logs.error(f'{err}')
@@ -178,7 +171,7 @@ class Channel:
def get_channel_asdict(self, chan_name: str) -> Optional[dict[str, Any]]:
channel_obj: Optional['MChannel'] = self.get_Channel(chan_name=chan_name)
channel_obj: Optional['MChannel'] = self.get_Channel(chan_name)
if channel_obj is None:
return None
@@ -235,9 +228,9 @@ class Channel:
case 'add':
mes_donnees = {'module_name': module_name, 'channel_name': channel_name}
response = self.Base.db_execute_query(f"SELECT id FROM {core_table} WHERE module_name = :module_name AND channel_name = :channel_name", mes_donnees)
isChannelExist = response.fetchone()
is_channel_exist = response.fetchone()
if isChannelExist is None:
if is_channel_exist is None:
mes_donnees = {'datetime': self.Base.get_datetime(), 'channel_name': channel_name, 'module_name': module_name}
insert = self.Base.db_execute_query(f"INSERT INTO {core_table} (datetime, channel_name, module_name) VALUES (:datetime, :channel_name, :module_name)", mes_donnees)
if insert.rowcount:
@@ -261,4 +254,3 @@ class Channel:
except Exception as err:
self.Logs.error(err)

View File

@@ -1,6 +1,5 @@
from re import sub
from typing import Any, Optional, Union, TYPE_CHECKING
from dataclasses import asdict
if TYPE_CHECKING:
from core.base import Base
@@ -10,30 +9,28 @@ class Client:
CLIENT_DB: list['MClient'] = []
def __init__(self, baseObj: 'Base') -> None:
def __init__(self, base: 'Base'):
self.Logs = baseObj.logs
self.Base = baseObj
self.Logs = base.logs
self.Base = base
return None
def insert(self, newUser: 'MClient') -> bool:
def insert(self, new_client: 'MClient') -> bool:
"""Insert a new User object
Args:
newUser (UserModel): New userModel object
new_client (MClient): New Client object
Returns:
bool: True if inserted
"""
userObj = self.get_Client(newUser.uid)
client_obj = self.get_Client(new_client.uid)
if not userObj is None:
if not client_obj is None:
# User already created return False
return False
self.CLIENT_DB.append(newUser)
self.CLIENT_DB.append(new_client)
return True
@@ -47,12 +44,12 @@ class Client:
Returns:
bool: True if updated
"""
userObj = self.get_Client(uidornickname=uid)
user_obj = self.get_Client(uidornickname=uid)
if userObj is None:
if user_obj is None:
return False
userObj.nickname = newNickname
user_obj.nickname = newNickname
return True
@@ -67,16 +64,16 @@ class Client:
bool: True if user mode has been updaed
"""
response = True
userObj = self.get_Client(uidornickname=uidornickname)
user_obj = self.get_Client(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 == '+':
@@ -95,7 +92,7 @@ class Client:
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
@@ -109,16 +106,16 @@ class Client:
bool: True if deleted
"""
userObj = self.get_Client(uidornickname=uid)
user_obj = self.get_Client(uidornickname=uid)
if userObj is None:
if user_obj is None:
return False
self.CLIENT_DB.remove(userObj)
self.CLIENT_DB.remove(user_obj)
return True
def get_Client(self, uidornickname: str) -> Union['MClient', None]:
def get_Client(self, uidornickname: str) -> Optional['MClient']:
"""Get The Client Object model
Args:
@@ -127,16 +124,15 @@ class Client:
Returns:
UserModel|None: The UserModel Object | None
"""
User = None
for record in self.CLIENT_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:
@@ -146,12 +142,12 @@ class Client:
str|None: Return the UID
"""
userObj = self.get_Client(uidornickname=uidornickname)
client_obj = self.get_Client(uidornickname=uidornickname)
if userObj is None:
if client_obj is None:
return None
return userObj.uid
return client_obj.uid
def get_nickname(self, uidornickname:str) -> Union[str, None]:
"""Get the Nickname starting from UID or the nickname
@@ -162,12 +158,12 @@ class Client:
Returns:
str|None: the nickname
"""
userObj = self.get_Client(uidornickname=uidornickname)
client_obj = self.get_Client(uidornickname=uidornickname)
if userObj is None:
if client_obj is None:
return None
return userObj.nickname
return client_obj.nickname
def get_client_asdict(self, uidornickname: str) -> Optional[dict[str, Any]]:
"""Transform User Object to a dictionary
@@ -194,9 +190,9 @@ class Client:
Returns:
bool: True if exist
"""
userObj = self.get_Client(uidornickname=uidornikname)
user_obj = self.get_Client(uidornickname=uidornikname)
if userObj is None:
if user_obj is None:
return False
return True

View File

@@ -6,13 +6,11 @@ class Clone:
UID_CLONE_DB: list[MClone] = []
def __init__(self, baseObj: Base) -> None:
def __init__(self, base: Base):
self.Logs = baseObj.logs
self.Logs = base.logs
return None
def insert(self, newCloneObject: MClone) -> bool:
def insert(self, new_clone_object: MClone) -> bool:
"""Create new Clone object
Args:
@@ -25,23 +23,22 @@ class Clone:
exist = False
for record in self.UID_CLONE_DB:
if record.nickname == newCloneObject.nickname:
if record.nickname == new_clone_object.nickname:
# If the user exist then return False and do not go further
exist = True
self.Logs.warning(f'Nickname {record.nickname} already exist')
return result
if record.uid == newCloneObject.uid:
if record.uid == new_clone_object.uid:
exist = True
self.Logs.warning(f'UID: {record.uid} already exist')
return result
if not exist:
self.UID_CLONE_DB.append(newCloneObject)
self.UID_CLONE_DB.append(new_clone_object)
result = True
# self.Logs.debug(f'New Clone Object Created: ({newCloneObject})')
if not result:
self.Logs.critical(f'The Clone Object was not inserted {newCloneObject}')
self.Logs.critical(f'The Clone Object was not inserted {new_clone_object}')
return result
@@ -55,12 +52,12 @@ class Clone:
bool: True if deleted
"""
cloneObj = self.get_Clone(uidornickname=uidornickname)
clone_obj = self.get_clone(uidornickname=uidornickname)
if cloneObj is None:
if clone_obj is None:
return False
self.UID_CLONE_DB.remove(cloneObj)
self.UID_CLONE_DB.remove(clone_obj)
return True
@@ -73,7 +70,7 @@ class Clone:
Returns:
bool: True if the nickname exist
"""
clone = self.get_Clone(nickname)
clone = self.get_clone(nickname)
if isinstance(clone, MClone):
return True
@@ -88,13 +85,13 @@ class Clone:
Returns:
bool: True if the nickname exist
"""
clone = self.get_Clone(uid)
clone = self.get_clone(uid)
if isinstance(clone, MClone):
return True
return False
def get_Clone(self, uidornickname: str) -> Optional[MClone]:
def get_clone(self, uidornickname: str) -> Optional[MClone]:
"""Get MClone object or None
Args:
@@ -128,9 +125,9 @@ class Clone:
return None
def get_Clone_AsDict(self, uidornickname: str) -> Optional[dict[str, Any]]:
def get_clone_asdict(self, uidornickname: str) -> Optional[dict[str, Any]]:
clone_obj = self.get_Clone(uidornickname=uidornickname)
clone_obj = self.get_clone(uidornickname=uidornickname)
if clone_obj is None:
return None
@@ -141,9 +138,9 @@ class Clone:
response = False
for cloneObject in self.UID_CLONE_DB:
if cloneObject.nickname == nickname:
cloneObject.alive = False # Kill the clone
for clone in self.UID_CLONE_DB:
if clone.nickname == nickname:
clone.alive = False # Kill the clone
response = True
return response

View File

@@ -186,16 +186,16 @@ class Inspircd:
uidornickname (str): The UID or the Nickname
reason (str): The reason for the quit
"""
userObj = self.__Irc.User.get_User(uidornickname=uid)
cloneObj = self.__Irc.Clone.get_Clone(uidornickname=uid)
user_obj = self.__Irc.User.get_User(uidornickname=uid)
clone_obj = self.__Irc.Clone.get_clone(uidornickname=uid)
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
if not userObj is None:
self.send2socket(f":{userObj.uid} QUIT :{reason}", print_log=print_log)
self.__Irc.User.delete(userObj.uid)
if not user_obj is None:
self.send2socket(f":{user_obj.uid} QUIT :{reason}", print_log=print_log)
self.__Irc.User.delete(user_obj.uid)
if not cloneObj is None:
self.__Irc.Clone.delete(cloneObj.uid)
if not clone_obj is None:
self.__Irc.Clone.delete(clone_obj.uid)
if not reputationObj is None:
self.__Irc.Reputation.delete(reputationObj.uid)

View File

@@ -344,16 +344,16 @@ class Unrealircd6:
uidornickname (str): The UID or the Nickname
reason (str): The reason for the quit
"""
userObj = self.__Irc.User.get_User(uidornickname=uid)
cloneObj = self.__Irc.Clone.get_Clone(uidornickname=uid)
user_obj = self.__Irc.User.get_User(uidornickname=uid)
clone_obj = self.__Irc.Clone.get_clone(uidornickname=uid)
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
if not userObj is None:
self.send2socket(f":{userObj.uid} QUIT :{reason}", print_log=print_log)
self.__Irc.User.delete(userObj.uid)
if not user_obj is None:
self.send2socket(f":{user_obj.uid} QUIT :{reason}", print_log=print_log)
self.__Irc.User.delete(user_obj.uid)
if not cloneObj is None:
self.__Irc.Clone.delete(cloneObj.uid)
if not clone_obj is None:
self.__Irc.Clone.delete(clone_obj.uid)
if not reputationObj is None:
self.__Irc.Reputation.delete(reputationObj.uid)
@@ -469,7 +469,7 @@ class Unrealircd6:
def send_mode_chan(self, channel_name: str, channel_mode: str) -> None:
channel = self.__Irc.Channel.Is_Channel(channelToCheck=channel_name)
channel = self.__Irc.Channel.Is_Channel(channel_name)
if not channel:
self.__Base.logs.error(f'The channel [{channel_name}] is not correct')
return None

View File

@@ -6,13 +6,11 @@ class Reputation:
UID_REPUTATION_DB: list[MReputation] = []
def __init__(self, baseObj: Base) -> None:
def __init__(self, base: Base):
self.Logs = baseObj.logs
self.Logs = base.logs
self.MReputation: MReputation = MReputation
return None
def insert(self, new_reputation_user: MReputation) -> bool:
"""Insert a new Reputation User object

View File

@@ -1,6 +1,5 @@
from re import sub
from typing import Any, Optional, Union, TYPE_CHECKING
from dataclasses import asdict
from typing import Any, Optional, TYPE_CHECKING
from datetime import datetime
if TYPE_CHECKING:
@@ -11,12 +10,10 @@ class User:
UID_DB: list['MUser'] = []
def __init__(self, baseObj: 'Base') -> None:
def __init__(self, base: 'Base'):
self.Logs = baseObj.logs
self.Base = baseObj
return None
self.Logs = base.logs
self.Base = base
def insert(self, new_user: 'MUser') -> bool:
"""Insert a new User object

View File

@@ -269,15 +269,15 @@ class Clone():
if not senderObj is None:
senderMsg = ' '.join(cmd[4:])
getClone = self.Clone.get_Clone(cmd[3])
clone_obj = self.Clone.get_clone(cmd[3])
if getClone is None:
if clone_obj is None:
return None
if getClone.uid != self.Config.SERVICE_ID:
if clone_obj.uid != self.Config.SERVICE_ID:
final_message = f"{senderObj.nickname}!{senderObj.username}@{senderObj.hostname} > {senderMsg.lstrip(':')}"
self.Protocol.send_priv_msg(
nick_from=getClone.uid,
nick_from=clone_obj.uid,
msg=final_message,
channel=self.Config.CLONE_CHANNEL
)
@@ -337,9 +337,9 @@ class Clone():
self.Base.create_thread(func=self.thread_kill_clones, func_args=(fromuser, ))
else:
cloneObj = self.Clone.get_Clone(clone_name)
if not cloneObj is None:
self.Protocol.send_quit(cloneObj.uid, 'Goood bye', print_log=False)
clone_obj = self.Clone.get_clone(clone_name)
if not clone_obj is None:
self.Protocol.send_quit(clone_obj.uid, 'Goood bye', print_log=False)
except Exception as err:
self.Logs.error(f'{err}')

View File

@@ -22,7 +22,7 @@ class ModConfModel(MainModel):
autolimit_interval: int = 3
@dataclass
class FloodUser:
class FloodUser(MainModel):
uid: str = None
nbr_msg: int = 0
first_msg_time: int = 0

View File

@@ -1,3 +1,4 @@
from calendar import c
import socket
import psutil
import requests
@@ -264,7 +265,7 @@ def action_on_flood(uplink: 'Defender', srvmsg: list[str]):
channel = srvmsg[3]
User = irc.User.get_User(user_trigger)
if User is None or not irc.Channel.Is_Channel(channelToCheck=channel):
if User is None or not irc.Channel.Is_Channel(channel_to_check=channel):
return
flood_time = confmodel.flood_time