Adding some comments, editing methods names

This commit is contained in:
adator85
2025-08-15 15:47:01 +02:00
parent 21a2619f49
commit 6b22d786e3
25 changed files with 344 additions and 233 deletions

View File

@@ -1,5 +1,5 @@
from typing import Optional, TYPE_CHECKING
from core.definition import MClone
from mods.clone.schemas import MClone
if TYPE_CHECKING:
from mods.clone.mod_clone import Clone
@@ -16,33 +16,24 @@ class CloneManager:
"""Create new Clone object
Args:
newCloneObject (CloneModel): New CloneModel object
new_clone_object (MClone): New Clone object
Returns:
bool: True if inserted
"""
result = False
exist = False
if new_clone_object is None:
self.Logs.debug('New Clone object must not be None')
return False
for record in self.UID_CLONE_DB:
if record.nickname == new_clone_object.nickname:
if record.nickname == new_clone_object.nickname or record.uid == new_clone_object.uid:
# 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 == new_clone_object.uid:
exist = True
self.Logs.warning(f'UID: {record.uid} already exist')
return result
self.Logs.debug(f'Nickname/UID {record.nickname}/{record.uid} already exist')
return False
if not exist:
self.UID_CLONE_DB.append(new_clone_object)
result = True
if not result:
self.Logs.critical(f'The Clone Object was not inserted {new_clone_object}')
return result
self.UID_CLONE_DB.append(new_clone_object)
self.Logs.debug(f'New Clone object created: {new_clone_object}')
return True
def delete(self, uidornickname: str) -> bool:
"""Delete the Clone Object starting from the nickname or the UID

View File

@@ -1,6 +1,4 @@
import time, logging
from typing import TYPE_CHECKING, Optional
from faker import Faker
from typing import TYPE_CHECKING, Optional, Any
import mods.clone.utils as utils
import mods.clone.threads as thds
import mods.clone.schemas as schemas
@@ -8,40 +6,41 @@ from mods.clone.clone_manager import CloneManager
if TYPE_CHECKING:
from core.irc import Irc
from faker import Faker
class Clone():
class Clone:
def __init__(self, ircInstance: 'Irc') -> None:
def __init__(self, irc_instance: 'Irc') -> None:
# Module name (Mandatory)
self.module_name = 'mod_' + str(self.__class__.__name__).lower()
# Add Irc Object to the module (Mandatory)
self.Irc = ircInstance
self.Irc = irc_instance
# Add Irc Protocol Object to the module (Mandatory)
self.Protocol = ircInstance.Protocol
self.Protocol = irc_instance.Protocol
# Add Global Configuration to the module (Mandatory)
self.Config = ircInstance.Config
self.Config = irc_instance.Config
# Add Base object to the module (Mandatory)
self.Base = ircInstance.Base
self.Base = irc_instance.Base
# Add logs object to the module (Mandatory)
self.Logs = ircInstance.Base.logs
self.Logs = irc_instance.Base.logs
# Add User object to the module (Mandatory)
self.User = ircInstance.User
self.User = irc_instance.User
# Add Channel object to the module (Mandatory)
self.Channel = ircInstance.Channel
self.Channel = irc_instance.Channel
# Add global definitions
self.Definition = ircInstance.Loader.Definition
self.Definition = irc_instance.Loader.Definition
# The Global Settings
self.Settings = ircInstance.Loader.Settings
self.Settings = irc_instance.Loader.Settings
self.Schemas = schemas
@@ -88,8 +87,6 @@ class Clone():
def __create_tables(self) -> None:
"""Methode qui va créer la base de donnée si elle n'existe pas.
Une Session unique pour cette classe sera crée, qui sera utilisé dans cette classe / module
Args:
database_name (str): Nom de la base de données ( pas d'espace dans le nom )
Returns:
None: Aucun retour n'es attendu
@@ -136,15 +133,15 @@ class Clone():
return None
def cmd(self, data:list):
def cmd(self, data:list) -> None:
try:
if not data or len(data) < 2:
return
return None
cmd = data.copy() if isinstance(data, list) else list(data).copy()
index, command = self.Irc.Protocol.get_ircd_protocol_poisition(cmd)
if index == -1:
return
return None
match command:
@@ -152,15 +149,16 @@ class Clone():
return self.Utils.handle_on_privmsg(self, cmd)
case 'QUIT':
return
return None
case _:
return
return None
except Exception as err:
self.Logs.error(f'General Error: {err}', exc_info=True)
return None
def hcmds(self, user: str, channel: any, cmd: list, fullcmd: list = []) -> None:
def hcmds(self, user: str, channel: Any, cmd: list, fullcmd: list = []) -> None:
try:
@@ -310,7 +308,7 @@ class Clone():
try:
# clone say clone_nickname #channel message
clone_name = str(cmd[2])
clone_channel = str(cmd[3]) if self.Channel.Is_Channel(str(cmd[3])) else None
clone_channel = str(cmd[3]) if self.Channel.is_valid_channel(str(cmd[3])) else None
final_message = ' '.join(cmd[4:])

View File

@@ -12,7 +12,12 @@ def thread_connect_clones(uplink: 'Clone',
):
for i in range(0, number_of_clones):
uplink.Utils.create_new_clone(uplink, uplink.Faker, group=group, auto_remote_ip=auto_remote_ip)
uplink.Utils.create_new_clone(
uplink=uplink,
faker_instance=uplink.Faker,
group=group,
auto_remote_ip=auto_remote_ip
)
for clone in uplink.Clone.UID_CLONE_DB:

View File

@@ -1,4 +1,4 @@
from typing import Union, TYPE_CHECKING
from typing import Optional, TYPE_CHECKING
from dataclasses import dataclass
if TYPE_CHECKING:
@@ -271,7 +271,7 @@ class Command:
user_uid = self.User.clean_uid(cmd[5])
userObj: MUser = self.User.get_User(user_uid)
channel_name = cmd[4] if self.Channel.Is_Channel(cmd[4]) else None
channel_name = cmd[4] if self.Channel.is_valid_channel(cmd[4]) else None
client_obj = self.Client.get_Client(user_uid)
nickname = userObj.nickname if userObj is not None else None
@@ -296,7 +296,7 @@ class Command:
except Exception as err:
self.Logs.error(f"General Error: {err}")
def hcmds(self, uidornickname: str, channel_name: Union[str, None], cmd: list, fullcmd: list = []) -> None:
def hcmds(self, uidornickname: str, channel_name: Optional[str], cmd: list, fullcmd: list = []) -> None:
command = str(cmd[0]).lower()
dnickname = self.Config.SERVICE_NICKNAME
@@ -324,7 +324,7 @@ class Command:
# userObj: MUser = self.User.get_User(str(cmd[2]))
nickname = str(cmd[2])
mode = str(cmd[3])
chan: str = str(cmd[4]).lower() if self.Channel.Is_Channel(cmd[4]) else None
chan: str = str(cmd[4]).lower() if self.Channel.is_valid_channel(cmd[4]) else None
sign = mode[0] if mode.startswith( ('+', '-')) else None
clean_mode = mode[1:] if len(mode) > 0 else None
@@ -422,7 +422,7 @@ class Command:
case 'voiceall':
try:
chan_info = self.Channel.get_Channel(fromchannel)
chan_info = self.Channel.get_channel(fromchannel)
set_mode = 'v'
mode:str = ''
users:str = ''
@@ -444,7 +444,7 @@ class Command:
case 'opall':
try:
chan_info = self.Channel.get_Channel(fromchannel)
chan_info = self.Channel.get_channel(fromchannel)
set_mode = 'o'
mode:str = ''
users:str = ''
@@ -739,7 +739,7 @@ class Command:
case 'ban':
# .ban #channel nickname
try:
sentchannel = str(cmd[1]) if self.Channel.Is_Channel(cmd[1]) else None
sentchannel = str(cmd[1]) if self.Channel.is_valid_channel(cmd[1]) else None
if sentchannel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Right command : /msg {dnickname} {command.upper()} [#SALON] [NICKNAME]")
return False
@@ -757,7 +757,7 @@ class Command:
case 'unban':
# .unban #channel nickname
try:
sentchannel = str(cmd[1]) if self.Channel.Is_Channel(cmd[1]) else None
sentchannel = str(cmd[1]) if self.Channel.is_valid_channel(cmd[1]) else None
if sentchannel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Right command : /msg {dnickname} ban [#SALON] [NICKNAME]")
return False
@@ -775,7 +775,7 @@ class Command:
case 'kick':
# .kick #channel nickname reason
try:
sentchannel = str(cmd[1]) if self.Channel.Is_Channel(cmd[1]) else None
sentchannel = str(cmd[1]) if self.Channel.is_valid_channel(cmd[1]) else None
if sentchannel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Right command : /msg {dnickname} ban [#SALON] [NICKNAME]")
return False
@@ -794,7 +794,7 @@ class Command:
case 'kickban':
# .kickban #channel nickname reason
try:
sentchannel = str(cmd[1]) if self.Channel.Is_Channel(cmd[1]) else None
sentchannel = str(cmd[1]) if self.Channel.is_valid_channel(cmd[1]) else None
if sentchannel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Right command : /msg {dnickname} ban [#SALON] [NICKNAME]")
return False
@@ -814,7 +814,7 @@ class Command:
case 'join' | 'assign':
try:
sent_channel = str(cmd[1]) if self.Channel.Is_Channel(cmd[1]) else None
sent_channel = str(cmd[1]) if self.Channel.is_valid_channel(cmd[1]) else None
if sent_channel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"{self.Config.SERVICE_PREFIX}JOIN #channel")
return False
@@ -832,7 +832,7 @@ class Command:
case 'part' | 'unassign':
try:
sent_channel = str(cmd[1]) if self.Channel.Is_Channel(cmd[1]) else None
sent_channel = str(cmd[1]) if self.Channel.is_valid_channel(cmd[1]) else None
if sent_channel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"{self.Config.SERVICE_PREFIX}PART #channel")
return False
@@ -859,7 +859,7 @@ class Command:
return None
chan = str(cmd[1])
if not self.Channel.Is_Channel(chan):
if not self.Channel.is_valid_channel(chan):
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg="The channel must start with #")
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} TOPIC #channel THE_TOPIC_MESSAGE")
return None
@@ -959,7 +959,7 @@ class Command:
chan = str(cmd[1])
if not self.Channel.Is_Channel(chan):
if not self.Channel.is_valid_channel(chan):
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg="The channel must start with #")
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {str(cmd[0]).upper()} #channel")
return None
@@ -980,7 +980,7 @@ class Command:
nickname = str(cmd[1])
chan = str(cmd[2])
if not self.Channel.Is_Channel(chan):
if not self.Channel.is_valid_channel(chan):
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg="The channel must start with #")
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {str(cmd[0]).upper()} NICKNAME #CHANNEL")
return None
@@ -1051,7 +1051,7 @@ class Command:
if len(cmd) == 2:
channel_mode = cmd[1]
if self.Channel.Is_Channel(fromchannel):
if self.Channel.is_valid_channel(fromchannel):
self.Protocol.send2socket(f":{dnickname} MODE {fromchannel} {channel_mode}")
else:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Right command : Channel [{fromchannel}] is not correct should start with #")

View File

@@ -7,39 +7,42 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from core.irc import Irc
class Defender():
class Defender:
def __init__(self, ircInstance: 'Irc') -> None:
def __init__(self, irc_instance: 'Irc') -> None:
# Module name (Mandatory)
self.module_name = 'mod_' + str(self.__class__.__name__).lower()
# Add Irc Object to the module (Mandatory)
self.Irc = ircInstance
self.Irc = irc_instance
# Add Loader Object to the module (Mandatory)
self.Loader = ircInstance.Loader
self.Loader = irc_instance.Loader
# Add server protocol Object to the module (Mandatory)
self.Protocol = ircInstance.Protocol
self.Protocol = irc_instance.Protocol
# Add Global Configuration to the module (Mandatory)
self.Config = ircInstance.Config
self.Config = irc_instance.Config
# Add Base object to the module (Mandatory)
self.Base = ircInstance.Base
self.Base = irc_instance.Base
# Add logs object to the module (Mandatory)
self.Logs = ircInstance.Base.logs
self.Logs = irc_instance.Base.logs
# Add User object to the module (Mandatory)
self.User = ircInstance.User
self.User = irc_instance.User
# Add Channel object to the module (Mandatory)
self.Channel = ircInstance.Channel
self.Channel = irc_instance.Channel
# Add Settings object to save objects when reloading modules (Mandatory)
self.Settings = irc_instance.Settings
# Add Reputation object to the module (Optional)
self.Reputation = ircInstance.Reputation
self.Reputation = irc_instance.Reputation
# Add module schemas
self.Schemas = schemas
@@ -158,10 +161,39 @@ class Defender():
self.Base.db_update_core_config(self.module_name, self.ModConfig, param_key, param_value)
def __onload(self):
abuseipdb = self.Settings.get_cache('ABUSEIPDB')
freeipapi = self.Settings.get_cache('FREEIPAPI')
cloudfilt = self.Settings.get_cache('CLOUDFILT')
psutils = self.Settings.get_cache('PSUTIL')
localscan = self.Settings.get_cache('LOCALSCAN')
if abuseipdb:
self.Schemas.DB_ABUSEIPDB_USERS = abuseipdb
if freeipapi:
self.Schemas.DB_FREEIPAPI_USERS = freeipapi
if cloudfilt:
self.Schemas.DB_CLOUD_FILT_USERS = cloudfilt
if psutils:
self.Schemas.DB_PSUTIL_USERS = psutils
if localscan:
self.Schemas.DB_LOCALSCAN_USERS = localscan
def unload(self) -> None:
"""Cette methode sera executée a chaque désactivation ou
rechargement de module
"""
self.Settings.set_cache('ABUSEIPDB', self.Schemas.DB_ABUSEIPDB_USERS)
self.Settings.set_cache('FREEIPAPI', self.Schemas.DB_FREEIPAPI_USERS)
self.Settings.set_cache('CLOUDFILT', self.Schemas.DB_CLOUDFILT_USERS)
self.Settings.set_cache('PSUTIL', self.Schemas.DB_PSUTIL_USERS)
self.Settings.set_cache('LOCALSCAN', self.Schemas.DB_LOCALSCAN_USERS)
self.Schemas.DB_ABUSEIPDB_USERS = []
self.Schemas.DB_FREEIPAPI_USERS = []
self.Schemas.DB_CLOUDFILT_USERS = []
@@ -300,7 +332,7 @@ class Defender():
command = str(cmd[0]).lower()
fromuser = user
channel = fromchannel = channel if self.Channel.Is_Channel(channel) else None
channel = fromchannel = channel if self.Channel.is_valid_channel(channel) else None
dnickname = self.Config.SERVICE_NICKNAME # Defender nickname
dchanlog = self.Config.SERVICE_CHANLOG # Defender chan log

View File

@@ -155,7 +155,7 @@ def timer_release_mode_mute(uplink: 'Defender', action: str, channel: str):
"""
service_id = uplink.Config.SERVICE_ID
if not uplink.Channel.Is_Channel(channel):
if not uplink.Channel.is_valid_channel(channel):
uplink.Logs.debug(f"Channel is not valid {channel}")
return

View File

@@ -52,7 +52,7 @@ def handle_on_mode(uplink: 'Defender', srvmsg: list[str]):
if confmodel.autolimit == 1:
if mode == '+l' or mode == '-l':
chan = irc.Channel.get_Channel(channel)
chan = irc.Channel.get_channel(channel)
p.send2socket(f":{gconfig.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + confmodel.autolimit_amount}")
if gconfig.SALON_JAIL == channel:
@@ -80,7 +80,7 @@ def handle_on_sjoin(uplink: 'Defender', srvmsg: list[str]):
gconfig = uplink.Config
confmodel = uplink.ModConfig
parsed_chan = srvmsg[4] if irc.Channel.Is_Channel(srvmsg[4]) else None
parsed_chan = srvmsg[4] if irc.Channel.is_valid_channel(srvmsg[4]) else None
parsed_UID = irc.User.clean_uid(srvmsg[5])
if parsed_chan is None or parsed_UID is None:
@@ -265,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(channel_to_check=channel):
if User is None or not irc.Channel.is_valid_channel(channel_to_check=channel):
return
flood_time = confmodel.flood_time

View File

@@ -190,7 +190,7 @@ class Jsonrpc():
self.Base.db_update_core_config(self.module_name, self.ModConfig, param_key, param_value)
def unload(self) -> None:
if self.UnrealIrcdRpcLive.Error.code != -1:
if self.UnrealIrcdRpcLive.get_error.code != -1:
self.UnrealIrcdRpcLive.unsubscribe()
return None
@@ -271,16 +271,13 @@ class Jsonrpc():
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'{rpc.get_error.message}')
return None
chan_list = []
for chan in UserInfo.user.channels:
chan_list.append(chan.name)
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'UID : {UserInfo.id}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'NICKNAME : {UserInfo.name}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'USERNAME : {UserInfo.user.username}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'REALNAME : {UserInfo.user.realname}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'MODES : {UserInfo.user.modes}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'CHANNELS : {chan_list}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'CHANNELS : {[chan.name for chan in UserInfo.user.channels]}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'SECURITY GROUP : {UserInfo.user.security_groups}')
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f'REPUTATION : {UserInfo.user.reputation}')

View File

@@ -291,7 +291,7 @@ class Votekick():
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' :Your are not allowed to execute this command')
return None
sentchannel = str(cmd[2]).lower() if self.Channel.Is_Channel(str(cmd[2]).lower()) else None
sentchannel = str(cmd[2]).lower() if self.Channel.is_valid_channel(str(cmd[2]).lower()) else None
if sentchannel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f" The correct command is {self.Config.SERVICE_PREFIX}{command} {option} #CHANNEL")
@@ -325,7 +325,7 @@ class Votekick():
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f" Your are not allowed to execute this command")
return None
sentchannel = str(cmd[2]).lower() if self.Channel.Is_Channel(str(cmd[2]).lower()) else None
sentchannel = str(cmd[2]).lower() if self.Channel.is_valid_channel(str(cmd[2]).lower()) else None
if sentchannel is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f" The correct command is {self.Config.SERVICE_PREFIX}{command} {option} #CHANNEL")
@@ -459,7 +459,7 @@ class Votekick():
return False
uid_cleaned = self.Base.clean_uid(uid_submitted)
ChannelInfo = self.Channel.get_Channel(channel)
ChannelInfo = self.Channel.get_channel(channel)
if ChannelInfo is None:
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,msg=f' This channel [{channel}] do not exist in the Channel Object')
return False