mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
Introduce full asyncio version (still some module to migrate). Defender JSONRPC Server ready and using with uvcorn
This commit is contained in:
@@ -10,7 +10,7 @@ class CloneManager:
|
||||
|
||||
def __init__(self, uplink: 'Clone'):
|
||||
|
||||
self.Logs = uplink.Logs
|
||||
self.Logs = uplink.ctx.Logs
|
||||
|
||||
def insert(self, new_clone_object: MClone) -> bool:
|
||||
"""Create new Clone object
|
||||
|
||||
@@ -8,6 +8,7 @@ from mods.clone.clone_manager import CloneManager
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from faker import Faker
|
||||
from core.loader import Loader
|
||||
|
||||
class Clone(IModule):
|
||||
|
||||
@@ -23,7 +24,15 @@ class Clone(IModule):
|
||||
'core_version':'Defender-6'
|
||||
}
|
||||
|
||||
def create_tables(self) -> None:
|
||||
def __init__(self, context: 'Loader') -> None:
|
||||
super().__init__(context)
|
||||
self._mod_config: Optional[schemas.ModConfModel] = None
|
||||
|
||||
@property
|
||||
def mod_config(self) -> ModConfModel:
|
||||
return self._mod_config
|
||||
|
||||
async def create_tables(self) -> None:
|
||||
"""Methode qui va créer la base de donnée si elle n'existe pas.
|
||||
Une Session unique pour cette classe sera crée, qui sera utilisé dans cette classe / module
|
||||
|
||||
@@ -39,63 +48,69 @@ class Clone(IModule):
|
||||
)
|
||||
'''
|
||||
|
||||
# self.Base.db_execute_query(table_channel)
|
||||
# await self.ctx.Base.db_execute_query(table_channel)
|
||||
|
||||
return None
|
||||
|
||||
def load(self) -> None:
|
||||
self.ModConfig = self.ModConfModel()
|
||||
async def load(self) -> None:
|
||||
|
||||
# Variable qui va contenir les options de configuration du module Defender
|
||||
self._mod_config: schemas.ModConfModel = self.ModConfModel()
|
||||
|
||||
# sync the database with local variable (Mandatory)
|
||||
await self.sync_db()
|
||||
|
||||
self.stop = False
|
||||
self.Schemas = schemas
|
||||
self.Utils = utils
|
||||
self.Threads = thds
|
||||
self.Faker: Optional['Faker'] = self.Utils.create_faker_object('en_GB')
|
||||
self.Clone = CloneManager(self)
|
||||
metadata = self.Settings.get_cache('UID_CLONE_DB')
|
||||
metadata = self.ctx.Settings.get_cache('UID_CLONE_DB')
|
||||
|
||||
if metadata is not None:
|
||||
self.Clone.UID_CLONE_DB = metadata
|
||||
self.Logs.debug(f"Cache Size = {self.Settings.get_cache_size()}")
|
||||
self.ctx.Logs.debug(f"Cache Size = {self.ctx.Settings.get_cache_size()}")
|
||||
|
||||
# Créer les nouvelles commandes du module
|
||||
self.Irc.build_command(1, self.module_name, 'clone', 'Connect, join, part, kill and say clones')
|
||||
self.ctx.Irc.build_command(1, self.module_name, 'clone', 'Connect, join, part, kill and say clones')
|
||||
|
||||
self.Channel.db_query_channel(action='add', module_name=self.module_name, channel_name=self.Config.CLONE_CHANNEL)
|
||||
self.Protocol.send_sjoin(self.Config.CLONE_CHANNEL)
|
||||
self.Protocol.send_set_mode('+o', nickname=self.Config.SERVICE_NICKNAME, channel_name=self.Config.CLONE_CHANNEL)
|
||||
self.Protocol.send_set_mode('+nts', channel_name=self.Config.CLONE_CHANNEL)
|
||||
self.Protocol.send_set_mode('+k', channel_name=self.Config.CLONE_CHANNEL, params=self.Config.CLONE_CHANNEL_PASSWORD)
|
||||
await self.ctx.Channel.db_query_channel(action='add', module_name=self.module_name, channel_name=self.ctx.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Irc.Protocol.send_sjoin(self.ctx.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Irc.Protocol.send_set_mode('+o', nickname=self.ctx.Config.SERVICE_NICKNAME, channel_name=self.ctx.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Irc.Protocol.send_set_mode('+nts', channel_name=self.ctx.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Irc.Protocol.send_set_mode('+k', channel_name=self.ctx.Config.CLONE_CHANNEL, params=self.ctx.Config.CLONE_CHANNEL_PASSWORD)
|
||||
|
||||
def unload(self) -> None:
|
||||
async def unload(self) -> None:
|
||||
"""Cette methode sera executée a chaque désactivation ou
|
||||
rechargement de module
|
||||
"""
|
||||
# Store Clones DB into the global Settings to retrieve it after the reload.
|
||||
self.Settings.set_cache('UID_CLONE_DB', self.Clone.UID_CLONE_DB)
|
||||
self.ctx.Settings.set_cache('UID_CLONE_DB', self.Clone.UID_CLONE_DB)
|
||||
|
||||
self.Channel.db_query_channel(action='del', module_name=self.module_name, channel_name=self.Config.CLONE_CHANNEL)
|
||||
self.Protocol.send_set_mode('-nts', channel_name=self.Config.CLONE_CHANNEL)
|
||||
self.Protocol.send_set_mode('-k', channel_name=self.Config.CLONE_CHANNEL)
|
||||
self.Protocol.send_part_chan(self.Config.SERVICE_NICKNAME, self.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Channel.db_query_channel(action='del', module_name=self.module_name, channel_name=self.ctx.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Irc.Protocol.send_set_mode('-nts', channel_name=self.ctx.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Irc.Protocol.send_set_mode('-k', channel_name=self.ctx.Config.CLONE_CHANNEL)
|
||||
await self.ctx.Irc.Protocol.send_part_chan(self.ctx.Config.SERVICE_NICKNAME, self.ctx.Config.CLONE_CHANNEL)
|
||||
|
||||
self.Irc.Commands.drop_command_by_module(self.module_name)
|
||||
self.ctx.Commands.drop_command_by_module(self.module_name)
|
||||
|
||||
return None
|
||||
|
||||
def cmd(self, data:list) -> None:
|
||||
async def cmd(self, data:list) -> None:
|
||||
try:
|
||||
if not data or len(data) < 2:
|
||||
return None
|
||||
|
||||
cmd = data.copy() if isinstance(data, list) else list(data).copy()
|
||||
index, command = self.Irc.Protocol.get_ircd_protocol_poisition(cmd)
|
||||
index, command = self.ctx.Irc.Protocol.get_ircd_protocol_poisition(cmd)
|
||||
if index == -1:
|
||||
return None
|
||||
|
||||
match command:
|
||||
|
||||
case 'PRIVMSG':
|
||||
self.Utils.handle_on_privmsg(self, cmd)
|
||||
await self.Utils.handle_on_privmsg(self, cmd)
|
||||
return None
|
||||
|
||||
case 'QUIT':
|
||||
@@ -105,10 +120,10 @@ class Clone(IModule):
|
||||
return None
|
||||
|
||||
except Exception as err:
|
||||
self.Logs.error(f'General Error: {err}', exc_info=True)
|
||||
self.ctx.Logs.error(f'General Error: {err}', exc_info=True)
|
||||
return None
|
||||
|
||||
def hcmds(self, user: str, channel: Any, cmd: list, fullcmd: list = []) -> None:
|
||||
async def hcmds(self, user: str, channel: Any, cmd: list, fullcmd: list = []) -> None:
|
||||
|
||||
try:
|
||||
|
||||
@@ -117,18 +132,18 @@ class Clone(IModule):
|
||||
|
||||
command = str(cmd[0]).lower()
|
||||
fromuser = user
|
||||
dnickname = self.Config.SERVICE_NICKNAME
|
||||
dnickname = self.ctx.Config.SERVICE_NICKNAME
|
||||
|
||||
match command:
|
||||
|
||||
case 'clone':
|
||||
|
||||
if len(cmd) == 1:
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone connect NUMBER GROUP_NAME INTERVAL")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone kill [all | group_name | nickname]")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone join [all | group_name | nickname] #channel")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone part [all | group_name | nickname] #channel")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone list [group name]")
|
||||
if len(cmd) < 2:
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone connect NUMBER GROUP_NAME INTERVAL")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone kill [all | group_name | nickname]")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone join [all | group_name | nickname] #channel")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone part [all | group_name | nickname] #channel")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone list [group name]")
|
||||
return None
|
||||
|
||||
option = str(cmd[1]).lower()
|
||||
@@ -143,15 +158,13 @@ class Clone(IModule):
|
||||
group = str(cmd[3]).lower()
|
||||
connection_interval = int(cmd[4]) if len(cmd) == 5 else 0.2
|
||||
|
||||
self.Base.create_thread(
|
||||
func=self.Threads.thread_connect_clones,
|
||||
func_args=(self, number_of_clones, group, False, connection_interval)
|
||||
self.ctx.Base.create_asynctask(
|
||||
func=self.Threads.coro_connect_clones(self, number_of_clones, group, False, connection_interval)
|
||||
)
|
||||
|
||||
except Exception as err:
|
||||
self.Logs.error(f'{err}')
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone connect [number of clone you want to connect] [Group] [freq]")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Exemple /msg {dnickname} clone connect 6 Ambiance")
|
||||
except IndexError:
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone connect [number of clone you want to connect] [Group] [freq]")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Exemple /msg {dnickname} clone connect 6 Ambiance")
|
||||
|
||||
case 'kill':
|
||||
try:
|
||||
@@ -160,27 +173,26 @@ class Clone(IModule):
|
||||
option = str(cmd[2])
|
||||
|
||||
if option.lower() == 'all':
|
||||
self.Base.create_thread(func=self.Threads.thread_kill_clones, func_args=(self, ))
|
||||
self.ctx.Base.create_asynctask(func=self.Threads.thread_kill_clones(self))
|
||||
|
||||
elif self.Clone.group_exists(option):
|
||||
list_of_clones_in_group = self.Clone.get_clones_from_groupname(option)
|
||||
|
||||
if len(list_of_clones_in_group) > 0:
|
||||
self.Logs.debug(f"[Clone Kill Group] - Killing {len(list_of_clones_in_group)} clones in the group {option}")
|
||||
self.ctx.Logs.debug(f"[Clone Kill Group] - Killing {len(list_of_clones_in_group)} clones in the group {option}")
|
||||
|
||||
for clone in list_of_clones_in_group:
|
||||
self.Protocol.send_quit(clone.uid, "Now i am leaving irc but i'll come back soon ...", print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_quit(clone.uid, "Now i am leaving irc but i'll come back soon ...", print_log=False)
|
||||
self.Clone.delete(clone.uid)
|
||||
|
||||
else:
|
||||
clone_obj = self.Clone.get_clone(option)
|
||||
if not clone_obj is None:
|
||||
self.Protocol.send_quit(clone_obj.uid, 'Goood bye', print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_quit(clone_obj.uid, 'Goood bye', print_log=False)
|
||||
self.Clone.delete(clone_obj.uid)
|
||||
|
||||
except Exception as err:
|
||||
self.Logs.error(f'{err}')
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone kill [all | group name | nickname]")
|
||||
except IndexError:
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone kill [all | group name | nickname]")
|
||||
|
||||
case 'join':
|
||||
try:
|
||||
@@ -191,25 +203,24 @@ class Clone(IModule):
|
||||
if option.lower() == 'all':
|
||||
|
||||
for clone in self.Clone.UID_CLONE_DB:
|
||||
self.Protocol.send_join_chan(uidornickname=clone.uid, channel=clone_channel_to_join, print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_join_chan(uidornickname=clone.uid, channel=clone_channel_to_join, print_log=False)
|
||||
|
||||
elif self.Clone.group_exists(option):
|
||||
list_of_clones_in_group = self.Clone.get_clones_from_groupname(option)
|
||||
|
||||
if len(list_of_clones_in_group) > 0:
|
||||
self.Logs.debug(f"[Clone Join Group] - Joining {len(list_of_clones_in_group)} clones from group {option} in the channel {clone_channel_to_join}")
|
||||
self.ctx.Logs.debug(f"[Clone Join Group] - Joining {len(list_of_clones_in_group)} clones from group {option} in the channel {clone_channel_to_join}")
|
||||
|
||||
for clone in list_of_clones_in_group:
|
||||
self.Protocol.send_join_chan(uidornickname=clone.nickname, channel=clone_channel_to_join, print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_join_chan(uidornickname=clone.nickname, channel=clone_channel_to_join, print_log=False)
|
||||
|
||||
else:
|
||||
if self.Clone.nickname_exists(option):
|
||||
clone_uid = self.Clone.get_clone(option).uid
|
||||
self.Protocol.send_join_chan(uidornickname=clone_uid, channel=clone_channel_to_join, print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_join_chan(uidornickname=clone_uid, channel=clone_channel_to_join, print_log=False)
|
||||
|
||||
except Exception as err:
|
||||
self.Logs.error(f'{err}')
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone join [all | group name | nickname] #channel")
|
||||
except IndexError:
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone join [all | group name | nickname] #channel")
|
||||
|
||||
case 'part':
|
||||
try:
|
||||
@@ -220,67 +231,66 @@ class Clone(IModule):
|
||||
if option.lower() == 'all':
|
||||
|
||||
for clone in self.Clone.UID_CLONE_DB:
|
||||
self.Protocol.send_part_chan(uidornickname=clone.uid, channel=clone_channel_to_part, print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_part_chan(uidornickname=clone.uid, channel=clone_channel_to_part, print_log=False)
|
||||
|
||||
elif self.Clone.group_exists(option):
|
||||
list_of_clones_in_group = self.Clone.get_clones_from_groupname(option)
|
||||
|
||||
if len(list_of_clones_in_group) > 0:
|
||||
self.Logs.debug(f"[Clone Part Group] - Part {len(list_of_clones_in_group)} clones from group {option} from the channel {clone_channel_to_part}")
|
||||
self.ctx.Logs.debug(f"[Clone Part Group] - Part {len(list_of_clones_in_group)} clones from group {option} from the channel {clone_channel_to_part}")
|
||||
|
||||
for clone in list_of_clones_in_group:
|
||||
self.Protocol.send_part_chan(uidornickname=clone.uid, channel=clone_channel_to_part, print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_part_chan(uidornickname=clone.uid, channel=clone_channel_to_part, print_log=False)
|
||||
|
||||
else:
|
||||
if self.Clone.nickname_exists(option):
|
||||
clone_uid = self.Clone.get_uid(option)
|
||||
if not clone_uid is None:
|
||||
self.Protocol.send_part_chan(uidornickname=clone_uid, channel=clone_channel_to_part, print_log=False)
|
||||
await self.ctx.Irc.Protocol.send_part_chan(uidornickname=clone_uid, channel=clone_channel_to_part, print_log=False)
|
||||
|
||||
except Exception as err:
|
||||
self.Logs.error(f'{err}')
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone part [all | group name | nickname] #channel")
|
||||
except IndexError:
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone part [all | group name | nickname] #channel")
|
||||
|
||||
case 'list':
|
||||
try:
|
||||
# Syntax. /msg defender clone list <group_name>
|
||||
header = f" {'Nickname':<12}| {'Real name':<25}| {'Group name':<15}| {'Connected':<35}"
|
||||
line = "-"*67
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=header)
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" {line}")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=header)
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" {line}")
|
||||
group_name = cmd[2] if len(cmd) > 2 else None
|
||||
|
||||
if group_name is None:
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Number of connected clones: {len(self.Clone.UID_CLONE_DB)}")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" {line}")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Number of connected clones: {len(self.Clone.UID_CLONE_DB)}")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" {line}")
|
||||
for clone_name in self.Clone.UID_CLONE_DB:
|
||||
self.Protocol.send_notice(
|
||||
await self.ctx.Irc.Protocol.send_notice(
|
||||
nick_from=dnickname,
|
||||
nick_to=fromuser,
|
||||
msg=f" {clone_name.nickname:<12}| {clone_name.realname:<25}| {clone_name.group:<15}| {clone_name.connected:<35}")
|
||||
else:
|
||||
if not self.Clone.group_exists(group_name):
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg="This Group name doesn't exist!")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg="This Group name doesn't exist!")
|
||||
return None
|
||||
clones = self.Clone.get_clones_from_groupname(group_name)
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Number of connected clones: {len(clones)}")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" {line}")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" Number of connected clones: {len(clones)}")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f" {line}")
|
||||
for clone in clones:
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,
|
||||
msg=f" {clone.nickname:<12}| {clone.realname:<25}| {clone.group:<15}| {clone.connected:<35}")
|
||||
except Exception as err:
|
||||
self.Logs.error(f'{err}')
|
||||
except IndexError:
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone list [group name]")
|
||||
|
||||
case 'say':
|
||||
try:
|
||||
# clone say clone_nickname #channel message
|
||||
clone_name = str(cmd[2])
|
||||
clone_channel = str(cmd[3]) if self.Channel.is_valid_channel(str(cmd[3])) else None
|
||||
clone_channel = str(cmd[3]) if self.ctx.Channel.is_valid_channel(str(cmd[3])) else None
|
||||
|
||||
final_message = ' '.join(cmd[4:])
|
||||
|
||||
if clone_channel is None or not self.Clone.nickname_exists(clone_name):
|
||||
self.Protocol.send_notice(
|
||||
await self.ctx.Irc.Protocol.send_notice(
|
||||
nick_from=dnickname,
|
||||
nick_to=fromuser,
|
||||
msg=f"/msg {dnickname} clone say [clone_nickname] #channel message"
|
||||
@@ -288,24 +298,21 @@ class Clone(IModule):
|
||||
return None
|
||||
|
||||
if self.Clone.nickname_exists(clone_name):
|
||||
self.Protocol.send_priv_msg(nick_from=clone_name, msg=final_message, channel=clone_channel)
|
||||
await self.ctx.Irc.Protocol.send_priv_msg(nick_from=clone_name, msg=final_message, channel=clone_channel)
|
||||
|
||||
except Exception as err:
|
||||
self.Logs.error(f'{err}')
|
||||
self.Protocol.send_notice(
|
||||
except IndexError:
|
||||
await self.ctx.Irc.Protocol.send_notice(
|
||||
nick_from=dnickname,
|
||||
nick_to=fromuser,
|
||||
msg=f"/msg {dnickname} clone say [clone_nickname] #channel message"
|
||||
)
|
||||
|
||||
case _:
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone connect NUMBER GROUP_NAME INTERVAL")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone kill [all | group name | nickname]")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone join [all | group name | nickname] #channel")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone part [all | group name | nickname] #channel")
|
||||
self.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone list [group name]")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone connect NUMBER GROUP_NAME INTERVAL")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone kill [all | group name | nickname]")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone join [all | group name | nickname] #channel")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone part [all | group name | nickname] #channel")
|
||||
await self.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} clone list [group name]")
|
||||
|
||||
except IndexError as ie:
|
||||
self.Logs.error(f'Index Error: {ie}')
|
||||
except Exception as err:
|
||||
self.Logs.error(f'General Error: {err}')
|
||||
self.ctx.Logs.error(f'General Error: {err}', exc_info=True)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import asyncio
|
||||
from typing import TYPE_CHECKING
|
||||
from time import sleep
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from mods.clone.mod_clone import Clone
|
||||
|
||||
def thread_connect_clones(uplink: 'Clone',
|
||||
async def coro_connect_clones(uplink: 'Clone',
|
||||
number_of_clones:int ,
|
||||
group: str = 'Default',
|
||||
auto_remote_ip: bool = False,
|
||||
@@ -27,18 +28,18 @@ def thread_connect_clones(uplink: 'Clone',
|
||||
break
|
||||
|
||||
if not clone.connected:
|
||||
uplink.Protocol.send_uid(clone.nickname, clone.username, clone.hostname, clone.uid, clone.umodes, clone.vhost, clone.remote_ip, clone.realname, print_log=False)
|
||||
uplink.Protocol.send_join_chan(uidornickname=clone.uid, channel=uplink.Config.CLONE_CHANNEL, password=uplink.Config.CLONE_CHANNEL_PASSWORD, print_log=False)
|
||||
await uplink.ctx.Irc.Protocol.send_uid(clone.nickname, clone.username, clone.hostname, clone.uid, clone.umodes, clone.vhost, clone.remote_ip, clone.realname, print_log=False)
|
||||
await uplink.ctx.Irc.Protocol.send_join_chan(uidornickname=clone.uid, channel=uplink.ctx.Config.CLONE_CHANNEL, password=uplink.ctx.Config.CLONE_CHANNEL_PASSWORD, print_log=False)
|
||||
|
||||
sleep(interval)
|
||||
await asyncio.sleep(interval)
|
||||
clone.connected = True
|
||||
|
||||
def thread_kill_clones(uplink: 'Clone'):
|
||||
async def thread_kill_clones(uplink: 'Clone'):
|
||||
|
||||
clone_to_kill = uplink.Clone.UID_CLONE_DB.copy()
|
||||
|
||||
for clone in clone_to_kill:
|
||||
uplink.Protocol.send_quit(clone.uid, 'Gooood bye', print_log=False)
|
||||
await uplink.ctx.Irc.Protocol.send_quit(clone.uid, 'Gooood bye', print_log=False)
|
||||
uplink.Clone.delete(clone.uid)
|
||||
|
||||
del clone_to_kill
|
||||
|
||||
@@ -125,8 +125,8 @@ def create_new_clone(uplink: 'Clone', faker_instance: 'Faker', group: str = 'Def
|
||||
"""
|
||||
faker = faker_instance
|
||||
|
||||
uid = generate_uid_for_clone(faker, uplink.Config.SERVEUR_ID)
|
||||
umodes = uplink.Config.CLONE_UMODES
|
||||
uid = generate_uid_for_clone(faker, uplink.ctx.Config.SERVEUR_ID)
|
||||
umodes = uplink.ctx.Config.CLONE_UMODES
|
||||
|
||||
# Generate Username
|
||||
username = generate_username_for_clone(faker)
|
||||
@@ -153,7 +153,7 @@ def create_new_clone(uplink: 'Clone', faker_instance: 'Faker', group: str = 'Def
|
||||
checkNickname = uplink.Clone.nickname_exists(nickname)
|
||||
|
||||
while checkUid:
|
||||
uid = generate_uid_for_clone(faker, uplink.Config.SERVEUR_ID)
|
||||
uid = generate_uid_for_clone(faker, uplink.ctx.Config.SERVEUR_ID)
|
||||
checkUid = uplink.Clone.uid_exists(uid=uid)
|
||||
|
||||
clone = uplink.Schemas.MClone(
|
||||
@@ -174,12 +174,12 @@ def create_new_clone(uplink: 'Clone', faker_instance: 'Faker', group: str = 'Def
|
||||
|
||||
return True
|
||||
|
||||
def handle_on_privmsg(uplink: 'Clone', srvmsg: list[str]) -> None:
|
||||
async def handle_on_privmsg(uplink: 'Clone', srvmsg: list[str]) -> None:
|
||||
|
||||
senderObj, recieverObj, channel, message = uplink.Protocol.parse_privmsg(srvmsg)
|
||||
senderObj, recieverObj, channel, message = uplink.ctx.Irc.Protocol.parse_privmsg(srvmsg)
|
||||
|
||||
if senderObj is not None:
|
||||
if senderObj.hostname in uplink.Config.CLONE_LOG_HOST_EXEMPT:
|
||||
if senderObj.hostname in uplink.ctx.Config.CLONE_LOG_HOST_EXEMPT:
|
||||
return
|
||||
senderMsg = message
|
||||
clone_obj = recieverObj
|
||||
@@ -187,12 +187,12 @@ def handle_on_privmsg(uplink: 'Clone', srvmsg: list[str]) -> None:
|
||||
if clone_obj is None:
|
||||
return
|
||||
|
||||
if clone_obj.uid != uplink.Config.SERVICE_ID:
|
||||
if clone_obj.uid != uplink.ctx.Config.SERVICE_ID:
|
||||
final_message = f"{senderObj.nickname}!{senderObj.username}@{senderObj.hostname} > {senderMsg.lstrip(':')}"
|
||||
uplink.Protocol.send_priv_msg(
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(
|
||||
nick_from=clone_obj.uid,
|
||||
msg=final_message,
|
||||
channel=uplink.Config.CLONE_CHANNEL
|
||||
channel=uplink.ctx.Config.CLONE_CHANNEL
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,243 +4,243 @@ if TYPE_CHECKING:
|
||||
from mods.command.mod_command import Command
|
||||
|
||||
|
||||
def set_automode(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
async def set_automode(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
|
||||
command: str = str(cmd[0]).lower()
|
||||
option: str = str(cmd[1]).lower()
|
||||
allowed_modes: list[str] = uplink.Loader.Settings.PROTOCTL_PREFIX # ['q','a','o','h','v']
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
allowed_modes: list[str] = uplink.ctx.Settings.PROTOCTL_PREFIX # ['q','a','o','h','v']
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
fromuser = client
|
||||
|
||||
match option:
|
||||
case 'set':
|
||||
if len(cmd) < 5:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {command.upper()} [nickname] [+/-mode] [#channel]")
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"AutoModes available: {' / '.join(allowed_modes)}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {command.upper()} [nickname] [+/-mode] [#channel]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"AutoModes available: {' / '.join(allowed_modes)}")
|
||||
return None
|
||||
|
||||
nickname = str(cmd[2])
|
||||
mode = str(cmd[3])
|
||||
chan: str = str(cmd[4]).lower() if uplink.Channel.is_valid_channel(cmd[4]) else None
|
||||
chan: str = str(cmd[4]).lower() if uplink.ctx.Channel.is_valid_channel(cmd[4]) else None
|
||||
sign = mode[0] if mode.startswith( ('+', '-')) else None
|
||||
clean_mode = mode[1:] if len(mode) > 0 else None
|
||||
|
||||
if sign is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg="You must provide the flag mode + or -")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg="You must provide the flag mode + or -")
|
||||
return None
|
||||
|
||||
if clean_mode not in allowed_modes:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"You should use one of those modes {' / '.join(allowed_modes)}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"You should use one of those modes {' / '.join(allowed_modes)}")
|
||||
return None
|
||||
|
||||
if chan is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"You should use one of those modes {' / '.join(allowed_modes)}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"You should use one of those modes {' / '.join(allowed_modes)}")
|
||||
return None
|
||||
|
||||
db_data: dict[str, str] = {"nickname": nickname, "channel": chan}
|
||||
db_query = uplink.Base.db_execute_query(query="SELECT id FROM command_automode WHERE nickname = :nickname and channel = :channel", params=db_data)
|
||||
db_query = await uplink.ctx.Base.db_execute_query(query="SELECT id FROM command_automode WHERE nickname = :nickname and channel = :channel", params=db_data)
|
||||
db_result = db_query.fetchone()
|
||||
|
||||
if db_result is not None:
|
||||
if sign == '+':
|
||||
db_data = {"updated_on": uplink.MainUtils.get_sdatetime(), "nickname": nickname, "channel": chan, "mode": mode}
|
||||
db_result = uplink.Base.db_execute_query(query="UPDATE command_automode SET mode = :mode, updated_on = :updated_on WHERE nickname = :nickname and channel = :channel",
|
||||
db_data = {"updated_on": uplink.ctx.Utils.get_sdatetime(), "nickname": nickname, "channel": chan, "mode": mode}
|
||||
db_result = await uplink.ctx.Base.db_execute_query(query="UPDATE command_automode SET mode = :mode, updated_on = :updated_on WHERE nickname = :nickname and channel = :channel",
|
||||
params=db_data)
|
||||
if db_result.rowcount > 0:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Automode {mode} edited for {nickname} in {chan}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Automode {mode} edited for {nickname} in {chan}")
|
||||
elif sign == '-':
|
||||
db_data = {"nickname": nickname, "channel": chan, "mode": f"+{clean_mode}"}
|
||||
db_result = uplink.Base.db_execute_query(query="DELETE FROM command_automode WHERE nickname = :nickname and channel = :channel and mode = :mode",
|
||||
db_result = await uplink.ctx.Base.db_execute_query(query="DELETE FROM command_automode WHERE nickname = :nickname and channel = :channel and mode = :mode",
|
||||
params=db_data)
|
||||
if db_result.rowcount > 0:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Automode {mode} deleted for {nickname} in {chan}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Automode {mode} deleted for {nickname} in {chan}")
|
||||
else:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"The mode [{mode}] has not been found for {nickname} in channel {chan}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"The mode [{mode}] has not been found for {nickname} in channel {chan}")
|
||||
|
||||
return None
|
||||
|
||||
# Instert a new automode
|
||||
if sign == '+':
|
||||
db_data = {"created_on": uplink.MainUtils.get_sdatetime(), "updated_on": uplink.MainUtils.get_sdatetime(), "nickname": nickname, "channel": chan, "mode": mode}
|
||||
db_query = uplink.Base.db_execute_query(
|
||||
db_data = {"created_on": uplink.ctx.Utils.get_sdatetime(), "updated_on": uplink.ctx.Utils.get_sdatetime(), "nickname": nickname, "channel": chan, "mode": mode}
|
||||
db_query = await uplink.ctx.Base.db_execute_query(
|
||||
query="INSERT INTO command_automode (created_on, updated_on, nickname, channel, mode) VALUES (:created_on, :updated_on, :nickname, :channel, :mode)",
|
||||
params=db_data
|
||||
)
|
||||
|
||||
if db_query.rowcount > 0:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Automode {mode} applied to {nickname} in {chan}")
|
||||
if uplink.Channel.is_user_present_in_channel(chan, uplink.User.get_uid(nickname)):
|
||||
uplink.Protocol.send2socket(f":{service_id} MODE {chan} {mode} {nickname}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"Automode {mode} applied to {nickname} in {chan}")
|
||||
if uplink.ctx.Channel.is_user_present_in_channel(chan, uplink.ctx.User.get_uid(nickname)):
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {chan} {mode} {nickname}")
|
||||
else:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"AUTOMODE {mode} cannot be added to {nickname} in {chan} because it doesn't exist")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"AUTOMODE {mode} cannot be added to {nickname} in {chan} because it doesn't exist")
|
||||
|
||||
case 'list':
|
||||
db_query = uplink.Base.db_execute_query("SELECT nickname, channel, mode FROM command_automode")
|
||||
db_query = await uplink.ctx.Base.db_execute_query("SELECT nickname, channel, mode FROM command_automode")
|
||||
db_results = db_query.fetchall()
|
||||
|
||||
if not db_results:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,
|
||||
msg="There is no automode to display.")
|
||||
|
||||
for db_result in db_results:
|
||||
db_nickname, db_channel, db_mode = db_result
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser,
|
||||
msg=f"Nickname: {db_nickname} | Channel: {db_channel} | Mode: {db_mode}")
|
||||
|
||||
case _:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {command.upper()} SET [nickname] [+/-mode] [#channel]")
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {command.upper()} LIST")
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"[AUTOMODES AVAILABLE] are {' / '.join(allowed_modes)}")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {command.upper()} SET [nickname] [+/-mode] [#channel]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"/msg {dnickname} {command.upper()} LIST")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=fromuser, msg=f"[AUTOMODES AVAILABLE] are {' / '.join(allowed_modes)}")
|
||||
|
||||
def set_deopall(uplink: 'Command', channel_name: str) -> None:
|
||||
async def set_deopall(uplink: 'Command', channel_name: str) -> None:
|
||||
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
uplink.Protocol.send2socket(f":{service_id} SVSMODE {channel_name} -o")
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} SVSMODE {channel_name} -o")
|
||||
return None
|
||||
|
||||
def set_devoiceall(uplink: 'Command', channel_name: str) -> None:
|
||||
async def set_devoiceall(uplink: 'Command', channel_name: str) -> None:
|
||||
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
uplink.Protocol.send2socket(f":{service_id} SVSMODE {channel_name} -v")
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} SVSMODE {channel_name} -v")
|
||||
return None
|
||||
|
||||
def set_mode_to_all(uplink: 'Command', channel_name: str, action: Literal['+', '-'], pmode: str) -> None:
|
||||
async def set_mode_to_all(uplink: 'Command', channel_name: str, action: Literal['+', '-'], pmode: str) -> None:
|
||||
|
||||
chan_info = uplink.Channel.get_channel(channel_name)
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
chan_info = uplink.ctx.Channel.get_channel(channel_name)
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
set_mode = pmode
|
||||
mode:str = ''
|
||||
users:str = ''
|
||||
uids_split = [chan_info.uids[i:i + 6] for i in range(0, len(chan_info.uids), 6)]
|
||||
|
||||
uplink.Protocol.send2socket(f":{service_id} MODE {channel_name} {action}{set_mode} {dnickname}")
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {channel_name} {action}{set_mode} {dnickname}")
|
||||
for uid in uids_split:
|
||||
for i in range(0, len(uid)):
|
||||
mode += set_mode
|
||||
users += f'{uplink.User.get_nickname(uplink.MainUtils.clean_uid(uid[i]))} '
|
||||
users += f'{uplink.ctx.User.get_nickname(uplink.ctx.Utils.clean_uid(uid[i]))} '
|
||||
if i == len(uid) - 1:
|
||||
uplink.Protocol.send2socket(f":{service_id} MODE {channel_name} {action}{mode} {users}")
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {channel_name} {action}{mode} {users}")
|
||||
mode = ''
|
||||
users = ''
|
||||
|
||||
def set_operation(uplink: 'Command', cmd: list[str], channel_name: Optional[str], client: str, mode: str) -> None:
|
||||
async def set_operation(uplink: 'Command', cmd: list[str], channel_name: Optional[str], client: str, mode: str) -> None:
|
||||
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
if channel_name is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {mode} [#SALON] [NICKNAME]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {mode} [#SALON] [NICKNAME]")
|
||||
return False
|
||||
|
||||
if len(cmd) == 1:
|
||||
# uplink.Protocol.send2socket(f":{service_id} MODE {channel_name} {mode} {client}")
|
||||
uplink.Protocol.send_set_mode(mode, nickname=client, channel_name=channel_name)
|
||||
# await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {channel_name} {mode} {client}")
|
||||
await uplink.ctx.Irc.Protocol.send_set_mode(mode, nickname=client, channel_name=channel_name)
|
||||
return None
|
||||
|
||||
# deop nickname
|
||||
if len(cmd) == 2:
|
||||
nickname = cmd[1]
|
||||
# uplink.Protocol.send2socket(f":{service_id} MODE {channel_name} {mode} {nickname}")
|
||||
uplink.Protocol.send_set_mode(mode, nickname=nickname, channel_name=channel_name)
|
||||
# await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {channel_name} {mode} {nickname}")
|
||||
await uplink.ctx.Irc.Protocol.send_set_mode(mode, nickname=nickname, channel_name=channel_name)
|
||||
return None
|
||||
|
||||
nickname = cmd[2]
|
||||
# uplink.Protocol.send2socket(f":{service_id} MODE {channel_name} {mode} {nickname}")
|
||||
uplink.Protocol.send_set_mode(mode, nickname=nickname, channel_name=channel_name)
|
||||
# await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {channel_name} {mode} {nickname}")
|
||||
await uplink.ctx.Irc.Protocol.send_set_mode(mode, nickname=nickname, channel_name=channel_name)
|
||||
return None
|
||||
|
||||
def set_ban(uplink: 'Command', cmd: list[str], action: Literal['+', '-'], client: str) -> None:
|
||||
async def set_ban(uplink: 'Command', cmd: list[str], action: Literal['+', '-'], client: str) -> None:
|
||||
|
||||
command = str(cmd[0])
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
sentchannel = str(cmd[1]) if uplink.Channel.is_valid_channel(cmd[1]) else None
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
sentchannel = str(cmd[1]) if uplink.ctx.Channel.is_valid_channel(cmd[1]) else None
|
||||
|
||||
if sentchannel is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command.upper()} [#SALON] [NICKNAME]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command.upper()} [#SALON] [NICKNAME]")
|
||||
return None
|
||||
|
||||
nickname = cmd[2]
|
||||
|
||||
uplink.Protocol.send2socket(f":{service_id} MODE {sentchannel} {action}b {nickname}!*@*")
|
||||
uplink.Logs.debug(f'{client} has banned {nickname} from {sentchannel}')
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {sentchannel} {action}b {nickname}!*@*")
|
||||
uplink.ctx.Logs.debug(f'{client} has banned {nickname} from {sentchannel}')
|
||||
return None
|
||||
|
||||
def set_kick(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
async def set_kick(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
|
||||
command = str(cmd[0])
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
|
||||
sentchannel = str(cmd[1]) if uplink.Channel.is_valid_channel(cmd[1]) else None
|
||||
sentchannel = str(cmd[1]) if uplink.ctx.Channel.is_valid_channel(cmd[1]) else None
|
||||
if sentchannel is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command} [#SALON] [NICKNAME]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command} [#SALON] [NICKNAME]")
|
||||
return False
|
||||
|
||||
nickname = cmd[2]
|
||||
final_reason = ' '.join(cmd[3:])
|
||||
|
||||
uplink.Protocol.send2socket(f":{service_id} KICK {sentchannel} {nickname} {final_reason}")
|
||||
uplink.Logs.debug(f'{client} has kicked {nickname} from {sentchannel} : {final_reason}')
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} KICK {sentchannel} {nickname} {final_reason}")
|
||||
uplink.ctx.Logs.debug(f'{client} has kicked {nickname} from {sentchannel} : {final_reason}')
|
||||
return None
|
||||
|
||||
def set_kickban(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
async def set_kickban(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
|
||||
command = str(cmd[0])
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
|
||||
sentchannel = str(cmd[1]) if uplink.Channel.is_valid_channel(cmd[1]) else None
|
||||
sentchannel = str(cmd[1]) if uplink.ctx.Channel.is_valid_channel(cmd[1]) else None
|
||||
if sentchannel is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command} [#SALON] [NICKNAME]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command} [#SALON] [NICKNAME]")
|
||||
return False
|
||||
nickname = cmd[2]
|
||||
final_reason = ' '.join(cmd[3:])
|
||||
|
||||
uplink.Protocol.send2socket(f":{service_id} KICK {sentchannel} {nickname} {final_reason}")
|
||||
uplink.Protocol.send2socket(f":{service_id} MODE {sentchannel} +b {nickname}!*@*")
|
||||
uplink.Logs.debug(f'{client} has kicked and banned {nickname} from {sentchannel} : {final_reason}')
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} KICK {sentchannel} {nickname} {final_reason}")
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {sentchannel} +b {nickname}!*@*")
|
||||
uplink.ctx.Logs.debug(f'{client} has kicked and banned {nickname} from {sentchannel} : {final_reason}')
|
||||
|
||||
def set_assign_channel_to_service(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
async def set_assign_channel_to_service(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
|
||||
if len(cmd) < 2:
|
||||
raise IndexError(f"{cmd[0].upper()} is expecting the channel parameter")
|
||||
|
||||
command = str(cmd[0])
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
sent_channel = str(cmd[1]) if uplink.Channel.is_valid_channel(cmd[1]) else None
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
sent_channel = str(cmd[1]) if uplink.ctx.Channel.is_valid_channel(cmd[1]) else None
|
||||
if sent_channel is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command.upper()} [#SALON]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command.upper()} [#SALON]")
|
||||
return None
|
||||
|
||||
# self.Protocol.send2socket(f':{service_id} JOIN {sent_channel}')
|
||||
uplink.Protocol.send_join_chan(uidornickname=dnickname,channel=sent_channel)
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Has joined {sent_channel}")
|
||||
uplink.Channel.db_query_channel('add', uplink.module_name, sent_channel)
|
||||
await uplink.ctx.Irc.Protocol.send_join_chan(uidornickname=dnickname,channel=sent_channel)
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Has joined {sent_channel}")
|
||||
await uplink.ctx.Channel.db_query_channel('add', uplink.module_name, sent_channel)
|
||||
|
||||
return None
|
||||
|
||||
def set_unassign_channel_to_service(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
async def set_unassign_channel_to_service(uplink: 'Command', cmd: list[str], client: str) -> None:
|
||||
|
||||
if len(cmd) < 2:
|
||||
raise IndexError(f"{cmd[0].upper()} is expecting the channel parameter")
|
||||
|
||||
command = str(cmd[0])
|
||||
dnickname = uplink.Config.SERVICE_NICKNAME
|
||||
dchanlog = uplink.Config.SERVICE_CHANLOG
|
||||
dnickname = uplink.ctx.Config.SERVICE_NICKNAME
|
||||
dchanlog = uplink.ctx.Config.SERVICE_CHANLOG
|
||||
|
||||
sent_channel = str(cmd[1]) if uplink.Channel.is_valid_channel(cmd[1]) else None
|
||||
sent_channel = str(cmd[1]) if uplink.ctx.Channel.is_valid_channel(cmd[1]) else None
|
||||
if sent_channel is None:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command.upper()} [#SALON]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Right command : /msg {dnickname} {command.upper()} [#SALON]")
|
||||
return None
|
||||
|
||||
if sent_channel == dchanlog:
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f"[!] CAN'T LEFT {sent_channel} AS IT IS LOG CHANNEL [!]")
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f"[!] CAN'T LEFT {sent_channel} AS IT IS LOG CHANNEL [!]")
|
||||
return None
|
||||
|
||||
uplink.Protocol.send_part_chan(uidornickname=dnickname, channel=sent_channel)
|
||||
uplink.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Has left {sent_channel}")
|
||||
await uplink.ctx.Irc.Protocol.send_part_chan(uidornickname=dnickname, channel=sent_channel)
|
||||
await uplink.ctx.Irc.Protocol.send_notice(nick_from=dnickname, nick_to=client, msg=f" Has left {sent_channel}")
|
||||
|
||||
uplink.Channel.db_query_channel('del', uplink.module_name, sent_channel)
|
||||
await uplink.ctx.Channel.db_query_channel('del', uplink.module_name, sent_channel)
|
||||
return None
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,115 +1,116 @@
|
||||
import asyncio
|
||||
from typing import TYPE_CHECKING
|
||||
from time import sleep
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from mods.defender.mod_defender import Defender
|
||||
|
||||
def thread_apply_reputation_sanctions(uplink: 'Defender'):
|
||||
async def coro_apply_reputation_sanctions(uplink: 'Defender'):
|
||||
while uplink.reputationTimer_isRunning:
|
||||
uplink.Utils.action_apply_reputation_santions(uplink)
|
||||
sleep(5)
|
||||
await uplink.mod_utils.action_apply_reputation_santions(uplink)
|
||||
await asyncio.sleep(5)
|
||||
|
||||
def thread_cloudfilt_scan(uplink: 'Defender'):
|
||||
async def coro_cloudfilt_scan(uplink: 'Defender'):
|
||||
|
||||
while uplink.cloudfilt_isRunning:
|
||||
list_to_remove:list = []
|
||||
for user in uplink.Schemas.DB_CLOUDFILT_USERS:
|
||||
uplink.Utils.action_scan_client_with_cloudfilt(uplink, user)
|
||||
uplink.mod_utils.action_scan_client_with_cloudfilt(uplink, user)
|
||||
list_to_remove.append(user)
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
for user_model in list_to_remove:
|
||||
uplink.Schemas.DB_CLOUDFILT_USERS.remove(user_model)
|
||||
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def thread_freeipapi_scan(uplink: 'Defender'):
|
||||
async def coro_freeipapi_scan(uplink: 'Defender'):
|
||||
|
||||
while uplink.freeipapi_isRunning:
|
||||
|
||||
list_to_remove: list = []
|
||||
for user in uplink.Schemas.DB_FREEIPAPI_USERS:
|
||||
uplink.Utils.action_scan_client_with_freeipapi(uplink, user)
|
||||
uplink.mod_utils.action_scan_client_with_freeipapi(uplink, user)
|
||||
list_to_remove.append(user)
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
for user_model in list_to_remove:
|
||||
uplink.Schemas.DB_FREEIPAPI_USERS.remove(user_model)
|
||||
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def thread_abuseipdb_scan(uplink: 'Defender'):
|
||||
async def coro_abuseipdb_scan(uplink: 'Defender'):
|
||||
|
||||
while uplink.abuseipdb_isRunning:
|
||||
|
||||
list_to_remove: list = []
|
||||
for user in uplink.Schemas.DB_ABUSEIPDB_USERS:
|
||||
uplink.Utils.action_scan_client_with_abuseipdb(uplink, user)
|
||||
uplink.mod_utils.action_scan_client_with_abuseipdb(uplink, user)
|
||||
list_to_remove.append(user)
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
for user_model in list_to_remove:
|
||||
uplink.Schemas.DB_ABUSEIPDB_USERS.remove(user_model)
|
||||
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def thread_local_scan(uplink: 'Defender'):
|
||||
async def coro_local_scan(uplink: 'Defender'):
|
||||
|
||||
while uplink.localscan_isRunning:
|
||||
list_to_remove:list = []
|
||||
for user in uplink.Schemas.DB_LOCALSCAN_USERS:
|
||||
uplink.Utils.action_scan_client_with_local_socket(uplink, user)
|
||||
uplink.mod_utils.action_scan_client_with_local_socket(uplink, user)
|
||||
list_to_remove.append(user)
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
for user_model in list_to_remove:
|
||||
uplink.Schemas.DB_LOCALSCAN_USERS.remove(user_model)
|
||||
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def thread_psutil_scan(uplink: 'Defender'):
|
||||
async def coro_psutil_scan(uplink: 'Defender'):
|
||||
|
||||
while uplink.psutil_isRunning:
|
||||
|
||||
list_to_remove:list = []
|
||||
for user in uplink.Schemas.DB_PSUTIL_USERS:
|
||||
uplink.Utils.action_scan_client_with_psutil(uplink, user)
|
||||
uplink.mod_utils.action_scan_client_with_psutil(uplink, user)
|
||||
list_to_remove.append(user)
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
for user_model in list_to_remove:
|
||||
uplink.Schemas.DB_PSUTIL_USERS.remove(user_model)
|
||||
|
||||
sleep(1)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def thread_autolimit(uplink: 'Defender'):
|
||||
async def coro_autolimit(uplink: 'Defender'):
|
||||
|
||||
if uplink.ModConfig.autolimit == 0:
|
||||
uplink.Logs.debug("autolimit deactivated ... canceling the thread")
|
||||
if uplink.mod_config.autolimit == 0:
|
||||
uplink.ctx.Logs.debug("autolimit deactivated ... canceling the thread")
|
||||
return None
|
||||
|
||||
while uplink.Irc.autolimit_started:
|
||||
sleep(0.2)
|
||||
while uplink.ctx.Irc.autolimit_started:
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
uplink.Irc.autolimit_started = True
|
||||
init_amount = uplink.ModConfig.autolimit_amount
|
||||
p = uplink.Protocol
|
||||
uplink.ctx.Irc.autolimit_started = True
|
||||
init_amount = uplink.mod_config.autolimit_amount
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
INIT = 1
|
||||
|
||||
# Copy Channels to a list of dict
|
||||
chanObj_copy: list[dict[str, int]] = [{"name": c.name, "uids_count": len(c.uids)} for c in uplink.Channel.UID_CHANNEL_DB]
|
||||
chan_list: list[str] = [c.name for c in uplink.Channel.UID_CHANNEL_DB]
|
||||
chanObj_copy: list[dict[str, int]] = [{"name": c.name, "uids_count": len(c.uids)} for c in uplink.ctx.Channel.UID_CHANNEL_DB]
|
||||
chan_list: list[str] = [c.name for c in uplink.ctx.Channel.UID_CHANNEL_DB]
|
||||
|
||||
while uplink.autolimit_isRunning:
|
||||
|
||||
if uplink.ModConfig.autolimit == 0:
|
||||
uplink.Logs.debug("autolimit deactivated ... stopping the current thread")
|
||||
if uplink.mod_config.autolimit == 0:
|
||||
uplink.ctx.Logs.debug("autolimit deactivated ... stopping the current thread")
|
||||
break
|
||||
|
||||
for chan in uplink.Channel.UID_CHANNEL_DB:
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
for chan_copy in chanObj_copy:
|
||||
if chan_copy["name"] == chan.name and len(chan.uids) != chan_copy["uids_count"]:
|
||||
p.send2socket(f":{uplink.Config.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + uplink.ModConfig.autolimit_amount}")
|
||||
await p.send2socket(f":{uplink.ctx.Config.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + uplink.mod_config.autolimit_amount}")
|
||||
chan_copy["uids_count"] = len(chan.uids)
|
||||
|
||||
if chan.name not in chan_list:
|
||||
@@ -117,51 +118,55 @@ def thread_autolimit(uplink: 'Defender'):
|
||||
chanObj_copy.append({"name": chan.name, "uids_count": 0})
|
||||
|
||||
# Verifier si un salon a été vidé
|
||||
current_chan_in_list = [d.name for d in uplink.Channel.UID_CHANNEL_DB]
|
||||
current_chan_in_list = [d.name for d in uplink.ctx.Channel.UID_CHANNEL_DB]
|
||||
for c in chan_list:
|
||||
if c not in current_chan_in_list:
|
||||
chan_list.remove(c)
|
||||
|
||||
# Si c'est la premiere execution
|
||||
if INIT == 1:
|
||||
for chan in uplink.Channel.UID_CHANNEL_DB:
|
||||
p.send2socket(f":{uplink.Config.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + uplink.ModConfig.autolimit_amount}")
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
await p.send2socket(f":{uplink.ctx.Config.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + uplink.mod_config.autolimit_amount}")
|
||||
|
||||
# Si le nouveau amount est différent de l'initial
|
||||
if init_amount != uplink.ModConfig.autolimit_amount:
|
||||
init_amount = uplink.ModConfig.autolimit_amount
|
||||
for chan in uplink.Channel.UID_CHANNEL_DB:
|
||||
p.send2socket(f":{uplink.Config.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + uplink.ModConfig.autolimit_amount}")
|
||||
if init_amount != uplink.mod_config.autolimit_amount:
|
||||
init_amount = uplink.mod_config.autolimit_amount
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
await p.send2socket(f":{uplink.ctx.Config.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + uplink.mod_config.autolimit_amount}")
|
||||
|
||||
INIT = 0
|
||||
|
||||
if uplink.autolimit_isRunning:
|
||||
sleep(uplink.ModConfig.autolimit_interval)
|
||||
await asyncio.sleep(uplink.mod_config.autolimit_interval)
|
||||
|
||||
for chan in uplink.Channel.UID_CHANNEL_DB:
|
||||
p.send2socket(f":{uplink.Config.SERVICE_ID} MODE {chan.name} -l")
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
# await p.send2socket(f":{uplink.ctx.Config.SERVICE_ID} MODE {chan.name} -l")
|
||||
await p.send_set_mode('-l', channel_name=chan.name)
|
||||
|
||||
uplink.Irc.autolimit_started = False
|
||||
uplink.ctx.Irc.autolimit_started = False
|
||||
|
||||
return None
|
||||
|
||||
def timer_release_mode_mute(uplink: 'Defender', action: str, channel: str):
|
||||
"""DO NOT EXECUTE THIS FUNCTION WITHOUT THREADING
|
||||
async def coro_release_mode_mute(uplink: 'Defender', action: str, channel: str):
|
||||
"""DO NOT EXECUTE THIS FUNCTION DIRECTLY
|
||||
IT WILL BLOCK THE PROCESS
|
||||
|
||||
Args:
|
||||
action (str): _description_
|
||||
action (str): mode-m
|
||||
channel (str): The related channel
|
||||
|
||||
"""
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
timeout = uplink.mod_config.flood_timer
|
||||
await asyncio.sleep(timeout)
|
||||
|
||||
if not uplink.Channel.is_valid_channel(channel):
|
||||
uplink.Logs.debug(f"Channel is not valid {channel}")
|
||||
if not uplink.ctx.Channel.is_valid_channel(channel):
|
||||
uplink.ctx.Logs.debug(f"Channel is not valid {channel}")
|
||||
return
|
||||
|
||||
match action:
|
||||
case 'mode-m':
|
||||
# Action -m sur le salon
|
||||
uplink.Protocol.send2socket(f":{service_id} MODE {channel} -m")
|
||||
await uplink.ctx.Irc.Protocol.send2socket(f":{service_id} MODE {channel} -m")
|
||||
case _:
|
||||
pass
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Optional
|
||||
from mods.defender.schemas import FloodUser
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.loader import Loader
|
||||
from core.definition import MUser
|
||||
from mods.defender.mod_defender import Defender
|
||||
|
||||
@@ -28,10 +29,10 @@ def handle_on_reputation(uplink: 'Defender', srvmsg: list[str]):
|
||||
return
|
||||
|
||||
# Possibilité de déclancher les bans a ce niveau.
|
||||
if not uplink.Base.is_valid_ip(ip):
|
||||
if not uplink.ctx.Base.is_valid_ip(ip):
|
||||
return
|
||||
|
||||
def handle_on_mode(uplink: 'Defender', srvmsg: list[str]):
|
||||
async def handle_on_mode(uplink: 'Defender', srvmsg: list[str]):
|
||||
"""_summary_
|
||||
>>> srvmsg = ['@unrealircd.org/...', ':001C0MF01', 'MODE', '#services', '+l', '1']
|
||||
>>> srvmsg = ['...', ':001XSCU0Q', 'MODE', '#jail', '+b', '~security-group:unknown-users']
|
||||
@@ -40,10 +41,10 @@ def handle_on_mode(uplink: 'Defender', srvmsg: list[str]):
|
||||
srvmsg (list[str]): The Server MSG
|
||||
confmodel (ModConfModel): The Module Configuration
|
||||
"""
|
||||
irc = uplink.Irc
|
||||
gconfig = uplink.Config
|
||||
p = uplink.Protocol
|
||||
confmodel = uplink.ModConfig
|
||||
irc = uplink.ctx.Irc
|
||||
gconfig = uplink.ctx.Config
|
||||
p = irc.Protocol
|
||||
confmodel = uplink.mod_config
|
||||
|
||||
channel = str(srvmsg[3])
|
||||
mode = str(srvmsg[4])
|
||||
@@ -52,25 +53,25 @@ def handle_on_mode(uplink: 'Defender', srvmsg: list[str]):
|
||||
|
||||
if confmodel.autolimit == 1:
|
||||
if mode == '+l' or mode == '-l':
|
||||
chan = irc.Channel.get_channel(channel)
|
||||
p.send2socket(f":{gconfig.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + confmodel.autolimit_amount}")
|
||||
chan = uplink.ctx.Channel.get_channel(channel)
|
||||
await p.send2socket(f":{gconfig.SERVICE_ID} MODE {chan.name} +l {len(chan.uids) + confmodel.autolimit_amount}")
|
||||
|
||||
if gconfig.SALON_JAIL == channel:
|
||||
if mode == '+b' and group_to_unban in group_to_check:
|
||||
p.send2socket(f":{gconfig.SERVICE_ID} MODE {gconfig.SALON_JAIL} -b ~security-group:unknown-users")
|
||||
p.send2socket(f":{gconfig.SERVICE_ID} MODE {gconfig.SALON_JAIL} -eee ~security-group:webirc-users ~security-group:known-users ~security-group:websocket-users")
|
||||
await p.send2socket(f":{gconfig.SERVICE_ID} MODE {gconfig.SALON_JAIL} -b ~security-group:unknown-users")
|
||||
await p.send2socket(f":{gconfig.SERVICE_ID} MODE {gconfig.SALON_JAIL} -eee ~security-group:webirc-users ~security-group:known-users ~security-group:websocket-users")
|
||||
|
||||
def handle_on_privmsg(uplink: 'Defender', srvmsg: list[str]):
|
||||
async def handle_on_privmsg(uplink: 'Defender', srvmsg: list[str]):
|
||||
# ['@mtag....',':python', 'PRIVMSG', '#defender', ':zefzefzregreg', 'regg', 'aerg']
|
||||
|
||||
sender, reciever, channel, message = uplink.Protocol.parse_privmsg(srvmsg)
|
||||
if uplink.ModConfig.sentinel == 1 and channel.name != uplink.Config.SERVICE_CHANLOG:
|
||||
uplink.Protocol.send_priv_msg(uplink.Config.SERVICE_NICKNAME, f"{sender.nickname} say on {channel.name}: {' '.join(message)}", uplink.Config.SERVICE_CHANLOG)
|
||||
sender, reciever, channel, message = uplink.ctx.Irc.Protocol.parse_privmsg(srvmsg)
|
||||
if uplink.mod_config.sentinel == 1 and channel.name != uplink.ctx.Config.SERVICE_CHANLOG:
|
||||
await uplink.ctx.Irc.Protocol.send_priv_msg(uplink.ctx.Config.SERVICE_NICKNAME, f"{sender.nickname} say on {channel.name}: {' '.join(message)}", uplink.ctx.Config.SERVICE_CHANLOG)
|
||||
|
||||
action_on_flood(uplink, srvmsg)
|
||||
await action_on_flood(uplink, srvmsg)
|
||||
return None
|
||||
|
||||
def handle_on_sjoin(uplink: 'Defender', srvmsg: list[str]):
|
||||
async def handle_on_sjoin(uplink: 'Defender', srvmsg: list[str]):
|
||||
"""If Joining a new channel, it applies group bans.
|
||||
|
||||
>>> srvmsg = ['@msgid..', ':001', 'SJOIN', '1702138958', '#welcome', ':0015L1AHL']
|
||||
@@ -80,37 +81,37 @@ def handle_on_sjoin(uplink: 'Defender', srvmsg: list[str]):
|
||||
srvmsg (list[str]): The Server MSG
|
||||
confmodel (ModConfModel): The Module Configuration
|
||||
"""
|
||||
irc = uplink.Irc
|
||||
irc = uplink.ctx.Irc
|
||||
p = irc.Protocol
|
||||
gconfig = uplink.Config
|
||||
confmodel = uplink.ModConfig
|
||||
gconfig = uplink.ctx.Config
|
||||
confmodel = uplink.mod_config
|
||||
|
||||
parsed_chan = srvmsg[4] if irc.Channel.is_valid_channel(srvmsg[4]) else None
|
||||
parsed_UID = uplink.Loader.Utils.clean_uid(srvmsg[5])
|
||||
parsed_chan = srvmsg[4] if uplink.ctx.Channel.is_valid_channel(srvmsg[4]) else None
|
||||
parsed_UID = uplink.ctx.Utils.clean_uid(srvmsg[5])
|
||||
|
||||
if parsed_chan is None or parsed_UID is None:
|
||||
return
|
||||
|
||||
if confmodel.reputation == 1:
|
||||
get_reputation = irc.Reputation.get_reputation(parsed_UID)
|
||||
get_reputation = uplink.ctx.Reputation.get_reputation(parsed_UID)
|
||||
|
||||
if parsed_chan != gconfig.SALON_JAIL:
|
||||
p.send2socket(f":{gconfig.SERVICE_ID} MODE {parsed_chan} +b ~security-group:unknown-users")
|
||||
p.send2socket(f":{gconfig.SERVICE_ID} MODE {parsed_chan} +eee ~security-group:webirc-users ~security-group:known-users ~security-group:websocket-users")
|
||||
await p.send2socket(f":{gconfig.SERVICE_ID} MODE {parsed_chan} +b ~security-group:unknown-users")
|
||||
await p.send2socket(f":{gconfig.SERVICE_ID} MODE {parsed_chan} +eee ~security-group:webirc-users ~security-group:known-users ~security-group:websocket-users")
|
||||
|
||||
if get_reputation is not None:
|
||||
isWebirc = get_reputation.isWebirc
|
||||
|
||||
if not isWebirc:
|
||||
if parsed_chan != gconfig.SALON_JAIL:
|
||||
p.send_sapart(nick_to_sapart=get_reputation.nickname, channel_name=parsed_chan)
|
||||
await p.send_sapart(nick_to_sapart=get_reputation.nickname, channel_name=parsed_chan)
|
||||
|
||||
if confmodel.reputation_ban_all_chan == 1 and not isWebirc:
|
||||
if parsed_chan != gconfig.SALON_JAIL:
|
||||
p.send2socket(f":{gconfig.SERVICE_ID} MODE {parsed_chan} +b {get_reputation.nickname}!*@*")
|
||||
p.send2socket(f":{gconfig.SERVICE_ID} KICK {parsed_chan} {get_reputation.nickname}")
|
||||
await p.send2socket(f":{gconfig.SERVICE_ID} MODE {parsed_chan} +b {get_reputation.nickname}!*@*")
|
||||
await p.send2socket(f":{gconfig.SERVICE_ID} KICK {parsed_chan} {get_reputation.nickname}")
|
||||
|
||||
irc.Logs.debug(f'SJOIN parsed_uid : {parsed_UID}')
|
||||
uplink.ctx.Logs.debug(f'SJOIN parsed_uid : {parsed_UID}')
|
||||
|
||||
def handle_on_slog(uplink: 'Defender', srvmsg: list[str]):
|
||||
"""Handling SLOG messages
|
||||
@@ -122,27 +123,27 @@ def handle_on_slog(uplink: 'Defender', srvmsg: list[str]):
|
||||
"""
|
||||
['@unrealircd...', ':001', 'SLOG', 'info', 'blacklist', 'BLACKLIST_HIT', ':[Blacklist]', 'IP', '162.x.x.x', 'matches', 'blacklist', 'dronebl', '(dnsbl.dronebl.org/reply=6)']
|
||||
|
||||
if not uplink.Base.is_valid_ip(srvmsg[8]):
|
||||
if not uplink.ctx.Base.is_valid_ip(srvmsg[8]):
|
||||
return None
|
||||
|
||||
# if self.ModConfig.local_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# if self.mod_config.local_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# self.localscan_remote_ip.append(cmd[7])
|
||||
|
||||
# if self.ModConfig.psutil_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# if self.mod_config.psutil_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# self.psutil_remote_ip.append(cmd[7])
|
||||
|
||||
# if self.ModConfig.abuseipdb_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# if self.mod_config.abuseipdb_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# self.abuseipdb_remote_ip.append(cmd[7])
|
||||
|
||||
# if self.ModConfig.freeipapi_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# if self.mod_config.freeipapi_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# self.freeipapi_remote_ip.append(cmd[7])
|
||||
|
||||
# if self.ModConfig.cloudfilt_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# if self.mod_config.cloudfilt_scan == 1 and not cmd[7] in self.Config.WHITELISTED_IP:
|
||||
# self.cloudfilt_remote_ip.append(cmd[7])
|
||||
|
||||
return None
|
||||
|
||||
def handle_on_nick(uplink: 'Defender', srvmsg: list[str]):
|
||||
async def handle_on_nick(uplink: 'Defender', srvmsg: list[str]):
|
||||
"""Handle nickname changes.
|
||||
>>> srvmsg = ['@unrealircd.org...', ':001MZQ0RB', 'NICK', 'newnickname', '1754663712']
|
||||
>>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740']
|
||||
@@ -151,22 +152,22 @@ def handle_on_nick(uplink: 'Defender', srvmsg: list[str]):
|
||||
srvmsg (list[str]): The Server MSG
|
||||
confmodel (ModConfModel): The Module Configuration
|
||||
"""
|
||||
p = uplink.Protocol
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
u, new_nickname, timestamp = p.parse_nick(srvmsg)
|
||||
|
||||
if u is None:
|
||||
uplink.Logs.error(f"[USER OBJ ERROR {timestamp}] - {srvmsg}")
|
||||
uplink.ctx.Logs.error(f"[USER OBJ ERROR {timestamp}] - {srvmsg}")
|
||||
return None
|
||||
|
||||
uid = u.uid
|
||||
confmodel = uplink.ModConfig
|
||||
confmodel = uplink.mod_config
|
||||
|
||||
get_reputation = uplink.Reputation.get_reputation(uid)
|
||||
jail_salon = uplink.Config.SALON_JAIL
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
get_reputation = uplink.ctx.Reputation.get_reputation(uid)
|
||||
jail_salon = uplink.ctx.Config.SALON_JAIL
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
|
||||
if get_reputation is None:
|
||||
uplink.Logs.debug(f'This UID: {uid} is not listed in the reputation dataclass')
|
||||
uplink.ctx.Logs.debug(f'This UID: {uid} is not listed in the reputation dataclass')
|
||||
return None
|
||||
|
||||
# Update the new nickname
|
||||
@@ -176,42 +177,42 @@ def handle_on_nick(uplink: 'Defender', srvmsg: list[str]):
|
||||
|
||||
# If ban in all channel is ON then unban old nickname an ban the new nickname
|
||||
if confmodel.reputation_ban_all_chan == 1:
|
||||
for chan in uplink.Channel.UID_CHANNEL_DB:
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
if chan.name != jail_salon:
|
||||
p.send2socket(f":{service_id} MODE {chan.name} -b {oldnick}!*@*")
|
||||
p.send2socket(f":{service_id} MODE {chan.name} +b {newnickname}!*@*")
|
||||
await p.send2socket(f":{service_id} MODE {chan.name} -b {oldnick}!*@*")
|
||||
await p.send2socket(f":{service_id} MODE {chan.name} +b {newnickname}!*@*")
|
||||
|
||||
def handle_on_quit(uplink: 'Defender', srvmsg: list[str]):
|
||||
async def handle_on_quit(uplink: 'Defender', srvmsg: list[str]):
|
||||
"""Handle on quit message
|
||||
>>> srvmsg = ['@unrealircd.org...', ':001MZQ0RB', 'QUIT', ':Quit:', 'quit message']
|
||||
Args:
|
||||
uplink (Irc): The Defender Module instance
|
||||
srvmsg (list[str]): The Server MSG
|
||||
"""
|
||||
p = uplink.Protocol
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
userobj, reason = p.parse_quit(srvmsg)
|
||||
confmodel = uplink.ModConfig
|
||||
confmodel = uplink.mod_config
|
||||
|
||||
if userobj is None:
|
||||
uplink.Logs.debug(f"This UID do not exist anymore: {srvmsg}")
|
||||
uplink.ctx.Logs.debug(f"This UID do not exist anymore: {srvmsg}")
|
||||
return None
|
||||
|
||||
ban_all_chan = uplink.Base.int_if_possible(confmodel.reputation_ban_all_chan)
|
||||
jail_salon = uplink.Config.SALON_JAIL
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
get_user_reputation = uplink.Reputation.get_reputation(userobj.uid)
|
||||
ban_all_chan = uplink.ctx.Base.int_if_possible(confmodel.reputation_ban_all_chan)
|
||||
jail_salon = uplink.ctx.Config.SALON_JAIL
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
get_user_reputation = uplink.ctx.Reputation.get_reputation(userobj.uid)
|
||||
|
||||
if get_user_reputation is not None:
|
||||
final_nickname = get_user_reputation.nickname
|
||||
for chan in uplink.Channel.UID_CHANNEL_DB:
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
if chan.name != jail_salon and ban_all_chan == 1:
|
||||
p.send2socket(f":{service_id} MODE {chan.name} -b {final_nickname}!*@*")
|
||||
uplink.Logs.debug(f"Mode -b {final_nickname} on channel {chan.name}")
|
||||
await p.send2socket(f":{service_id} MODE {chan.name} -b {final_nickname}!*@*")
|
||||
uplink.ctx.Logs.debug(f"Mode -b {final_nickname} on channel {chan.name}")
|
||||
|
||||
uplink.Reputation.delete(userobj.uid)
|
||||
uplink.Logs.debug(f"Client {get_user_reputation.nickname} has been removed from Reputation local DB")
|
||||
uplink.ctx.Reputation.delete(userobj.uid)
|
||||
uplink.ctx.Logs.debug(f"Client {get_user_reputation.nickname} has been removed from Reputation local DB")
|
||||
|
||||
def handle_on_uid(uplink: 'Defender', srvmsg: list[str]):
|
||||
async def handle_on_uid(uplink: 'Defender', srvmsg: list[str]):
|
||||
"""_summary_
|
||||
>>> ['@s2s-md...', ':001', 'UID', 'nickname', '0', '1754675249', '...', '125-168-141-239.hostname.net', '001BAPN8M',
|
||||
'0', '+iwx', '*', '32001BBE.25ACEFE7.429FE90D.IP', 'ZA2ic7w==', ':realname']
|
||||
@@ -220,10 +221,10 @@ def handle_on_uid(uplink: 'Defender', srvmsg: list[str]):
|
||||
uplink (Defender): The Defender instance
|
||||
srvmsg (list[str]): The Server MSG
|
||||
"""
|
||||
_User = uplink.Protocol.parse_uid(srvmsg)
|
||||
gconfig = uplink.Config
|
||||
irc = uplink.Irc
|
||||
confmodel = uplink.ModConfig
|
||||
irc = uplink.ctx.Irc
|
||||
_User = irc.Protocol.parse_uid(srvmsg)
|
||||
gconfig = uplink.ctx.Config
|
||||
confmodel = uplink.mod_config
|
||||
|
||||
# If Init then do nothing
|
||||
if gconfig.DEFENDER_INIT == 1:
|
||||
@@ -231,7 +232,7 @@ def handle_on_uid(uplink: 'Defender', srvmsg: list[str]):
|
||||
|
||||
# Get User information
|
||||
if _User is None:
|
||||
irc.Logs.warning(f'Error when parsing UID', exc_info=True)
|
||||
uplink.ctx.Logs.warning(f'Error when parsing UID', exc_info=True)
|
||||
return
|
||||
|
||||
# If user is not service or IrcOp then scan them
|
||||
@@ -250,38 +251,38 @@ def handle_on_uid(uplink: 'Defender', srvmsg: list[str]):
|
||||
if not match(r'^.*[S|o?].*$', _User.umodes):
|
||||
if reputation_flag == 1 and _User.score_connexion <= reputation_seuil:
|
||||
# currentDateTime = self.Base.get_datetime()
|
||||
irc.Reputation.insert(
|
||||
irc.Loader.Definition.MReputation(
|
||||
uplink.ctx.Reputation.insert(
|
||||
uplink.ctx.Definition.MReputation(
|
||||
**_User.to_dict(),
|
||||
secret_code=irc.Utils.generate_random_string(8)
|
||||
secret_code=uplink.ctx.Utils.generate_random_string(8)
|
||||
)
|
||||
)
|
||||
if irc.Reputation.is_exist(_User.uid):
|
||||
if uplink.ctx.Reputation.is_exist(_User.uid):
|
||||
if reputation_flag == 1 and _User.score_connexion <= reputation_seuil:
|
||||
action_add_reputation_sanctions(uplink, _User.uid)
|
||||
irc.Logs.info(f'[REPUTATION] Reputation system ON (Nickname: {_User.nickname}, uid: {_User.uid})')
|
||||
await action_add_reputation_sanctions(uplink, _User.uid)
|
||||
uplink.ctx.Logs.info(f'[REPUTATION] Reputation system ON (Nickname: {_User.nickname}, uid: {_User.uid})')
|
||||
|
||||
####################
|
||||
# ACTION FUNCTIONS #
|
||||
####################
|
||||
# [:<sid>] UID <uid> <ts> <nick> <real-host> <displayed-host> <real-user> <ip> <signon> <modes> [<mode-parameters>]+ :<real>
|
||||
# [:<sid>] UID nickname hopcount timestamp username hostname uid servicestamp umodes virthost cloakedhost ip :gecos
|
||||
def action_on_flood(uplink: 'Defender', srvmsg: list[str]):
|
||||
async def action_on_flood(uplink: 'Defender', srvmsg: list[str]):
|
||||
|
||||
confmodel = uplink.ModConfig
|
||||
confmodel = uplink.mod_config
|
||||
if confmodel.flood == 0:
|
||||
return None
|
||||
|
||||
irc = uplink.Irc
|
||||
gconfig = uplink.Config
|
||||
p = uplink.Protocol
|
||||
irc = uplink.ctx.Irc
|
||||
gconfig = uplink.ctx.Config
|
||||
p = irc.Protocol
|
||||
flood_users = uplink.Schemas.DB_FLOOD_USERS
|
||||
|
||||
user_trigger = str(srvmsg[1]).replace(':','')
|
||||
channel = srvmsg[3]
|
||||
User = irc.User.get_user(user_trigger)
|
||||
User = uplink.ctx.User.get_user(user_trigger)
|
||||
|
||||
if User is None or not irc.Channel.is_valid_channel(channel_to_check=channel):
|
||||
if User is None or not uplink.ctx.Channel.is_valid_channel(channel_to_check=channel):
|
||||
return
|
||||
|
||||
flood_time = confmodel.flood_time
|
||||
@@ -294,7 +295,7 @@ def action_on_flood(uplink: 'Defender', srvmsg: list[str]):
|
||||
|
||||
get_detected_uid = User.uid
|
||||
get_detected_nickname = User.nickname
|
||||
unixtime = irc.Utils.get_unixtime()
|
||||
unixtime = uplink.ctx.Utils.get_unixtime()
|
||||
get_diff_secondes = 0
|
||||
|
||||
def get_flood_user(uid: str) -> Optional[FloodUser]:
|
||||
@@ -315,29 +316,29 @@ def action_on_flood(uplink: 'Defender', srvmsg: list[str]):
|
||||
fu.nbr_msg = 0
|
||||
get_diff_secondes = unixtime - fu.first_msg_time
|
||||
elif fu.nbr_msg > flood_message:
|
||||
irc.Logs.info('system de flood detecté')
|
||||
p.send_priv_msg(
|
||||
uplink.ctx.Logs.info('system de flood detecté')
|
||||
await p.send_priv_msg(
|
||||
nick_from=dnickname,
|
||||
msg=f"{color_red} {color_bold} Flood detected. Apply the +m mode (Ô_o)",
|
||||
channel=channel
|
||||
)
|
||||
p.send2socket(f":{service_id} MODE {channel} +m")
|
||||
irc.Logs.info(f'FLOOD Détecté sur {get_detected_nickname} mode +m appliqué sur le salon {channel}')
|
||||
await p.send2socket(f":{service_id} MODE {channel} +m")
|
||||
uplink.ctx.Logs.info(f'FLOOD Détecté sur {get_detected_nickname} mode +m appliqué sur le salon {channel}')
|
||||
fu.nbr_msg = 0
|
||||
fu.first_msg_time = unixtime
|
||||
irc.Base.create_timer(flood_timer, dthreads.timer_release_mode_mute, (uplink, 'mode-m', channel))
|
||||
uplink.ctx.Base.create_asynctask(dthreads.coro_release_mode_mute(uplink, 'mode-m', channel))
|
||||
|
||||
def action_add_reputation_sanctions(uplink: 'Defender', jailed_uid: str ):
|
||||
async def action_add_reputation_sanctions(uplink: 'Defender', jailed_uid: str ):
|
||||
|
||||
irc = uplink.Irc
|
||||
gconfig = uplink.Config
|
||||
p = uplink.Protocol
|
||||
confmodel = uplink.ModConfig
|
||||
irc = uplink.ctx.Irc
|
||||
gconfig = uplink.ctx.Config
|
||||
p = irc.Protocol
|
||||
confmodel = uplink.mod_config
|
||||
|
||||
get_reputation = irc.Reputation.get_reputation(jailed_uid)
|
||||
get_reputation = uplink.ctx.Reputation.get_reputation(jailed_uid)
|
||||
|
||||
if get_reputation is None:
|
||||
irc.Logs.warning(f'UID {jailed_uid} has not been found')
|
||||
uplink.ctx.Logs.warning(f'UID {jailed_uid} has not been found')
|
||||
return
|
||||
|
||||
salon_logs = gconfig.SERVICE_CHANLOG
|
||||
@@ -357,33 +358,33 @@ def action_add_reputation_sanctions(uplink: 'Defender', jailed_uid: str ):
|
||||
|
||||
if not get_reputation.isWebirc:
|
||||
# Si le user ne vient pas de webIrc
|
||||
p.send_sajoin(nick_to_sajoin=jailed_nickname, channel_name=salon_jail)
|
||||
p.send_priv_msg(nick_from=gconfig.SERVICE_NICKNAME,
|
||||
await p.send_sajoin(nick_to_sajoin=jailed_nickname, channel_name=salon_jail)
|
||||
await p.send_priv_msg(nick_from=gconfig.SERVICE_NICKNAME,
|
||||
msg=f" [{color_red} REPUTATION {nogc}] : Connexion de {jailed_nickname} ({jailed_score}) ==> {salon_jail}",
|
||||
channel=salon_logs
|
||||
)
|
||||
p.send_notice(
|
||||
await p.send_notice(
|
||||
nick_from=gconfig.SERVICE_NICKNAME,
|
||||
nick_to=jailed_nickname,
|
||||
msg=f"[{color_red} {jailed_nickname} {color_black}] : Merci de tapez la commande suivante {color_bold}{service_prefix}code {code}{color_bold}"
|
||||
)
|
||||
if reputation_ban_all_chan == 1:
|
||||
for chan in irc.Channel.UID_CHANNEL_DB:
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
if chan.name != salon_jail:
|
||||
p.send2socket(f":{service_id} MODE {chan.name} +b {jailed_nickname}!*@*")
|
||||
p.send2socket(f":{service_id} KICK {chan.name} {jailed_nickname}")
|
||||
await p.send2socket(f":{service_id} MODE {chan.name} +b {jailed_nickname}!*@*")
|
||||
await p.send2socket(f":{service_id} KICK {chan.name} {jailed_nickname}")
|
||||
|
||||
irc.Logs.info(f"[REPUTATION] {jailed_nickname} jailed (UID: {jailed_uid}, score: {jailed_score})")
|
||||
uplink.ctx.Logs.info(f"[REPUTATION] {jailed_nickname} jailed (UID: {jailed_uid}, score: {jailed_score})")
|
||||
else:
|
||||
irc.Logs.info(f"[REPUTATION] {jailed_nickname} skipped (trusted or WebIRC)")
|
||||
irc.Reputation.delete(jailed_uid)
|
||||
uplink.ctx.Logs.info(f"[REPUTATION] {jailed_nickname} skipped (trusted or WebIRC)")
|
||||
uplink.ctx.Reputation.delete(jailed_uid)
|
||||
|
||||
def action_apply_reputation_santions(uplink: 'Defender') -> None:
|
||||
async def action_apply_reputation_santions(uplink: 'Defender') -> None:
|
||||
|
||||
irc = uplink.Irc
|
||||
gconfig = uplink.Config
|
||||
p = uplink.Protocol
|
||||
confmodel = uplink.ModConfig
|
||||
irc = uplink.ctx.Irc
|
||||
gconfig = uplink.ctx.Config
|
||||
p = irc.Protocol
|
||||
confmodel = uplink.mod_config
|
||||
|
||||
reputation_flag = confmodel.reputation
|
||||
reputation_timer = confmodel.reputation_timer
|
||||
@@ -396,36 +397,36 @@ def action_apply_reputation_santions(uplink: 'Defender') -> None:
|
||||
salon_jail = gconfig.SALON_JAIL
|
||||
uid_to_clean = []
|
||||
|
||||
if reputation_flag == 0 or reputation_timer == 0 or not irc.Reputation.UID_REPUTATION_DB:
|
||||
if reputation_flag == 0 or reputation_timer == 0 or not uplink.ctx.Reputation.UID_REPUTATION_DB:
|
||||
return None
|
||||
|
||||
for user in irc.Reputation.UID_REPUTATION_DB:
|
||||
for user in uplink.ctx.Reputation.UID_REPUTATION_DB:
|
||||
if not user.isWebirc: # Si il ne vient pas de WebIRC
|
||||
if irc.User.get_user_uptime_in_minutes(user.uid) >= reputation_timer and int(user.score_connexion) <= int(reputation_seuil):
|
||||
p.send_priv_msg(
|
||||
if uplink.ctx.User.get_user_uptime_in_minutes(user.uid) >= reputation_timer and int(user.score_connexion) <= int(reputation_seuil):
|
||||
await p.send_priv_msg(
|
||||
nick_from=service_id,
|
||||
msg=f"[{color_red} REPUTATION {nogc}] : Action sur {user.nickname} aprés {str(reputation_timer)} minutes d'inactivité",
|
||||
channel=dchanlog
|
||||
)
|
||||
p.send2socket(f":{service_id} KILL {user.nickname} After {str(reputation_timer)} minutes of inactivity you should reconnect and type the password code")
|
||||
p.send2socket(f":{gconfig.SERVEUR_LINK} REPUTATION {user.remote_ip} 0")
|
||||
await p.send2socket(f":{service_id} KILL {user.nickname} After {str(reputation_timer)} minutes of inactivity you should reconnect and type the password code")
|
||||
await p.send2socket(f":{gconfig.SERVEUR_LINK} REPUTATION {user.remote_ip} 0")
|
||||
|
||||
irc.Logs.info(f"Nickname: {user.nickname} KILLED after {str(reputation_timer)} minutes of inactivity")
|
||||
uplink.ctx.Logs.info(f"Nickname: {user.nickname} KILLED after {str(reputation_timer)} minutes of inactivity")
|
||||
uid_to_clean.append(user.uid)
|
||||
|
||||
for uid in uid_to_clean:
|
||||
# Suppression des éléments dans {UID_DB} et {REPUTATION_DB}
|
||||
for chan in irc.Channel.UID_CHANNEL_DB:
|
||||
for chan in uplink.ctx.Channel.UID_CHANNEL_DB:
|
||||
if chan.name != salon_jail and ban_all_chan == 1:
|
||||
get_user_reputation = irc.Reputation.get_reputation(uid)
|
||||
p.send2socket(f":{service_id} MODE {chan.name} -b {get_user_reputation.nickname}!*@*")
|
||||
get_user_reputation = uplink.ctx.Reputation.get_reputation(uid)
|
||||
await p.send2socket(f":{service_id} MODE {chan.name} -b {get_user_reputation.nickname}!*@*")
|
||||
|
||||
# Lorsqu'un utilisateur quitte, il doit être supprimé de {UID_DB}.
|
||||
irc.Channel.delete_user_from_all_channel(uid)
|
||||
irc.Reputation.delete(uid)
|
||||
irc.User.delete(uid)
|
||||
uplink.ctx.Channel.delete_user_from_all_channel(uid)
|
||||
uplink.ctx.Reputation.delete(uid)
|
||||
uplink.ctx.User.delete(uid)
|
||||
|
||||
def action_scan_client_with_cloudfilt(uplink: 'Defender', user_model: 'MUser') -> Optional[dict[str, str]]:
|
||||
async def action_scan_client_with_cloudfilt(uplink: 'Defender', user_model: 'MUser') -> Optional[dict[str, str]]:
|
||||
"""Analyse l'ip avec cloudfilt
|
||||
Cette methode devra etre lancer toujours via un thread ou un timer.
|
||||
Args:
|
||||
@@ -440,19 +441,19 @@ def action_scan_client_with_cloudfilt(uplink: 'Defender', user_model: 'MUser') -
|
||||
username = user_model.username
|
||||
hostname = user_model.hostname
|
||||
nickname = user_model.nickname
|
||||
p = uplink.Protocol
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
|
||||
if remote_ip in uplink.Config.WHITELISTED_IP:
|
||||
if remote_ip in uplink.ctx.Config.WHITELISTED_IP:
|
||||
return None
|
||||
if uplink.ModConfig.cloudfilt_scan == 0:
|
||||
if uplink.mod_config.cloudfilt_scan == 0:
|
||||
return None
|
||||
if uplink.cloudfilt_key == '':
|
||||
return None
|
||||
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
service_chanlog = uplink.Config.SERVICE_CHANLOG
|
||||
color_red = uplink.Config.COLORS.red
|
||||
nogc = uplink.Config.COLORS.nogc
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
service_chanlog = uplink.ctx.Config.SERVICE_CHANLOG
|
||||
color_red = uplink.ctx.Config.COLORS.red
|
||||
nogc = uplink.ctx.Config.COLORS.nogc
|
||||
|
||||
url = "https://developers18334.cloudfilt.com/"
|
||||
|
||||
@@ -466,7 +467,7 @@ def action_scan_client_with_cloudfilt(uplink: 'Defender', user_model: 'MUser') -
|
||||
decoded_response: dict = loads(response.text)
|
||||
status_code = response.status_code
|
||||
if status_code != 200:
|
||||
uplink.Logs.warning(f'Error connecting to cloudfilt API | Code: {str(status_code)}')
|
||||
uplink.ctx.Logs.warning(f'Error connecting to cloudfilt API | Code: {str(status_code)}')
|
||||
return
|
||||
|
||||
result = {
|
||||
@@ -479,22 +480,22 @@ def action_scan_client_with_cloudfilt(uplink: 'Defender', user_model: 'MUser') -
|
||||
# pseudo!ident@host
|
||||
fullname = f'{nickname}!{username}@{hostname}'
|
||||
|
||||
p.send_priv_msg(
|
||||
await p.send_priv_msg(
|
||||
nick_from=service_id,
|
||||
msg=f"[ {color_red}CLOUDFILT_SCAN{nogc} ] : Connexion de {fullname} ({remote_ip}) ==> Host: {str(result['host'])} | country: {str(result['countryiso'])} | listed: {str(result['listed'])} | listed by : {str(result['listed_by'])}",
|
||||
channel=service_chanlog)
|
||||
|
||||
uplink.Logs.debug(f"[CLOUDFILT SCAN] ({fullname}) connected from ({result['countryiso']}), Listed: {result['listed']}, by: {result['listed_by']}")
|
||||
uplink.ctx.Logs.debug(f"[CLOUDFILT SCAN] ({fullname}) connected from ({result['countryiso']}), Listed: {result['listed']}, by: {result['listed_by']}")
|
||||
|
||||
if result['listed']:
|
||||
p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.Config.GLINE_DURATION} Your connexion is listed as dangerous {str(result['listed'])} {str(result['listed_by'])} - detected by cloudfilt")
|
||||
uplink.Logs.debug(f"[CLOUDFILT SCAN GLINE] Dangerous connection ({fullname}) from ({result['countryiso']}) Listed: {result['listed']}, by: {result['listed_by']}")
|
||||
await p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.ctx.Config.GLINE_DURATION} Your connexion is listed as dangerous {str(result['listed'])} {str(result['listed_by'])} - detected by cloudfilt")
|
||||
uplink.ctx.Logs.debug(f"[CLOUDFILT SCAN GLINE] Dangerous connection ({fullname}) from ({result['countryiso']}) Listed: {result['listed']}, by: {result['listed_by']}")
|
||||
|
||||
response.close()
|
||||
|
||||
return result
|
||||
|
||||
def action_scan_client_with_freeipapi(uplink: 'Defender', user_model: 'MUser') -> Optional[dict[str, str]]:
|
||||
async def action_scan_client_with_freeipapi(uplink: 'Defender', user_model: 'MUser') -> Optional[dict[str, str]]:
|
||||
"""Analyse l'ip avec Freeipapi
|
||||
Cette methode devra etre lancer toujours via un thread ou un timer.
|
||||
Args:
|
||||
@@ -504,21 +505,21 @@ def action_scan_client_with_freeipapi(uplink: 'Defender', user_model: 'MUser') -
|
||||
dict[str, any] | None: les informations du provider
|
||||
keys : 'countryCode', 'isProxy'
|
||||
"""
|
||||
p = uplink.Protocol
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
remote_ip = user_model.remote_ip
|
||||
username = user_model.username
|
||||
hostname = user_model.hostname
|
||||
nickname = user_model.nickname
|
||||
|
||||
if remote_ip in uplink.Config.WHITELISTED_IP:
|
||||
if remote_ip in uplink.ctx.Config.WHITELISTED_IP:
|
||||
return None
|
||||
if uplink.ModConfig.freeipapi_scan == 0:
|
||||
if uplink.mod_config.freeipapi_scan == 0:
|
||||
return None
|
||||
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
service_chanlog = uplink.Config.SERVICE_CHANLOG
|
||||
color_red = uplink.Config.COLORS.red
|
||||
nogc = uplink.Config.COLORS.nogc
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
service_chanlog = uplink.ctx.Config.SERVICE_CHANLOG
|
||||
color_red = uplink.ctx.Config.COLORS.red
|
||||
nogc = uplink.ctx.Config.COLORS.nogc
|
||||
|
||||
url = f'https://freeipapi.com/api/json/{remote_ip}'
|
||||
|
||||
@@ -533,10 +534,10 @@ def action_scan_client_with_freeipapi(uplink: 'Defender', user_model: 'MUser') -
|
||||
|
||||
status_code = response.status_code
|
||||
if status_code == 429:
|
||||
uplink.Logs.warning('Too Many Requests - The rate limit for the API has been exceeded.')
|
||||
uplink.ctx.Logs.warning('Too Many Requests - The rate limit for the API has been exceeded.')
|
||||
return None
|
||||
elif status_code != 200:
|
||||
uplink.Logs.warning(f'status code = {str(status_code)}')
|
||||
uplink.ctx.Logs.warning(f'status code = {str(status_code)}')
|
||||
return None
|
||||
|
||||
result = {
|
||||
@@ -547,21 +548,21 @@ def action_scan_client_with_freeipapi(uplink: 'Defender', user_model: 'MUser') -
|
||||
# pseudo!ident@host
|
||||
fullname = f'{nickname}!{username}@{hostname}'
|
||||
|
||||
p.send_priv_msg(
|
||||
await p.send_priv_msg(
|
||||
nick_from=service_id,
|
||||
msg=f"[ {color_red}FREEIPAPI_SCAN{nogc} ] : Connexion de {fullname} ({remote_ip}) ==> Proxy: {str(result['isProxy'])} | Country : {str(result['countryCode'])}",
|
||||
channel=service_chanlog)
|
||||
uplink.Logs.debug(f"[FREEIPAPI SCAN] ({fullname}) connected from ({result['countryCode']}), Proxy: {result['isProxy']}")
|
||||
uplink.ctx.Logs.debug(f"[FREEIPAPI SCAN] ({fullname}) connected from ({result['countryCode']}), Proxy: {result['isProxy']}")
|
||||
|
||||
if result['isProxy']:
|
||||
p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.Config.GLINE_DURATION} This server do not allow proxy connexions {str(result['isProxy'])} - detected by freeipapi")
|
||||
uplink.Logs.debug(f"[FREEIPAPI SCAN GLINE] Server do not allow proxy connexions {result['isProxy']}")
|
||||
await p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.ctx.Config.GLINE_DURATION} This server do not allow proxy connexions {str(result['isProxy'])} - detected by freeipapi")
|
||||
uplink.ctx.Logs.debug(f"[FREEIPAPI SCAN GLINE] Server do not allow proxy connexions {result['isProxy']}")
|
||||
|
||||
response.close()
|
||||
|
||||
return result
|
||||
|
||||
def action_scan_client_with_abuseipdb(uplink: 'Defender', user_model: 'MUser') -> Optional[dict[str, str]]:
|
||||
async def action_scan_client_with_abuseipdb(uplink: 'Defender', user_model: 'MUser') -> Optional[dict[str, str]]:
|
||||
"""Analyse l'ip avec AbuseIpDB
|
||||
Cette methode devra etre lancer toujours via un thread ou un timer.
|
||||
Args:
|
||||
@@ -571,15 +572,15 @@ def action_scan_client_with_abuseipdb(uplink: 'Defender', user_model: 'MUser') -
|
||||
Returns:
|
||||
dict[str, str] | None: les informations du provider
|
||||
"""
|
||||
p = uplink.Protocol
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
remote_ip = user_model.remote_ip
|
||||
username = user_model.username
|
||||
hostname = user_model.hostname
|
||||
nickname = user_model.nickname
|
||||
|
||||
if remote_ip in uplink.Config.WHITELISTED_IP:
|
||||
if remote_ip in uplink.ctx.Config.WHITELISTED_IP:
|
||||
return None
|
||||
if uplink.ModConfig.abuseipdb_scan == 0:
|
||||
if uplink.mod_config.abuseipdb_scan == 0:
|
||||
return None
|
||||
|
||||
if uplink.abuseipdb_key == '':
|
||||
@@ -611,81 +612,81 @@ def action_scan_client_with_abuseipdb(uplink: 'Defender', user_model: 'MUser') -
|
||||
'totalReports': decoded_response.get('data', {}).get('totalReports', 0)
|
||||
}
|
||||
|
||||
service_id = uplink.Config.SERVICE_ID
|
||||
service_chanlog = uplink.Config.SERVICE_CHANLOG
|
||||
color_red = uplink.Config.COLORS.red
|
||||
nogc = uplink.Config.COLORS.nogc
|
||||
service_id = uplink.ctx.Config.SERVICE_ID
|
||||
service_chanlog = uplink.ctx.Config.SERVICE_CHANLOG
|
||||
color_red = uplink.ctx.Config.COLORS.red
|
||||
nogc = uplink.ctx.Config.COLORS.nogc
|
||||
|
||||
# pseudo!ident@host
|
||||
fullname = f'{nickname}!{username}@{hostname}'
|
||||
|
||||
p.send_priv_msg(
|
||||
await p.send_priv_msg(
|
||||
nick_from=service_id,
|
||||
msg=f"[ {color_red}ABUSEIPDB_SCAN{nogc} ] : Connexion de {fullname} ({remote_ip}) ==> Score: {str(result['score'])} | Country : {result['country']} | Tor : {str(result['isTor'])} | Total Reports : {str(result['totalReports'])}",
|
||||
channel=service_chanlog
|
||||
)
|
||||
uplink.Logs.debug(f"[ABUSEIPDB SCAN] ({fullname}) connected from ({result['country']}), Score: {result['score']}, Tor: {result['isTor']}")
|
||||
uplink.ctx.Logs.debug(f"[ABUSEIPDB SCAN] ({fullname}) connected from ({result['country']}), Score: {result['score']}, Tor: {result['isTor']}")
|
||||
|
||||
if result['isTor']:
|
||||
p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.Config.GLINE_DURATION} This server do not allow Tor connexions {str(result['isTor'])} - Detected by Abuseipdb")
|
||||
uplink.Logs.debug(f"[ABUSEIPDB SCAN GLINE] Server do not allow Tor connections Tor: {result['isTor']}, Score: {result['score']}")
|
||||
await p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.ctx.Config.GLINE_DURATION} This server do not allow Tor connexions {str(result['isTor'])} - Detected by Abuseipdb")
|
||||
uplink.ctx.Logs.debug(f"[ABUSEIPDB SCAN GLINE] Server do not allow Tor connections Tor: {result['isTor']}, Score: {result['score']}")
|
||||
elif result['score'] >= 95:
|
||||
p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.Config.GLINE_DURATION} You were banned from this server because your abuse score is = {str(result['score'])} - Detected by Abuseipdb")
|
||||
uplink.Logs.debug(f"[ABUSEIPDB SCAN GLINE] Server do not high risk connections Country: {result['country']}, Score: {result['score']}")
|
||||
await p.send2socket(f":{service_id} GLINE +*@{remote_ip} {uplink.ctx.Config.GLINE_DURATION} You were banned from this server because your abuse score is = {str(result['score'])} - Detected by Abuseipdb")
|
||||
uplink.ctx.Logs.debug(f"[ABUSEIPDB SCAN GLINE] Server do not high risk connections Country: {result['country']}, Score: {result['score']}")
|
||||
|
||||
response.close()
|
||||
|
||||
return result
|
||||
|
||||
def action_scan_client_with_local_socket(uplink: 'Defender', user_model: 'MUser'):
|
||||
async def action_scan_client_with_local_socket(uplink: 'Defender', user_model: 'MUser'):
|
||||
"""local_scan
|
||||
|
||||
Args:
|
||||
uplink (Defender): Defender instance object
|
||||
user_model (MUser): l'objet User qui contient l'ip
|
||||
"""
|
||||
p = uplink.Protocol
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
remote_ip = user_model.remote_ip
|
||||
username = user_model.username
|
||||
hostname = user_model.hostname
|
||||
nickname = user_model.nickname
|
||||
fullname = f'{nickname}!{username}@{hostname}'
|
||||
|
||||
if remote_ip in uplink.Config.WHITELISTED_IP:
|
||||
if remote_ip in uplink.ctx.Config.WHITELISTED_IP:
|
||||
return None
|
||||
|
||||
for port in uplink.Config.PORTS_TO_SCAN:
|
||||
for port in uplink.ctx.Config.PORTS_TO_SCAN:
|
||||
try:
|
||||
newSocket = ''
|
||||
newSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM or socket.SOCK_NONBLOCK)
|
||||
newSocket.settimeout(0.5)
|
||||
|
||||
connection = (remote_ip, uplink.Base.int_if_possible(port))
|
||||
connection = (remote_ip, uplink.ctx.Base.int_if_possible(port))
|
||||
newSocket.connect(connection)
|
||||
|
||||
p.send_priv_msg(
|
||||
nick_from=uplink.Config.SERVICE_NICKNAME,
|
||||
msg=f"[ {uplink.Config.COLORS.red}PROXY_SCAN{uplink.Config.COLORS.nogc} ] {fullname} ({remote_ip}) : Port [{str(port)}] ouvert sur l'adresse ip [{remote_ip}]",
|
||||
channel=uplink.Config.SERVICE_CHANLOG
|
||||
await p.send_priv_msg(
|
||||
nick_from=uplink.ctx.Config.SERVICE_NICKNAME,
|
||||
msg=f"[ {uplink.ctx.Config.COLORS.red}PROXY_SCAN{uplink.ctx.Config.COLORS.nogc} ] {fullname} ({remote_ip}) : Port [{str(port)}] ouvert sur l'adresse ip [{remote_ip}]",
|
||||
channel=uplink.ctx.Config.SERVICE_CHANLOG
|
||||
)
|
||||
# print(f"=======> Le port {str(port)} est ouvert !!")
|
||||
uplink.Base.running_sockets.append(newSocket)
|
||||
uplink.ctx.Base.running_sockets.append(newSocket)
|
||||
# print(newSocket)
|
||||
newSocket.shutdown(socket.SHUT_RDWR)
|
||||
newSocket.close()
|
||||
|
||||
except (socket.timeout, ConnectionRefusedError):
|
||||
uplink.Logs.info(f"Le port {remote_ip}:{str(port)} est fermé")
|
||||
uplink.ctx.Logs.info(f"Le port {remote_ip}:{str(port)} est fermé")
|
||||
except AttributeError as ae:
|
||||
uplink.Logs.warning(f"AttributeError ({remote_ip}): {ae}")
|
||||
uplink.ctx.Logs.warning(f"AttributeError ({remote_ip}): {ae}")
|
||||
except socket.gaierror as err:
|
||||
uplink.Logs.warning(f"Address Info Error ({remote_ip}): {err}")
|
||||
uplink.ctx.Logs.warning(f"Address Info Error ({remote_ip}): {err}")
|
||||
finally:
|
||||
# newSocket.shutdown(socket.SHUT_RDWR)
|
||||
newSocket.close()
|
||||
uplink.Logs.info('=======> Fermeture de la socket')
|
||||
uplink.ctx.Logs.info('=======> Fermeture de la socket')
|
||||
|
||||
def action_scan_client_with_psutil(uplink: 'Defender', user_model: 'MUser') -> list[int]:
|
||||
async def action_scan_client_with_psutil(uplink: 'Defender', user_model: 'MUser') -> list[int]:
|
||||
"""psutil_scan for Linux (should be run on the same location as the unrealircd server)
|
||||
|
||||
Args:
|
||||
@@ -694,13 +695,13 @@ def action_scan_client_with_psutil(uplink: 'Defender', user_model: 'MUser') -> l
|
||||
Returns:
|
||||
list[int]: list of ports
|
||||
"""
|
||||
p = uplink.Protocol
|
||||
p = uplink.ctx.Irc.Protocol
|
||||
remote_ip = user_model.remote_ip
|
||||
username = user_model.username
|
||||
hostname = user_model.hostname
|
||||
nickname = user_model.nickname
|
||||
|
||||
if remote_ip in uplink.Config.WHITELISTED_IP:
|
||||
if remote_ip in uplink.ctx.Config.WHITELISTED_IP:
|
||||
return None
|
||||
|
||||
try:
|
||||
@@ -708,16 +709,16 @@ def action_scan_client_with_psutil(uplink: 'Defender', user_model: 'MUser') -> l
|
||||
fullname = f'{nickname}!{username}@{hostname}'
|
||||
|
||||
matching_ports = [conn.raddr.port for conn in connections if conn.raddr and conn.raddr.ip == remote_ip]
|
||||
uplink.Logs.info(f"Connexion of {fullname} ({remote_ip}) using ports : {str(matching_ports)}")
|
||||
uplink.ctx.Logs.info(f"Connexion of {fullname} ({remote_ip}) using ports : {str(matching_ports)}")
|
||||
|
||||
if matching_ports:
|
||||
p.send_priv_msg(
|
||||
nick_from=uplink.Config.SERVICE_NICKNAME,
|
||||
msg=f"[ {uplink.Config.COLORS.red}PSUTIL_SCAN{uplink.Config.COLORS.black} ] {fullname} ({remote_ip}) : is using ports {matching_ports}",
|
||||
channel=uplink.Config.SERVICE_CHANLOG
|
||||
await p.send_priv_msg(
|
||||
nick_from=uplink.ctx.Config.SERVICE_NICKNAME,
|
||||
msg=f"[ {uplink.ctx.Config.COLORS.red}PSUTIL_SCAN{uplink.ctx.Config.COLORS.black} ] {fullname} ({remote_ip}) : is using ports {matching_ports}",
|
||||
channel=uplink.ctx.Config.SERVICE_CHANLOG
|
||||
)
|
||||
|
||||
return matching_ports
|
||||
|
||||
except psutil.AccessDenied as ad:
|
||||
uplink.Logs.critical(f'psutil_scan: Permission error: {ad}')
|
||||
uplink.ctx.Logs.critical(f'psutil_scan: Permission error: {ad}')
|
||||
@@ -48,7 +48,7 @@ class Test(IModule):
|
||||
# self.ctx.Base.db_execute_query(table_logs)
|
||||
return None
|
||||
|
||||
def load(self) -> None:
|
||||
async def load(self) -> None:
|
||||
"""### Load Module Configuration (Mandatory)
|
||||
"""
|
||||
|
||||
@@ -62,8 +62,11 @@ class Test(IModule):
|
||||
# Build the default configuration model (Mandatory)
|
||||
self._mod_config = self.ModConfModel(param_exemple1='str', param_exemple2=1)
|
||||
|
||||
# Init the module (Mandatory)
|
||||
self.init()
|
||||
# sync the database with local variable (Mandatory)
|
||||
await self.sync_db()
|
||||
|
||||
if self.mod_config.param_exemple2 == 1:
|
||||
await self.ctx.Irc.Protocol.send_priv_msg(self.ctx.Config.SERVICE_NICKNAME, "Param activated", self.ctx.Config.SERVICE_CHANLOG)
|
||||
|
||||
@property
|
||||
def mod_config(self) -> ModConfModel:
|
||||
@@ -71,7 +74,7 @@ class Test(IModule):
|
||||
|
||||
def unload(self) -> None:
|
||||
"""### This method is called when you unload, or you reload the module (Mandatory)"""
|
||||
self.ctx.Irc.Commands.drop_command_by_module(self.module_name)
|
||||
self.ctx.Commands.drop_command_by_module(self.module_name)
|
||||
return None
|
||||
|
||||
def cmd(self, data: list[str]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user