mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
Update Votekick module! following the same structure as other modules
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Any
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
@@ -55,6 +55,9 @@ class Votekick():
|
||||
# Add Channel object to the module
|
||||
self.Channel = ircInstance.Channel
|
||||
|
||||
# Add Utils.
|
||||
self.Utils = ircInstance.Utils
|
||||
|
||||
# Créer les nouvelles commandes du module
|
||||
self.Irc.build_command(1, self.module_name, 'vote', 'The kick vote module')
|
||||
|
||||
@@ -150,7 +153,7 @@ class Votekick():
|
||||
Args:
|
||||
channel (str): le salon à enregistrer.
|
||||
"""
|
||||
current_datetime = self.Base.get_datetime()
|
||||
current_datetime = self.Utils.get_sdatetime()
|
||||
mes_donnees = {'channel': channel}
|
||||
|
||||
response = self.Base.db_execute_query("SELECT id FROM votekick_channel WHERE channel = :channel", mes_donnees)
|
||||
@@ -256,7 +259,7 @@ class Votekick():
|
||||
except Exception as err:
|
||||
self.Logs.error(f"General Error: {err}")
|
||||
|
||||
def hcmds(self, user:str, channel: any, cmd: list, fullcmd: list = []) -> None:
|
||||
def hcmds(self, user:str, channel: Any, cmd: list, fullcmd: list = []) -> None:
|
||||
# cmd is the command starting from the user command
|
||||
# full cmd is sending the entire server response
|
||||
|
||||
|
||||
11
mods/votekick/schemas.py
Normal file
11
mods/votekick/schemas.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from typing import Optional
|
||||
from core.definition import MainModel, dataclass, field
|
||||
|
||||
|
||||
@dataclass
|
||||
class VoteChannelModel(MainModel):
|
||||
channel_name: Optional[str] = None
|
||||
target_user: Optional[str] = None
|
||||
voter_users: list = field(default_factory=list)
|
||||
vote_for: int = 0
|
||||
vote_against: int = 0
|
||||
98
mods/votekick/votekick_manager.py
Normal file
98
mods/votekick/votekick_manager.py
Normal file
@@ -0,0 +1,98 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from mods.votekick.schemas import VoteChannelModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from mods.votekick.mod_votekick import Votekick
|
||||
|
||||
class VotekickManager:
|
||||
|
||||
VOTE_CHANNEL_DB:list[VoteChannelModel] = []
|
||||
|
||||
def __init__(self, uplink: 'Votekick'):
|
||||
self.uplink = uplink
|
||||
self.Logs = uplink.Logs
|
||||
self.Utils = uplink.Utils
|
||||
|
||||
def activate_new_channel(self, channel_name: str) -> bool:
|
||||
"""Activate a new channel in the votekick systeme
|
||||
|
||||
Args:
|
||||
channel_name (str): The channel name you want to activate
|
||||
|
||||
Returns:
|
||||
bool: True if it was activated
|
||||
"""
|
||||
votec = self.get_vote_channel_model(channel_name)
|
||||
|
||||
if votec is None:
|
||||
self.VOTE_CHANNEL_DB.append(
|
||||
VoteChannelModel(
|
||||
channel_name=channel_name,
|
||||
target_user='',
|
||||
voter_users=[],
|
||||
vote_for=0,
|
||||
vote_against=0
|
||||
)
|
||||
)
|
||||
self.Logs.debug(f"[VOTEKICK MANAGER] {channel_name} has been activated.")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def get_vote_channel_model(self, channel_name: str) -> Optional[VoteChannelModel]:
|
||||
"""Get Vote Channel Object model
|
||||
|
||||
Args:
|
||||
channel_name (str): The channel name you want to activate
|
||||
|
||||
Returns:
|
||||
(VoteChannelModel | None): The VoteChannelModel if exist
|
||||
"""
|
||||
for vote in self.VOTE_CHANNEL_DB:
|
||||
if vote.channel_name.lower() == channel_name.lower():
|
||||
self.Logs.debug(f"[VOTEKICK MANAGER] {channel_name} has been found in the VOTE_CHANNEL_DB")
|
||||
return vote
|
||||
|
||||
return None
|
||||
|
||||
def drop_vote_channel_model(self, channel_name: str) -> bool:
|
||||
"""Drop a channel from the votekick system.
|
||||
|
||||
Args:
|
||||
channel_name (str): The channel name you want to drop
|
||||
|
||||
Returns:
|
||||
bool: True if the channel has been droped.
|
||||
"""
|
||||
votec = self.get_vote_channel_model(channel_name)
|
||||
|
||||
if votec:
|
||||
self.VOTE_CHANNEL_DB.remove(votec)
|
||||
self.Logs.debug(f"[VOTEKICK MANAGER] {channel_name} has been removed from the VOTE_CHANNEL_DB")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def is_vote_ongoing(self, channel_name: str) -> bool:
|
||||
"""Check if there is an angoing vote on the channel provided
|
||||
|
||||
Args:
|
||||
channel_name (str): The channel name to check
|
||||
|
||||
Returns:
|
||||
bool: True if there is an ongoing vote on the channel provided.
|
||||
"""
|
||||
|
||||
votec = self.get_vote_channel_model(channel_name)
|
||||
|
||||
if votec is None:
|
||||
self.Logs.debug(f"[VOTEKICK MANAGER] {channel_name} is not activated!")
|
||||
return False
|
||||
|
||||
if votec.target_user:
|
||||
self.Logs.debug(f'[VOTEKICK MANAGER] A vote is ongoing on {channel_name}')
|
||||
return True
|
||||
|
||||
self.Logs.debug(f'[VOTEKICK MANAGER] {channel_name} is activated but there is no ongoing vote!')
|
||||
|
||||
return False
|
||||
Reference in New Issue
Block a user