mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
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:
21
core/base.py
21
core/base.py
@@ -465,7 +465,7 @@ class Base:
|
||||
|
||||
try:
|
||||
t = threading.Timer(interval=time_to_wait, function=func, args=func_args)
|
||||
t.setName(func.__name__)
|
||||
t.name = func.__name__
|
||||
t.start()
|
||||
|
||||
self.running_timers.append(t)
|
||||
@@ -488,14 +488,14 @@ class Base:
|
||||
|
||||
if run_once:
|
||||
for thread in self.running_threads:
|
||||
if thread.getName() == func_name:
|
||||
if thread.name == func_name:
|
||||
return None
|
||||
|
||||
th = threading.Thread(target=func, args=func_args, name=str(func_name), daemon=daemon)
|
||||
th.start()
|
||||
|
||||
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:
|
||||
self.logs.error(f'{ae}')
|
||||
@@ -514,7 +514,7 @@ class Base:
|
||||
count = 0
|
||||
|
||||
for thr in self.running_threads:
|
||||
if thread_name == thr.getName():
|
||||
if thread_name == thr.name:
|
||||
count += 1
|
||||
|
||||
return count
|
||||
@@ -540,11 +540,10 @@ class Base:
|
||||
"""
|
||||
try:
|
||||
for thread in self.running_threads:
|
||||
if thread.getName() != 'heartbeat':
|
||||
# print(thread.getName(), thread.is_alive(), sep=' / ')
|
||||
if thread.name != 'heartbeat':
|
||||
if not thread.is_alive():
|
||||
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())
|
||||
except AssertionError as ae:
|
||||
@@ -568,19 +567,19 @@ class Base:
|
||||
self.logs.debug(f"=======> Checking for Timers to stop")
|
||||
for timer in self.running_timers:
|
||||
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()
|
||||
time.sleep(0.2)
|
||||
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")
|
||||
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.logs.debug(f"> Running the last periodic action")
|
||||
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")
|
||||
for soc in self.running_sockets:
|
||||
|
||||
@@ -2,6 +2,7 @@ import socket
|
||||
import json
|
||||
import time
|
||||
import re
|
||||
from webbrowser import get
|
||||
import psutil
|
||||
import requests
|
||||
from dataclasses import dataclass
|
||||
@@ -1325,9 +1326,13 @@ class Defender():
|
||||
# .reputation [on/off] --> activate or deactivate reputation system
|
||||
# .reputation set banallchan [on/off] --> activate or deactivate ban in all channel
|
||||
# .reputation set limit [xxxx] --> change the reputation threshold
|
||||
# .reputation release [nick]
|
||||
# .reputation [arg1] [arg2] [arg3]
|
||||
try:
|
||||
len_cmd = len(cmd)
|
||||
if len_cmd < 2:
|
||||
raise IndexError("Showing help!")
|
||||
|
||||
activation = str(cmd[1]).lower()
|
||||
|
||||
# Nous sommes dans l'activation ON / OFF
|
||||
@@ -1384,7 +1389,47 @@ class Defender():
|
||||
|
||||
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()
|
||||
|
||||
if get_set != 'set':
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "6.1.3",
|
||||
"version": "6.1.4",
|
||||
|
||||
"requests": "2.32.3",
|
||||
"psutil": "6.0.0",
|
||||
|
||||
Reference in New Issue
Block a user