mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
updating namings convension to stay coherent
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from typing import Optional, Union
|
from typing import Optional
|
||||||
from core.base import Base
|
from core.base import Base
|
||||||
import core.definition as df
|
import core.definition as df
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from re import findall
|
from re import findall
|
||||||
from typing import Any, Optional, Literal, TYPE_CHECKING
|
from typing import Any, Optional, Literal, TYPE_CHECKING
|
||||||
from core.classes import user
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.definition import MChannel
|
from core.definition import MChannel
|
||||||
@@ -12,14 +11,14 @@ class Channel:
|
|||||||
"""List that contains all the Channels objects (ChannelModel)
|
"""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.Logs = base.logs
|
||||||
self.Base = baseObj
|
self.Base = base
|
||||||
|
|
||||||
return None
|
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)
|
"""This method will insert a new channel and if the channel exist it will update the user list (uids)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -31,17 +30,17 @@ class Channel:
|
|||||||
result = False
|
result = False
|
||||||
exist = False
|
exist = False
|
||||||
|
|
||||||
if not self.Is_Channel(newChan.name):
|
if not self.Is_Channel(new_channel.name):
|
||||||
self.Logs.error(f"The channel {newChan.name} is not valid, channel must start with #")
|
self.Logs.error(f"The channel {new_channel.name} is not valid, channel must start with #")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for record in self.UID_CHANNEL_DB:
|
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
|
# If the channel exist, update the user list and do not go further
|
||||||
exist = True
|
exist = True
|
||||||
# self.Logs.debug(f'{record.name} already exist')
|
# self.Logs.debug(f'{record.name} already exist')
|
||||||
|
|
||||||
for user in newChan.uids:
|
for user in new_channel.uids:
|
||||||
record.uids.append(user)
|
record.uids.append(user)
|
||||||
|
|
||||||
# Supprimer les doublons
|
# Supprimer les doublons
|
||||||
@@ -52,13 +51,13 @@ class Channel:
|
|||||||
|
|
||||||
if not exist:
|
if not exist:
|
||||||
# If the channel don't exist, then create it
|
# If the channel don't exist, then create it
|
||||||
newChan.name = newChan.name.lower()
|
new_channel.name = new_channel.name.lower()
|
||||||
self.UID_CHANNEL_DB.append(newChan)
|
self.UID_CHANNEL_DB.append(new_channel)
|
||||||
result = True
|
result = True
|
||||||
# self.Logs.debug(f'New Channel Created: ({newChan})')
|
# self.Logs.debug(f'New Channel Created: ({new_channel})')
|
||||||
|
|
||||||
if not result:
|
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()
|
self.clean_channel()
|
||||||
|
|
||||||
@@ -66,12 +65,12 @@ class Channel:
|
|||||||
|
|
||||||
def delete(self, channel_name: str) -> bool:
|
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
|
return False
|
||||||
|
|
||||||
self.UID_CHANNEL_DB.remove(chanObj)
|
self.UID_CHANNEL_DB.remove(chan_obj)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -79,14 +78,14 @@ class Channel:
|
|||||||
try:
|
try:
|
||||||
result = False
|
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
|
return result
|
||||||
|
|
||||||
for userid in chanObj.uids:
|
for userid in chan_obj.uids:
|
||||||
if self.Base.clean_uid(userid) == self.Base.clean_uid(uid):
|
if self.Base.clean_uid(userid) == self.Base.clean_uid(uid):
|
||||||
chanObj.uids.remove(userid)
|
chan_obj.uids.remove(userid)
|
||||||
result = True
|
result = True
|
||||||
|
|
||||||
self.clean_channel()
|
self.clean_channel()
|
||||||
@@ -103,7 +102,6 @@ class Channel:
|
|||||||
for user_id in record.uids:
|
for user_id in record.uids:
|
||||||
if self.Base.clean_uid(user_id) == self.Base.clean_uid(uid):
|
if self.Base.clean_uid(user_id) == self.Base.clean_uid(uid):
|
||||||
record.uids.remove(user_id)
|
record.uids.remove(user_id)
|
||||||
# self.Logs.debug(f'The UID {uid} has been removed, here is the new object: {record}')
|
|
||||||
result = True
|
result = True
|
||||||
|
|
||||||
self.clean_channel()
|
self.clean_channel()
|
||||||
@@ -115,19 +113,16 @@ class Channel:
|
|||||||
def add_user_to_a_channel(self, channel_name: str, uid: str) -> bool:
|
def add_user_to_a_channel(self, channel_name: str, uid: str) -> bool:
|
||||||
try:
|
try:
|
||||||
result = False
|
result = False
|
||||||
chanObj = self.get_Channel(channel_name)
|
chan_obj = self.get_Channel(channel_name)
|
||||||
self.Logs.debug(f"** {__name__}")
|
self.Logs.debug(f"** {__name__}")
|
||||||
|
|
||||||
if chanObj is None:
|
if chan_obj is None:
|
||||||
result = self.insert(MChannel(channel_name, uids=[uid]))
|
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
|
return result
|
||||||
|
|
||||||
chanObj.uids.append(uid)
|
chan_obj.uids.append(uid)
|
||||||
del_duplicates = list(set(chanObj.uids))
|
del_duplicates = list(set(chan_obj.uids))
|
||||||
chanObj.uids = del_duplicates
|
chan_obj.uids = del_duplicates
|
||||||
# self.Logs.debug(f'New Channel Created: ({chanObj})')
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@@ -143,18 +138,16 @@ class Channel:
|
|||||||
Returns:
|
Returns:
|
||||||
bool: True if the user is present in the channel
|
bool: True if the user is present in the channel
|
||||||
"""
|
"""
|
||||||
user_found = False
|
|
||||||
chan = self.get_Channel(channel_name=channel_name)
|
chan = self.get_Channel(channel_name=channel_name)
|
||||||
if chan is None:
|
if chan is None:
|
||||||
return user_found
|
return False
|
||||||
|
|
||||||
clean_uid = self.Base.clean_uid(uid=uid)
|
clean_uid = self.Base.clean_uid(uid=uid)
|
||||||
for chan_uid in chan.uids:
|
for chan_uid in chan.uids:
|
||||||
if self.Base.clean_uid(chan_uid) == clean_uid:
|
if self.Base.clean_uid(chan_uid) == clean_uid:
|
||||||
user_found = True
|
return True
|
||||||
break
|
|
||||||
|
|
||||||
return user_found
|
return False
|
||||||
|
|
||||||
def clean_channel(self) -> None:
|
def clean_channel(self) -> None:
|
||||||
"""Remove Channels if empty
|
"""Remove Channels if empty
|
||||||
@@ -163,7 +156,7 @@ class Channel:
|
|||||||
for record in self.UID_CHANNEL_DB:
|
for record in self.UID_CHANNEL_DB:
|
||||||
if not record.uids:
|
if not record.uids:
|
||||||
self.UID_CHANNEL_DB.remove(record)
|
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
|
return None
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.Logs.error(f'{err}')
|
self.Logs.error(f'{err}')
|
||||||
@@ -178,7 +171,7 @@ class Channel:
|
|||||||
|
|
||||||
def get_channel_asdict(self, chan_name: str) -> Optional[dict[str, Any]]:
|
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:
|
if channel_obj is None:
|
||||||
return None
|
return None
|
||||||
@@ -235,9 +228,9 @@ class Channel:
|
|||||||
case 'add':
|
case 'add':
|
||||||
mes_donnees = {'module_name': module_name, 'channel_name': channel_name}
|
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)
|
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}
|
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)
|
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:
|
if insert.rowcount:
|
||||||
@@ -261,4 +254,3 @@ class Channel:
|
|||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.Logs.error(err)
|
self.Logs.error(err)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from re import sub
|
from re import sub
|
||||||
from typing import Any, Optional, Union, TYPE_CHECKING
|
from typing import Any, Optional, Union, TYPE_CHECKING
|
||||||
from dataclasses import asdict
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.base import Base
|
from core.base import Base
|
||||||
@@ -10,30 +9,28 @@ class Client:
|
|||||||
|
|
||||||
CLIENT_DB: list['MClient'] = []
|
CLIENT_DB: list['MClient'] = []
|
||||||
|
|
||||||
def __init__(self, baseObj: 'Base') -> None:
|
def __init__(self, base: 'Base'):
|
||||||
|
|
||||||
self.Logs = baseObj.logs
|
self.Logs = base.logs
|
||||||
self.Base = baseObj
|
self.Base = base
|
||||||
|
|
||||||
return None
|
def insert(self, new_client: 'MClient') -> bool:
|
||||||
|
|
||||||
def insert(self, newUser: 'MClient') -> bool:
|
|
||||||
"""Insert a new User object
|
"""Insert a new User object
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
newUser (UserModel): New userModel object
|
new_client (MClient): New Client object
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if inserted
|
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
|
# User already created return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.CLIENT_DB.append(newUser)
|
self.CLIENT_DB.append(new_client)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -47,12 +44,12 @@ class Client:
|
|||||||
Returns:
|
Returns:
|
||||||
bool: True if updated
|
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
|
return False
|
||||||
|
|
||||||
userObj.nickname = newNickname
|
user_obj.nickname = newNickname
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -67,16 +64,16 @@ class Client:
|
|||||||
bool: True if user mode has been updaed
|
bool: True if user mode has been updaed
|
||||||
"""
|
"""
|
||||||
response = True
|
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
|
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 == '+':
|
||||||
|
|
||||||
@@ -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_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
|
||||||
|
|
||||||
@@ -109,16 +106,16 @@ class Client:
|
|||||||
bool: True if deleted
|
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
|
return False
|
||||||
|
|
||||||
self.CLIENT_DB.remove(userObj)
|
self.CLIENT_DB.remove(user_obj)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_Client(self, uidornickname: str) -> Union['MClient', None]:
|
def get_Client(self, uidornickname: str) -> Optional['MClient']:
|
||||||
"""Get The Client Object model
|
"""Get The Client Object model
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -127,16 +124,15 @@ class Client:
|
|||||||
Returns:
|
Returns:
|
||||||
UserModel|None: The UserModel Object | None
|
UserModel|None: The UserModel Object | None
|
||||||
"""
|
"""
|
||||||
User = None
|
|
||||||
for record in self.CLIENT_DB:
|
for record in self.CLIENT_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:
|
||||||
@@ -146,12 +142,12 @@ class Client:
|
|||||||
str|None: Return the UID
|
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 None
|
||||||
|
|
||||||
return userObj.uid
|
return client_obj.uid
|
||||||
|
|
||||||
def get_nickname(self, uidornickname:str) -> Union[str, None]:
|
def get_nickname(self, uidornickname:str) -> Union[str, None]:
|
||||||
"""Get the Nickname starting from UID or the nickname
|
"""Get the Nickname starting from UID or the nickname
|
||||||
@@ -162,12 +158,12 @@ class Client:
|
|||||||
Returns:
|
Returns:
|
||||||
str|None: the nickname
|
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 None
|
||||||
|
|
||||||
return userObj.nickname
|
return client_obj.nickname
|
||||||
|
|
||||||
def get_client_asdict(self, uidornickname: str) -> Optional[dict[str, Any]]:
|
def get_client_asdict(self, uidornickname: str) -> Optional[dict[str, Any]]:
|
||||||
"""Transform User Object to a dictionary
|
"""Transform User Object to a dictionary
|
||||||
@@ -194,9 +190,9 @@ class Client:
|
|||||||
Returns:
|
Returns:
|
||||||
bool: True if exist
|
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 False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -6,13 +6,11 @@ class Clone:
|
|||||||
|
|
||||||
UID_CLONE_DB: list[MClone] = []
|
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, new_clone_object: MClone) -> bool:
|
||||||
|
|
||||||
def insert(self, newCloneObject: MClone) -> bool:
|
|
||||||
"""Create new Clone object
|
"""Create new Clone object
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -25,23 +23,22 @@ class Clone:
|
|||||||
exist = False
|
exist = False
|
||||||
|
|
||||||
for record in self.UID_CLONE_DB:
|
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
|
# If the user exist then return False and do not go further
|
||||||
exist = True
|
exist = True
|
||||||
self.Logs.warning(f'Nickname {record.nickname} already exist')
|
self.Logs.warning(f'Nickname {record.nickname} already exist')
|
||||||
return result
|
return result
|
||||||
if record.uid == newCloneObject.uid:
|
if record.uid == new_clone_object.uid:
|
||||||
exist = True
|
exist = True
|
||||||
self.Logs.warning(f'UID: {record.uid} already exist')
|
self.Logs.warning(f'UID: {record.uid} already exist')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if not exist:
|
if not exist:
|
||||||
self.UID_CLONE_DB.append(newCloneObject)
|
self.UID_CLONE_DB.append(new_clone_object)
|
||||||
result = True
|
result = True
|
||||||
# self.Logs.debug(f'New Clone Object Created: ({newCloneObject})')
|
|
||||||
|
|
||||||
if not result:
|
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
|
return result
|
||||||
|
|
||||||
@@ -55,12 +52,12 @@ class Clone:
|
|||||||
bool: True if deleted
|
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
|
return False
|
||||||
|
|
||||||
self.UID_CLONE_DB.remove(cloneObj)
|
self.UID_CLONE_DB.remove(clone_obj)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -73,7 +70,7 @@ class Clone:
|
|||||||
Returns:
|
Returns:
|
||||||
bool: True if the nickname exist
|
bool: True if the nickname exist
|
||||||
"""
|
"""
|
||||||
clone = self.get_Clone(nickname)
|
clone = self.get_clone(nickname)
|
||||||
if isinstance(clone, MClone):
|
if isinstance(clone, MClone):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -88,13 +85,13 @@ class Clone:
|
|||||||
Returns:
|
Returns:
|
||||||
bool: True if the nickname exist
|
bool: True if the nickname exist
|
||||||
"""
|
"""
|
||||||
clone = self.get_Clone(uid)
|
clone = self.get_clone(uid)
|
||||||
if isinstance(clone, MClone):
|
if isinstance(clone, MClone):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_Clone(self, uidornickname: str) -> Optional[MClone]:
|
def get_clone(self, uidornickname: str) -> Optional[MClone]:
|
||||||
"""Get MClone object or None
|
"""Get MClone object or None
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -128,9 +125,9 @@ class Clone:
|
|||||||
|
|
||||||
return None
|
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:
|
if clone_obj is None:
|
||||||
return None
|
return None
|
||||||
@@ -141,9 +138,9 @@ class Clone:
|
|||||||
|
|
||||||
response = False
|
response = False
|
||||||
|
|
||||||
for cloneObject in self.UID_CLONE_DB:
|
for clone in self.UID_CLONE_DB:
|
||||||
if cloneObject.nickname == nickname:
|
if clone.nickname == nickname:
|
||||||
cloneObject.alive = False # Kill the clone
|
clone.alive = False # Kill the clone
|
||||||
response = True
|
response = True
|
||||||
|
|
||||||
return response
|
return response
|
||||||
@@ -186,16 +186,16 @@ class Inspircd:
|
|||||||
uidornickname (str): The UID or the Nickname
|
uidornickname (str): The UID or the Nickname
|
||||||
reason (str): The reason for the quit
|
reason (str): The reason for the quit
|
||||||
"""
|
"""
|
||||||
userObj = self.__Irc.User.get_User(uidornickname=uid)
|
user_obj = self.__Irc.User.get_User(uidornickname=uid)
|
||||||
cloneObj = self.__Irc.Clone.get_Clone(uidornickname=uid)
|
clone_obj = self.__Irc.Clone.get_clone(uidornickname=uid)
|
||||||
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
|
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
|
||||||
|
|
||||||
if not userObj is None:
|
if not user_obj is None:
|
||||||
self.send2socket(f":{userObj.uid} QUIT :{reason}", print_log=print_log)
|
self.send2socket(f":{user_obj.uid} QUIT :{reason}", print_log=print_log)
|
||||||
self.__Irc.User.delete(userObj.uid)
|
self.__Irc.User.delete(user_obj.uid)
|
||||||
|
|
||||||
if not cloneObj is None:
|
if not clone_obj is None:
|
||||||
self.__Irc.Clone.delete(cloneObj.uid)
|
self.__Irc.Clone.delete(clone_obj.uid)
|
||||||
|
|
||||||
if not reputationObj is None:
|
if not reputationObj is None:
|
||||||
self.__Irc.Reputation.delete(reputationObj.uid)
|
self.__Irc.Reputation.delete(reputationObj.uid)
|
||||||
|
|||||||
@@ -344,16 +344,16 @@ class Unrealircd6:
|
|||||||
uidornickname (str): The UID or the Nickname
|
uidornickname (str): The UID or the Nickname
|
||||||
reason (str): The reason for the quit
|
reason (str): The reason for the quit
|
||||||
"""
|
"""
|
||||||
userObj = self.__Irc.User.get_User(uidornickname=uid)
|
user_obj = self.__Irc.User.get_User(uidornickname=uid)
|
||||||
cloneObj = self.__Irc.Clone.get_Clone(uidornickname=uid)
|
clone_obj = self.__Irc.Clone.get_clone(uidornickname=uid)
|
||||||
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
|
reputationObj = self.__Irc.Reputation.get_Reputation(uidornickname=uid)
|
||||||
|
|
||||||
if not userObj is None:
|
if not user_obj is None:
|
||||||
self.send2socket(f":{userObj.uid} QUIT :{reason}", print_log=print_log)
|
self.send2socket(f":{user_obj.uid} QUIT :{reason}", print_log=print_log)
|
||||||
self.__Irc.User.delete(userObj.uid)
|
self.__Irc.User.delete(user_obj.uid)
|
||||||
|
|
||||||
if not cloneObj is None:
|
if not clone_obj is None:
|
||||||
self.__Irc.Clone.delete(cloneObj.uid)
|
self.__Irc.Clone.delete(clone_obj.uid)
|
||||||
|
|
||||||
if not reputationObj is None:
|
if not reputationObj is None:
|
||||||
self.__Irc.Reputation.delete(reputationObj.uid)
|
self.__Irc.Reputation.delete(reputationObj.uid)
|
||||||
@@ -469,7 +469,7 @@ class Unrealircd6:
|
|||||||
|
|
||||||
def send_mode_chan(self, channel_name: str, channel_mode: str) -> None:
|
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:
|
if not channel:
|
||||||
self.__Base.logs.error(f'The channel [{channel_name}] is not correct')
|
self.__Base.logs.error(f'The channel [{channel_name}] is not correct')
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -6,13 +6,11 @@ class Reputation:
|
|||||||
|
|
||||||
UID_REPUTATION_DB: list[MReputation] = []
|
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
|
self.MReputation: MReputation = MReputation
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def insert(self, new_reputation_user: MReputation) -> bool:
|
def insert(self, new_reputation_user: MReputation) -> bool:
|
||||||
"""Insert a new Reputation User object
|
"""Insert a new Reputation User object
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from re import sub
|
from re import sub
|
||||||
from typing import Any, Optional, Union, TYPE_CHECKING
|
from typing import Any, Optional, TYPE_CHECKING
|
||||||
from dataclasses import asdict
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -11,12 +10,10 @@ class User:
|
|||||||
|
|
||||||
UID_DB: list['MUser'] = []
|
UID_DB: list['MUser'] = []
|
||||||
|
|
||||||
def __init__(self, baseObj: 'Base') -> None:
|
def __init__(self, base: 'Base'):
|
||||||
|
|
||||||
self.Logs = baseObj.logs
|
self.Logs = base.logs
|
||||||
self.Base = baseObj
|
self.Base = base
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def insert(self, new_user: 'MUser') -> bool:
|
def insert(self, new_user: 'MUser') -> bool:
|
||||||
"""Insert a new User object
|
"""Insert a new User object
|
||||||
|
|||||||
@@ -269,15 +269,15 @@ class Clone():
|
|||||||
|
|
||||||
if not senderObj is None:
|
if not senderObj is None:
|
||||||
senderMsg = ' '.join(cmd[4:])
|
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
|
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(':')}"
|
final_message = f"{senderObj.nickname}!{senderObj.username}@{senderObj.hostname} > {senderMsg.lstrip(':')}"
|
||||||
self.Protocol.send_priv_msg(
|
self.Protocol.send_priv_msg(
|
||||||
nick_from=getClone.uid,
|
nick_from=clone_obj.uid,
|
||||||
msg=final_message,
|
msg=final_message,
|
||||||
channel=self.Config.CLONE_CHANNEL
|
channel=self.Config.CLONE_CHANNEL
|
||||||
)
|
)
|
||||||
@@ -337,9 +337,9 @@ class Clone():
|
|||||||
self.Base.create_thread(func=self.thread_kill_clones, func_args=(fromuser, ))
|
self.Base.create_thread(func=self.thread_kill_clones, func_args=(fromuser, ))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cloneObj = self.Clone.get_Clone(clone_name)
|
clone_obj = self.Clone.get_clone(clone_name)
|
||||||
if not cloneObj is None:
|
if not clone_obj is None:
|
||||||
self.Protocol.send_quit(cloneObj.uid, 'Goood bye', print_log=False)
|
self.Protocol.send_quit(clone_obj.uid, 'Goood bye', print_log=False)
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.Logs.error(f'{err}')
|
self.Logs.error(f'{err}')
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class ModConfModel(MainModel):
|
|||||||
autolimit_interval: int = 3
|
autolimit_interval: int = 3
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class FloodUser:
|
class FloodUser(MainModel):
|
||||||
uid: str = None
|
uid: str = None
|
||||||
nbr_msg: int = 0
|
nbr_msg: int = 0
|
||||||
first_msg_time: int = 0
|
first_msg_time: int = 0
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from calendar import c
|
||||||
import socket
|
import socket
|
||||||
import psutil
|
import psutil
|
||||||
import requests
|
import requests
|
||||||
@@ -264,7 +265,7 @@ def action_on_flood(uplink: 'Defender', srvmsg: list[str]):
|
|||||||
channel = srvmsg[3]
|
channel = srvmsg[3]
|
||||||
User = irc.User.get_User(user_trigger)
|
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
|
return
|
||||||
|
|
||||||
flood_time = confmodel.flood_time
|
flood_time = confmodel.flood_time
|
||||||
|
|||||||
Reference in New Issue
Block a user