mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
Refactoring code!
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from mods.clone.schemas import ModConfModel
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.irc import Irc
|
from core.irc import Irc
|
||||||
@@ -89,13 +88,9 @@ class IModule(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def create_tables(self) -> None:
|
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.
|
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:
|
Returns:
|
||||||
None: No return is expected
|
None: No return is expected
|
||||||
"""
|
"""
|
||||||
@@ -119,7 +114,7 @@ class IModule(ABC):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
"""These are the commands recieved from a client
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
'''
|
"""
|
||||||
Main utils library.
|
Main utils library.
|
||||||
'''
|
"""
|
||||||
import gc
|
import gc
|
||||||
import ssl
|
import ssl
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from re import match, sub
|
from re import match, sub
|
||||||
from base64 import b64decode
|
|
||||||
from typing import Literal, Optional, Any, TYPE_CHECKING
|
from typing import Literal, Optional, Any, TYPE_CHECKING
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime
|
||||||
from time import time
|
from time import time
|
||||||
from random import choice
|
from random import choice
|
||||||
from hashlib import md5, sha3_512
|
from hashlib import md5, sha3_512
|
||||||
@@ -84,9 +83,9 @@ def get_unixtime() -> int:
|
|||||||
Returns:
|
Returns:
|
||||||
int: Current time in seconds since the Epoch (int)
|
int: Current time in seconds since the Epoch (int)
|
||||||
"""
|
"""
|
||||||
cet_offset = timezone(timedelta(hours=2))
|
# cet_offset = timezone(timedelta(hours=2))
|
||||||
now_cet = datetime.now(cet_offset)
|
# now_cet = datetime.now(cet_offset)
|
||||||
unixtime_cet = int(now_cet.timestamp())
|
# unixtime_cet = int(now_cet.timestamp())
|
||||||
return int(time())
|
return int(time())
|
||||||
|
|
||||||
def get_sdatetime() -> str:
|
def get_sdatetime() -> str:
|
||||||
@@ -142,9 +141,9 @@ def create_socket(uplink: 'Irc') -> None:
|
|||||||
except OSError as oe:
|
except OSError as oe:
|
||||||
uplink.Logs.critical(f"[OS Error]: {oe}")
|
uplink.Logs.critical(f"[OS Error]: {oe}")
|
||||||
if 'connection refused' in str(oe).lower():
|
if 'connection refused' in str(oe).lower():
|
||||||
sys.exit(oe)
|
sys.exit(oe.__str__())
|
||||||
if oe.errno == 10053:
|
if oe.errno == 10053:
|
||||||
sys.exit(oe)
|
sys.exit(oe.__str__())
|
||||||
except AttributeError as ae:
|
except AttributeError as ae:
|
||||||
uplink.Logs.critical(f"AttributeError: {ae}")
|
uplink.Logs.critical(f"AttributeError: {ae}")
|
||||||
|
|
||||||
@@ -225,9 +224,9 @@ def clean_uid(uid: str) -> Optional[str]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
pattern = fr'[:|@|%|\+|~|\*]*'
|
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]:
|
def hide_sensitive_data(srvmsg: list[str]) -> list[str]:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user