From 10cad7cda651e79cbd36ed8837e1c697c8521380 Mon Sep 17 00:00:00 2001 From: adator <85586985+adator85@users.noreply.github.com> Date: Tue, 11 Nov 2025 03:48:20 +0100 Subject: [PATCH] Refactoring code! --- core/classes/interfaces/imodule.py | 9 ++------- core/utils.py | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/core/classes/interfaces/imodule.py b/core/classes/interfaces/imodule.py index 901c3d2..72c0c8c 100644 --- a/core/classes/interfaces/imodule.py +++ b/core/classes/interfaces/imodule.py @@ -1,7 +1,6 @@ from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Optional from dataclasses import dataclass -from mods.clone.schemas import ModConfModel if TYPE_CHECKING: from core.irc import Irc @@ -89,13 +88,9 @@ class IModule(ABC): @abstractmethod def create_tables(self) -> None: - """ - Method that will create the database if it does not exist. + """Method that will create the database if it does not exist. A single Session for this class will be created, which will be used within this class/module. - Args: - database_name (str): Name of the database (no spaces allowed in the name) - Returns: None: No return is expected """ @@ -119,7 +114,7 @@ class IModule(ABC): """ @abstractmethod - def hcmds(self, user: str, channel: Optional[str], cmd: list, fullcmd: list = []) -> None: + def hcmds(self, user: str, channel: Optional[str], cmd: list[str], fullcmd: Optional[list[str]] = None) -> None: """These are the commands recieved from a client Args: diff --git a/core/utils.py b/core/utils.py index bf2a397..e79752d 100644 --- a/core/utils.py +++ b/core/utils.py @@ -1,15 +1,14 @@ -''' +""" Main utils library. -''' +""" import gc import ssl import socket import sys from pathlib import Path from re import match, sub -from base64 import b64decode from typing import Literal, Optional, Any, TYPE_CHECKING -from datetime import datetime, timedelta, timezone +from datetime import datetime from time import time from random import choice from hashlib import md5, sha3_512 @@ -84,9 +83,9 @@ def get_unixtime() -> int: Returns: int: Current time in seconds since the Epoch (int) """ - cet_offset = timezone(timedelta(hours=2)) - now_cet = datetime.now(cet_offset) - unixtime_cet = int(now_cet.timestamp()) + # cet_offset = timezone(timedelta(hours=2)) + # now_cet = datetime.now(cet_offset) + # unixtime_cet = int(now_cet.timestamp()) return int(time()) def get_sdatetime() -> str: @@ -142,9 +141,9 @@ def create_socket(uplink: 'Irc') -> None: except OSError as oe: uplink.Logs.critical(f"[OS Error]: {oe}") if 'connection refused' in str(oe).lower(): - sys.exit(oe) + sys.exit(oe.__str__()) if oe.errno == 10053: - sys.exit(oe) + sys.exit(oe.__str__()) except AttributeError as ae: uplink.Logs.critical(f"AttributeError: {ae}") @@ -225,9 +224,9 @@ def clean_uid(uid: str) -> Optional[str]: return None pattern = fr'[:|@|%|\+|~|\*]*' - parsed_UID = sub(pattern, '', uid) + parsed_uid = sub(pattern, '', uid) - return parsed_UID + return parsed_uid def hide_sensitive_data(srvmsg: list[str]) -> list[str]: try: