mod_defender:

- New command added in reputation (release)
    to release a known user.
base.py:
    - Switch deprecated getName() method
    to name attribute (In threading methods)
This commit is contained in:
adator
2025-08-07 23:15:18 +02:00
parent 64f1490942
commit 9df18de0b1
3 changed files with 58 additions and 14 deletions

View File

@@ -465,7 +465,7 @@ class Base:
try: try:
t = threading.Timer(interval=time_to_wait, function=func, args=func_args) t = threading.Timer(interval=time_to_wait, function=func, args=func_args)
t.setName(func.__name__) t.name = func.__name__
t.start() t.start()
self.running_timers.append(t) self.running_timers.append(t)
@@ -488,14 +488,14 @@ class Base:
if run_once: if run_once:
for thread in self.running_threads: for thread in self.running_threads:
if thread.getName() == func_name: if thread.name == func_name:
return None return None
th = threading.Thread(target=func, args=func_args, name=str(func_name), daemon=daemon) th = threading.Thread(target=func, args=func_args, name=str(func_name), daemon=daemon)
th.start() th.start()
self.running_threads.append(th) self.running_threads.append(th)
self.logs.debug(f"-- Thread ID : {str(th.ident)} | Thread name : {th.getName()} | Running Threads : {len(threading.enumerate())}") self.logs.debug(f"-- Thread ID : {str(th.ident)} | Thread name : {th.name} | Running Threads : {len(threading.enumerate())}")
except AssertionError as ae: except AssertionError as ae:
self.logs.error(f'{ae}') self.logs.error(f'{ae}')
@@ -514,7 +514,7 @@ class Base:
count = 0 count = 0
for thr in self.running_threads: for thr in self.running_threads:
if thread_name == thr.getName(): if thread_name == thr.name:
count += 1 count += 1
return count return count
@@ -540,11 +540,10 @@ class Base:
""" """
try: try:
for thread in self.running_threads: for thread in self.running_threads:
if thread.getName() != 'heartbeat': if thread.name != 'heartbeat':
# print(thread.getName(), thread.is_alive(), sep=' / ')
if not thread.is_alive(): if not thread.is_alive():
self.running_threads.remove(thread) self.running_threads.remove(thread)
self.logs.info(f"-- Thread {str(thread.getName())} {str(thread.native_id)} removed") self.logs.info(f"-- Thread {str(thread.name)} {str(thread.native_id)} removed")
# print(threading.enumerate()) # print(threading.enumerate())
except AssertionError as ae: except AssertionError as ae:
@@ -568,19 +567,19 @@ class Base:
self.logs.debug(f"=======> Checking for Timers to stop") self.logs.debug(f"=======> Checking for Timers to stop")
for timer in self.running_timers: for timer in self.running_timers:
while timer.is_alive(): while timer.is_alive():
self.logs.debug(f"> waiting for {timer.getName()} to close") self.logs.debug(f"> waiting for {timer.name} to close")
timer.cancel() timer.cancel()
time.sleep(0.2) time.sleep(0.2)
self.running_timers.remove(timer) self.running_timers.remove(timer)
self.logs.debug(f"> Cancelling {timer.getName()} {timer.native_id}") self.logs.debug(f"> Cancelling {timer.name} {timer.native_id}")
self.logs.debug(f"=======> Checking for Threads to stop") self.logs.debug(f"=======> Checking for Threads to stop")
for thread in self.running_threads: for thread in self.running_threads:
if thread.getName() == 'heartbeat' and thread.is_alive(): if thread.name == 'heartbeat' and thread.is_alive():
self.execute_periodic_action() self.execute_periodic_action()
self.logs.debug(f"> Running the last periodic action") self.logs.debug(f"> Running the last periodic action")
self.running_threads.remove(thread) self.running_threads.remove(thread)
self.logs.debug(f"> Cancelling {thread.getName()} {thread.native_id}") self.logs.debug(f"> Cancelling {thread.name} {thread.native_id}")
self.logs.debug(f"=======> Checking for Sockets to stop") self.logs.debug(f"=======> Checking for Sockets to stop")
for soc in self.running_sockets: for soc in self.running_sockets:

View File

@@ -2,6 +2,7 @@ import socket
import json import json
import time import time
import re import re
from webbrowser import get
import psutil import psutil
import requests import requests
from dataclasses import dataclass from dataclasses import dataclass
@@ -1325,9 +1326,13 @@ class Defender():
# .reputation [on/off] --> activate or deactivate reputation system # .reputation [on/off] --> activate or deactivate reputation system
# .reputation set banallchan [on/off] --> activate or deactivate ban in all channel # .reputation set banallchan [on/off] --> activate or deactivate ban in all channel
# .reputation set limit [xxxx] --> change the reputation threshold # .reputation set limit [xxxx] --> change the reputation threshold
# .reputation release [nick]
# .reputation [arg1] [arg2] [arg3] # .reputation [arg1] [arg2] [arg3]
try: try:
len_cmd = len(cmd) len_cmd = len(cmd)
if len_cmd < 2:
raise IndexError("Showing help!")
activation = str(cmd[1]).lower() activation = str(cmd[1]).lower()
# Nous sommes dans l'activation ON / OFF # Nous sommes dans l'activation ON / OFF
@@ -1384,7 +1389,47 @@ class Defender():
self.Channel.db_query_channel('del', self.module_name, jail_chan) self.Channel.db_query_channel('del', self.module_name, jail_chan)
if len_cmd == 4: if len_cmd == 3:
get_options = str(cmd[1]).lower()
match get_options:
case 'release':
# .reputation release [nick]
p = self.Protocol
link = self.Config.SERVEUR_LINK
jailed_salon = self.Config.SALON_JAIL
welcome_salon = self.Config.SALON_LIBERER
client_obj = self.User.get_User(str(cmd[2]))
client_to_release = self.Reputation.get_Reputation(client_obj.uid)
if client_to_release is None:
p.send_notice(nick_from=dnickname,
nick_to=fromuser, msg=f"This nickname doesn't exist - {str(cmd[1])}")
return None
if self.Reputation.delete(client_to_release.uid):
p.send_priv_msg(
nick_from=dnickname,
msg=f"[ {self.Config.COLORS.green}REPUTATION RELEASE{self.Config.COLORS.black} ] : {client_to_release.nickname} has been released",
channel=dchanlog)
p.send_notice(nick_from=dnickname,
nick_to=fromuser, msg=f"This nickname has been released from reputation system")
p.send_notice(nick_from=dnickname,
nick_to=client_to_release.nickname, msg=f"You have been released from the reputation system by ({fromuser})")
p.send_sapart(nick_to_sapart=client_to_release.nickname, channel_name=jailed_salon)
p.send_sajoin(nick_to_sajoin=client_to_release.nickname, channel_name=welcome_salon)
p.send2socket(f":{link} REPUTATION {client_to_release.remote_ip} {self.ModConfig.reputation_score_after_release}")
return None
else:
p.send_priv_msg(
nick_from=dnickname,
msg=f"[ {self.Config.COLORS.red}REPUTATION RELEASE ERROR{self.Config.COLORS.black} ] : "
f"{client_to_release.nickname} has not been released! as he is not in the reputation database",
channel=dchanlog
)
if len_cmd > 4:
get_set = str(cmd[1]).lower() get_set = str(cmd[1]).lower()
if get_set != 'set': if get_set != 'set':
@@ -1393,7 +1438,7 @@ class Defender():
get_options = str(cmd[2]).lower() get_options = str(cmd[2]).lower()
match get_options: match get_options:
case 'banallchan': case 'banallchan':
key = 'reputation_ban_all_chan' key = 'reputation_ban_all_chan'
get_value = str(cmd[3]).lower() get_value = str(cmd[3]).lower()

View File

@@ -1,5 +1,5 @@
{ {
"version": "6.1.3", "version": "6.1.4",
"requests": "2.32.3", "requests": "2.32.3",
"psutil": "6.0.0", "psutil": "6.0.0",