Replace build_command location, code refactoring on irc

This commit is contained in:
adator
2025-11-23 16:15:10 +01:00
parent d66d297a33
commit 226340e1aa
5 changed files with 149 additions and 188 deletions

View File

@@ -1,8 +1,7 @@
import asyncio import asyncio
import socket
import re import re
import time import ssl
from ssl import SSLSocket import threading
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Any, Optional, Union from typing import TYPE_CHECKING, Any, Optional, Union
from core.classes.modules import rehash from core.classes.modules import rehash
@@ -30,6 +29,10 @@ class Irc:
# Load Context class (Loader) # Load Context class (Loader)
self.ctx = loader self.ctx = loader
# Define Reader and Writer
self.reader: Optional[asyncio.StreamReader] = None
self.writer: Optional[asyncio.StreamWriter] = None
# Date et heure de la premiere connexion de Defender # Date et heure de la premiere connexion de Defender
self.defender_connexion_datetime = self.ctx.Config.DEFENDER_CONNEXION_DATETIME self.defender_connexion_datetime = self.ctx.Config.DEFENDER_CONNEXION_DATETIME
@@ -58,50 +61,56 @@ class Irc:
# Load Commands Utils # Load Commands Utils
# self.Commands = self.Loader.Commands # self.Commands = self.Loader.Commands
"""Command utils""" """Command utils"""
self.ctx.Commands.build_command(0, 'core', 'help', 'This provide the help')
self.ctx.Commands.build_command(0, 'core', 'auth', 'Login to the IRC Service')
self.ctx.Commands.build_command(0, 'core', 'copyright', 'Give some information about the IRC Service')
self.ctx.Commands.build_command(0, 'core', 'uptime', 'Give you since when the service is connected')
self.ctx.Commands.build_command(0, 'core', 'firstauth', 'First authentication of the Service')
self.ctx.Commands.build_command(0, 'core', 'register', f'Register your nickname /msg {self.ctx.Config.SERVICE_NICKNAME} REGISTER <password> <email>')
self.ctx.Commands.build_command(0, 'core', 'identify', f'Identify yourself with your password /msg {self.ctx.Config.SERVICE_NICKNAME} IDENTIFY <account> <password>')
self.ctx.Commands.build_command(0, 'core', 'logout', 'Reverse the effect of the identify command')
self.ctx.Commands.build_command(1, 'core', 'load', 'Load an existing module')
self.ctx.Commands.build_command(1, 'core', 'unload', 'Unload a module')
self.ctx.Commands.build_command(1, 'core', 'reload', 'Reload a module')
self.ctx.Commands.build_command(1, 'core', 'deauth', 'Deauth from the irc service')
self.ctx.Commands.build_command(1, 'core', 'checkversion', 'Check the version of the irc service')
self.ctx.Commands.build_command(2, 'core', 'show_modules', 'Display a list of loaded modules')
self.ctx.Commands.build_command(2, 'core', 'show_timers', 'Display active timers')
self.ctx.Commands.build_command(2, 'core', 'show_threads', 'Display active threads in the system')
self.ctx.Commands.build_command(2, 'core', 'show_asyncio', 'Display active asyncio')
self.ctx.Commands.build_command(2, 'core', 'show_channels', 'Display a list of active channels')
self.ctx.Commands.build_command(2, 'core', 'show_users', 'Display a list of connected users')
self.ctx.Commands.build_command(2, 'core', 'show_clients', 'Display a list of connected clients')
self.ctx.Commands.build_command(2, 'core', 'show_admins', 'Display a list of administrators')
self.ctx.Commands.build_command(2, 'core', 'show_configuration', 'Display the current configuration settings')
self.ctx.Commands.build_command(2, 'core', 'show_cache', 'Display the current cache')
self.ctx.Commands.build_command(2, 'core', 'clear_cache', 'Clear the cache!')
self.ctx.Commands.build_command(3, 'core', 'quit', 'Disconnect the bot or user from the server.')
self.ctx.Commands.build_command(3, 'core', 'restart', 'Restart the bot or service.')
self.ctx.Commands.build_command(3, 'core', 'addaccess', 'Add a user or entity to an access list with specific permissions.')
self.ctx.Commands.build_command(3, 'core', 'editaccess', 'Modify permissions for an existing user or entity in the access list.')
self.ctx.Commands.build_command(3, 'core', 'delaccess', 'Remove a user or entity from the access list.')
self.ctx.Commands.build_command(3, 'core', 'cert', 'Append your new fingerprint to your account!')
self.ctx.Commands.build_command(4, 'core', 'rehash', 'Reload the configuration file without restarting')
self.ctx.Commands.build_command(4, 'core', 'raw', 'Send a raw command directly to the IRC server')
self.ctx.Commands.build_command(4, 'core', 'print_vars', 'Print users in a file.')
self.ctx.Commands.build_command(4, 'core', 'start_rpc', 'Start defender jsonrpc server')
self.ctx.Commands.build_command(4, 'core', 'stop_rpc', 'Stop defender jsonrpc server')
self.build_command(0, 'core', 'help', 'This provide the help') ##############################################
self.build_command(0, 'core', 'auth', 'Login to the IRC Service') # CONNEXION IRC #
self.build_command(0, 'core', 'copyright', 'Give some information about the IRC Service') ##############################################
self.build_command(0, 'core', 'uptime', 'Give you since when the service is connected')
self.build_command(0, 'core', 'firstauth', 'First authentication of the Service')
self.build_command(0, 'core', 'register', f'Register your nickname /msg {self.ctx.Config.SERVICE_NICKNAME} REGISTER <password> <email>')
self.build_command(0, 'core', 'identify', f'Identify yourself with your password /msg {self.ctx.Config.SERVICE_NICKNAME} IDENTIFY <account> <password>')
self.build_command(0, 'core', 'logout', 'Reverse the effect of the identify command')
self.build_command(1, 'core', 'load', 'Load an existing module')
self.build_command(1, 'core', 'unload', 'Unload a module')
self.build_command(1, 'core', 'reload', 'Reload a module')
self.build_command(1, 'core', 'deauth', 'Deauth from the irc service')
self.build_command(1, 'core', 'checkversion', 'Check the version of the irc service')
self.build_command(2, 'core', 'show_modules', 'Display a list of loaded modules')
self.build_command(2, 'core', 'show_timers', 'Display active timers')
self.build_command(2, 'core', 'show_threads', 'Display active threads in the system')
self.build_command(2, 'core', 'show_asyncio', 'Display active asyncio')
self.build_command(2, 'core', 'show_channels', 'Display a list of active channels')
self.build_command(2, 'core', 'show_users', 'Display a list of connected users')
self.build_command(2, 'core', 'show_clients', 'Display a list of connected clients')
self.build_command(2, 'core', 'show_admins', 'Display a list of administrators')
self.build_command(2, 'core', 'show_configuration', 'Display the current configuration settings')
self.build_command(2, 'core', 'show_cache', 'Display the current cache')
self.build_command(2, 'core', 'clear_cache', 'Clear the cache!')
self.build_command(3, 'core', 'quit', 'Disconnect the bot or user from the server.')
self.build_command(3, 'core', 'restart', 'Restart the bot or service.')
self.build_command(3, 'core', 'addaccess', 'Add a user or entity to an access list with specific permissions.')
self.build_command(3, 'core', 'editaccess', 'Modify permissions for an existing user or entity in the access list.')
self.build_command(3, 'core', 'delaccess', 'Remove a user or entity from the access list.')
self.build_command(3, 'core', 'cert', 'Append your new fingerprint to your account!')
self.build_command(4, 'core', 'rehash', 'Reload the configuration file without restarting')
self.build_command(4, 'core', 'raw', 'Send a raw command directly to the IRC server')
self.build_command(4, 'core', 'print_vars', 'Print users in a file.')
self.build_command(4, 'core', 'start_rpc', 'Start defender jsonrpc server')
self.build_command(4, 'core', 'stop_rpc', 'Stop defender jsonrpc server')
# Define the IrcSocket object async def run(self):
self.IrcSocket: Optional[Union[socket.socket, SSLSocket]] = None try:
await self.connect()
self.reader: Optional[asyncio.StreamReader] = None await self.listen()
self.writer: Optional[asyncio.StreamWriter] = None except asyncio.exceptions.IncompleteReadError as ie:
# When IRCd server is down
self.ctx.Base.create_asynctask(self.heartbeat(self.beat)) # asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of undefined expected bytes
self.ctx.Logs.critical(f"The IRCd server is no more connected! {ie}")
except asyncio.exceptions.CancelledError as cerr:
self.ctx.Logs.debug(f"Asyncio CancelledError reached! {cerr}")
async def connect(self): async def connect(self):
@@ -116,24 +125,32 @@ class Irc:
await self.Protocol.send_link() await self.Protocol.send_link()
async def listen(self): async def listen(self):
self.ctx.Base.create_asynctask(
self.ctx.Base.create_thread_io(self.ctx.Utils.heartbeat, True, self.ctx, self.beat)
)
while self.signal: while self.signal:
data = await self.reader.readuntil(b'\r\n') data = await self.reader.readuntil(b'\r\n')
await self.send_response(data.splitlines()) await self.send_response(data.splitlines())
async def run(self): async def send_response(self, responses:list[bytes]) -> None:
try: try:
await self.connect() for data in responses:
await self.listen() response = data.decode(self.CHARSET[0]).split()
except asyncio.exceptions.IncompleteReadError as ie: await self.cmd(response)
# When IRCd server is down
# asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of undefined expected bytes
self.ctx.Logs.critical(f"The IRCd server is no more connected! {ie}")
except asyncio.exceptions.CancelledError as cerr:
self.ctx.Logs.debug(f"Asyncio CancelledError reached! {cerr}")
############################################## except (UnicodeEncodeError, UnicodeDecodeError) as ue:
# CONNEXION IRC # for data in responses:
############################################## response = data.decode(self.CHARSET[1], 'replace').split()
await self.cmd(response)
self.ctx.Logs.error(f'UnicodeEncodeError: {ue}')
self.ctx.Logs.error(responses)
except AssertionError as ae:
self.ctx.Logs.error(f"Assertion error : {ae}")
# --------------------------------------------
# FIN CONNEXION IRC #
# --------------------------------------------
def init_service_user(self) -> None: def init_service_user(self) -> None:
@@ -157,51 +174,6 @@ class Irc:
chan = chan_name[0] chan = chan_name[0]
await self.Protocol.send_sjoin(channel=chan) await self.Protocol.send_sjoin(channel=chan)
async def send_response(self, responses:list[bytes]) -> None:
try:
for data in responses:
response = data.decode(self.CHARSET[0]).split()
await self.cmd(response)
except UnicodeEncodeError as ue:
for data in responses:
response = data.decode(self.CHARSET[1],'replace').split()
await self.cmd(response)
self.ctx.Logs.error(f'UnicodeEncodeError: {ue}')
self.ctx.Logs.error(response)
except UnicodeDecodeError as ud:
for data in responses:
response = data.decode(self.CHARSET[1],'replace').split()
await self.cmd(response)
self.ctx.Logs.error(f'UnicodeDecodeError: {ud}')
self.ctx.Logs.error(response)
except AssertionError as ae:
self.ctx.Logs.error(f"Assertion error : {ae}")
def unload(self) -> None:
# This is only to reference the method
return None
# --------------------------------------------
# FIN CONNEXION IRC #
# --------------------------------------------
def build_command(self, level: int, module_name: str, command_name: str, command_description: str) -> None:
"""This method build the commands variable
Args:
level (int): The Level of the command
module_name (str): The module name
command_name (str): The command name
command_description (str): The description of the command
"""
# Build Model.
self.ctx.Commands.build(self.ctx.Definition.MCommand(module_name, command_name, command_description, level))
return None
async def generate_help_menu(self, nickname: str, module: Optional[str] = None) -> None: async def generate_help_menu(self, nickname: str, module: Optional[str] = None) -> None:
# Check if the nickname is an admin # Check if the nickname is an admin
@@ -289,17 +261,6 @@ class Irc:
return uptime return uptime
async def heartbeat(self, beat: float) -> None:
"""Execute certaines commandes de nettoyage toutes les x secondes
x étant définit a l'initialisation de cette class (self.beat)
Args:
beat (float): Nombre de secondes entre chaque exécution
"""
while self.hb_active:
await asyncio.sleep(beat)
self.ctx.Base.execute_periodic_action()
def insert_db_admin(self, uid: str, account: str, level: int, language: str) -> None: def insert_db_admin(self, uid: str, account: str, level: int, language: str) -> None:
user_obj = self.ctx.User.get_user(uid) user_obj = self.ctx.User.get_user(uid)
@@ -413,12 +374,6 @@ class Irc:
for module in modules: for module in modules:
await module.class_instance.cmd(original_response) if self.ctx.Utils.is_coroutinefunction(module.class_instance.cmd) else module.class_instance.cmd(original_response) await module.class_instance.cmd(original_response) if self.ctx.Utils.is_coroutinefunction(module.class_instance.cmd) else module.class_instance.cmd(original_response)
# if len(original_response) > 2:
# if original_response[2] != 'UID':
# # Envoyer la commande aux classes dynamiquement chargées
# for module in self.ctx.ModuleUtils.model_get_loaded_modules().copy():
# module.class_instance.cmd(original_response)
except IndexError as ie: except IndexError as ie:
self.ctx.Logs.error(f"IndexError: {ie}") self.ctx.Logs.error(f"IndexError: {ie}")
except Exception as err: except Exception as err:
@@ -441,7 +396,7 @@ class Irc:
if u is None: if u is None:
return None return None
c = self.ctx.Client.get_Client(u.uid) c = self.ctx.Client.get_client(u.uid)
"""The Client Object""" """The Client Object"""
fromuser = u.nickname fromuser = u.nickname
@@ -627,7 +582,7 @@ class Irc:
level = self.ctx.Base.int_if_possible(cmd[2]) level = self.ctx.Base.int_if_possible(cmd[2])
password = str(cmd[3]) password = str(cmd[3])
self.create_defender_user(fromuser, new_admin, level, password) await self.create_defender_user(fromuser, new_admin, level, password)
return None return None
except IndexError as ie: except IndexError as ie:
@@ -982,11 +937,10 @@ class Irc:
try: try:
final_reason = ' '.join(cmd[1:]) final_reason = ' '.join(cmd[1:])
self.hb_active = False self.hb_active = False
await self.ctx.Base.shutdown() await rehash.shutdown(self.ctx)
self.ctx.Base.execute_periodic_action() self.ctx.Base.execute_periodic_action()
for chan_name in self.ctx.Channel.UID_CHANNEL_DB: for chan_name in self.ctx.Channel.UID_CHANNEL_DB:
# self.Protocol.send_mode_chan(chan_name.name, '-l')
await self.Protocol.send_set_mode('-l', channel_name=chan_name.name) await self.Protocol.send_set_mode('-l', channel_name=chan_name.name)
for client in self.ctx.Client.CLIENT_DB: for client in self.ctx.Client.CLIENT_DB:
@@ -1002,7 +956,6 @@ class Irc:
self.ctx.Logs.info(f'Arrêt du server {dnickname}') self.ctx.Logs.info(f'Arrêt du server {dnickname}')
self.ctx.Config.DEFENDER_RESTART = 0 self.ctx.Config.DEFENDER_RESTART = 0
await self.writer.drain()
self.writer.close() self.writer.close()
await self.writer.wait_closed() await self.writer.wait_closed()
@@ -1011,6 +964,8 @@ class Irc:
except ConnectionResetError: except ConnectionResetError:
if self.writer.is_closing(): if self.writer.is_closing():
self.ctx.Logs.debug(f"Defender stopped properly!") self.ctx.Logs.debug(f"Defender stopped properly!")
except ssl.SSLError as serr:
self.ctx.Logs.error(f"Defender has ended with an SSL Error! - {serr}")
case 'restart': case 'restart':
final_reason = ' '.join(cmd[1:]) final_reason = ' '.join(cmd[1:])
@@ -1080,6 +1035,13 @@ class Irc:
msg=f">> {thread.name} ({thread.is_alive()})" msg=f">> {thread.name} ({thread.is_alive()})"
) )
for thread in threading.enumerate():
await self.Protocol.send_notice(
nick_from=dnickname,
nick_to=fromuser,
msg=f">> Thread name: {thread.name} - Is alive: {thread.is_alive()} - Daemon: {thread.daemon}"
)
return None return None
case 'show_asyncio': case 'show_asyncio':
@@ -1209,10 +1171,10 @@ class Irc:
return None return None
case 'start_rpc': case 'start_rpc':
self.ctx.Base.create_asynctask(self.ctx.RpcServer.start_server()) self.ctx.Base.create_asynctask(self.ctx.RpcServer.start_rpc_server())
case 'stop_rpc': case 'stop_rpc':
self.ctx.Base.create_asynctask(self.ctx.RpcServer.stop_server()) self.ctx.Base.create_asynctask(self.ctx.RpcServer.stop_rpc_server())
case _: case _:
pass pass

View File

@@ -73,7 +73,7 @@ class Clone(IModule):
self.ctx.Logs.debug(f"Cache Size = {self.ctx.Settings.get_cache_size()}") self.ctx.Logs.debug(f"Cache Size = {self.ctx.Settings.get_cache_size()}")
# Créer les nouvelles commandes du module # Créer les nouvelles commandes du module
self.ctx.Irc.build_command(1, self.module_name, 'clone', 'Connect, join, part, kill and say clones') self.ctx.Commands.build_command(1, self.module_name, 'clone', 'Connect, join, part, kill and say clones')
await self.ctx.Channel.db_query_channel(action='add', module_name=self.module_name, channel_name=self.ctx.Config.CLONE_CHANNEL) 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_sjoin(self.ctx.Config.CLONE_CHANNEL)

View File

@@ -65,56 +65,56 @@ class Command(IModule):
for c in new_cmds: for c in new_cmds:
self.ctx.Irc.Protocol.known_protocol.add(c) self.ctx.Irc.Protocol.known_protocol.add(c)
self.ctx.Irc.build_command(2, self.module_name, 'join', 'Join a channel') self.ctx.Commands.build_command(2, self.module_name, 'join', 'Join a channel')
self.ctx.Irc.build_command(2, self.module_name, 'assign', 'Assign a user to a role or task') self.ctx.Commands.build_command(2, self.module_name, 'assign', 'Assign a user to a role or task')
self.ctx.Irc.build_command(2, self.module_name, 'part', 'Leave a channel') self.ctx.Commands.build_command(2, self.module_name, 'part', 'Leave a channel')
self.ctx.Irc.build_command(2, self.module_name, 'unassign', 'Remove a user from a role or task') self.ctx.Commands.build_command(2, self.module_name, 'unassign', 'Remove a user from a role or task')
self.ctx.Irc.build_command(2, self.module_name, 'owner', 'Give channel ownership to a user') self.ctx.Commands.build_command(2, self.module_name, 'owner', 'Give channel ownership to a user')
self.ctx.Irc.build_command(2, self.module_name, 'deowner', 'Remove channel ownership from a user') self.ctx.Commands.build_command(2, self.module_name, 'deowner', 'Remove channel ownership from a user')
self.ctx.Irc.build_command(2, self.module_name, 'protect', 'Protect a user from being kicked') self.ctx.Commands.build_command(2, self.module_name, 'protect', 'Protect a user from being kicked')
self.ctx.Irc.build_command(2, self.module_name, 'deprotect', 'Remove protection from a user') self.ctx.Commands.build_command(2, self.module_name, 'deprotect', 'Remove protection from a user')
self.ctx.Irc.build_command(2, self.module_name, 'op', 'Grant operator privileges to a user') self.ctx.Commands.build_command(2, self.module_name, 'op', 'Grant operator privileges to a user')
self.ctx.Irc.build_command(2, self.module_name, 'deop', 'Remove operator privileges from a user') self.ctx.Commands.build_command(2, self.module_name, 'deop', 'Remove operator privileges from a user')
self.ctx.Irc.build_command(1, self.module_name, 'halfop', 'Grant half-operator privileges to a user') self.ctx.Commands.build_command(1, self.module_name, 'halfop', 'Grant half-operator privileges to a user')
self.ctx.Irc.build_command(1, self.module_name, 'dehalfop', 'Remove half-operator privileges from a user') self.ctx.Commands.build_command(1, self.module_name, 'dehalfop', 'Remove half-operator privileges from a user')
self.ctx.Irc.build_command(1, self.module_name, 'voice', 'Grant voice privileges to a user') self.ctx.Commands.build_command(1, self.module_name, 'voice', 'Grant voice privileges to a user')
self.ctx.Irc.build_command(1, self.module_name, 'devoice', 'Remove voice privileges from a user') self.ctx.Commands.build_command(1, self.module_name, 'devoice', 'Remove voice privileges from a user')
self.ctx.Irc.build_command(1, self.module_name, 'topic', 'Change the topic of a channel') self.ctx.Commands.build_command(1, self.module_name, 'topic', 'Change the topic of a channel')
self.ctx.Irc.build_command(2, self.module_name, 'opall', 'Grant operator privileges to all users') self.ctx.Commands.build_command(2, self.module_name, 'opall', 'Grant operator privileges to all users')
self.ctx.Irc.build_command(2, self.module_name, 'deopall', 'Remove operator privileges from all users') self.ctx.Commands.build_command(2, self.module_name, 'deopall', 'Remove operator privileges from all users')
self.ctx.Irc.build_command(2, self.module_name, 'devoiceall', 'Remove voice privileges from all users') self.ctx.Commands.build_command(2, self.module_name, 'devoiceall', 'Remove voice privileges from all users')
self.ctx.Irc.build_command(2, self.module_name, 'voiceall', 'Grant voice privileges to all users') self.ctx.Commands.build_command(2, self.module_name, 'voiceall', 'Grant voice privileges to all users')
self.ctx.Irc.build_command(2, self.module_name, 'ban', 'Ban a user from a channel') self.ctx.Commands.build_command(2, self.module_name, 'ban', 'Ban a user from a channel')
self.ctx.Irc.build_command(2, self.module_name, 'automode', 'Automatically set user modes upon join') self.ctx.Commands.build_command(2, self.module_name, 'automode', 'Automatically set user modes upon join')
self.ctx.Irc.build_command(2, self.module_name, 'unban', 'Remove a ban from a user') self.ctx.Commands.build_command(2, self.module_name, 'unban', 'Remove a ban from a user')
self.ctx.Irc.build_command(2, self.module_name, 'kick', 'Kick a user from a channel') self.ctx.Commands.build_command(2, self.module_name, 'kick', 'Kick a user from a channel')
self.ctx.Irc.build_command(2, self.module_name, 'kickban', 'Kick and ban a user from a channel') self.ctx.Commands.build_command(2, self.module_name, 'kickban', 'Kick and ban a user from a channel')
self.ctx.Irc.build_command(2, self.module_name, 'umode', 'Set user mode') self.ctx.Commands.build_command(2, self.module_name, 'umode', 'Set user mode')
self.ctx.Irc.build_command(2, self.module_name, 'mode', 'Set channel mode') self.ctx.Commands.build_command(2, self.module_name, 'mode', 'Set channel mode')
self.ctx.Irc.build_command(2, self.module_name, 'get_mode', 'Retrieve current channel mode') self.ctx.Commands.build_command(2, self.module_name, 'get_mode', 'Retrieve current channel mode')
self.ctx.Irc.build_command(2, self.module_name, 'svsjoin', 'Force a user to join a channel') self.ctx.Commands.build_command(2, self.module_name, 'svsjoin', 'Force a user to join a channel')
self.ctx.Irc.build_command(2, self.module_name, 'svspart', 'Force a user to leave a channel') self.ctx.Commands.build_command(2, self.module_name, 'svspart', 'Force a user to leave a channel')
self.ctx.Irc.build_command(2, self.module_name, 'svsnick', 'Force a user to change their nickname') self.ctx.Commands.build_command(2, self.module_name, 'svsnick', 'Force a user to change their nickname')
self.ctx.Irc.build_command(2, self.module_name, 'wallops', 'Send a message to all operators') self.ctx.Commands.build_command(2, self.module_name, 'wallops', 'Send a message to all operators')
self.ctx.Irc.build_command(2, self.module_name, 'globops', 'Send a global operator message') self.ctx.Commands.build_command(2, self.module_name, 'globops', 'Send a global operator message')
self.ctx.Irc.build_command(2, self.module_name, 'gnotice', 'Send a global notice') self.ctx.Commands.build_command(2, self.module_name, 'gnotice', 'Send a global notice')
self.ctx.Irc.build_command(2, self.module_name, 'whois', 'Get information about a user') self.ctx.Commands.build_command(2, self.module_name, 'whois', 'Get information about a user')
self.ctx.Irc.build_command(2, self.module_name, 'names', 'List users in a channel') self.ctx.Commands.build_command(2, self.module_name, 'names', 'List users in a channel')
self.ctx.Irc.build_command(2, self.module_name, 'invite', 'Invite a user to a channel') self.ctx.Commands.build_command(2, self.module_name, 'invite', 'Invite a user to a channel')
self.ctx.Irc.build_command(2, self.module_name, 'inviteme', 'Invite yourself to a channel') self.ctx.Commands.build_command(2, self.module_name, 'inviteme', 'Invite yourself to a channel')
self.ctx.Irc.build_command(2, self.module_name, 'sajoin', 'Force yourself into a channel') self.ctx.Commands.build_command(2, self.module_name, 'sajoin', 'Force yourself into a channel')
self.ctx.Irc.build_command(2, self.module_name, 'sapart', 'Force yourself to leave a channel') self.ctx.Commands.build_command(2, self.module_name, 'sapart', 'Force yourself to leave a channel')
self.ctx.Irc.build_command(2, self.module_name, 'kill', 'Disconnect a user from the server') self.ctx.Commands.build_command(2, self.module_name, 'kill', 'Disconnect a user from the server')
self.ctx.Irc.build_command(2, self.module_name, 'gline', 'Ban a user from the entire server') self.ctx.Commands.build_command(2, self.module_name, 'gline', 'Ban a user from the entire server')
self.ctx.Irc.build_command(2, self.module_name, 'ungline', 'Remove a global server ban') self.ctx.Commands.build_command(2, self.module_name, 'ungline', 'Remove a global server ban')
self.ctx.Irc.build_command(2, self.module_name, 'kline', 'Ban a user based on their hostname') self.ctx.Commands.build_command(2, self.module_name, 'kline', 'Ban a user based on their hostname')
self.ctx.Irc.build_command(2, self.module_name, 'unkline', 'Remove a K-line ban') self.ctx.Commands.build_command(2, self.module_name, 'unkline', 'Remove a K-line ban')
self.ctx.Irc.build_command(2, self.module_name, 'shun', 'Prevent a user from sending messages') self.ctx.Commands.build_command(2, self.module_name, 'shun', 'Prevent a user from sending messages')
self.ctx.Irc.build_command(2, self.module_name, 'unshun', 'Remove a shun from a user') self.ctx.Commands.build_command(2, self.module_name, 'unshun', 'Remove a shun from a user')
self.ctx.Irc.build_command(2, self.module_name, 'glinelist', 'List all global bans') self.ctx.Commands.build_command(2, self.module_name, 'glinelist', 'List all global bans')
self.ctx.Irc.build_command(2, self.module_name, 'shunlist', 'List all shunned users') self.ctx.Commands.build_command(2, self.module_name, 'shunlist', 'List all shunned users')
self.ctx.Irc.build_command(2, self.module_name, 'klinelist', 'List all K-line bans') self.ctx.Commands.build_command(2, self.module_name, 'klinelist', 'List all K-line bans')
self.ctx.Irc.build_command(3, self.module_name, 'map', 'Show the server network map') self.ctx.Commands.build_command(3, self.module_name, 'map', 'Show the server network map')
def unload(self) -> None: def unload(self) -> None:
self.ctx.Commands.drop_command_by_module(self.module_name) self.ctx.Commands.drop_command_by_module(self.module_name)
@@ -214,7 +214,7 @@ class Command(IModule):
user_uid = self.ctx.User.clean_uid(cmd[5]) user_uid = self.ctx.User.clean_uid(cmd[5])
userObj: MUser = self.ctx.User.get_user(user_uid) userObj: MUser = self.ctx.User.get_user(user_uid)
channel_name = cmd[4] if self.ctx.Channel.is_valid_channel(cmd[4]) else None channel_name = cmd[4] if self.ctx.Channel.is_valid_channel(cmd[4]) else None
client_obj = self.ctx.Client.get_Client(user_uid) client_obj = self.ctx.Client.get_client(user_uid)
nickname = userObj.nickname if userObj is not None else None nickname = userObj.nickname if userObj is not None else None
if client_obj is not None: if client_obj is not None:

View File

@@ -91,9 +91,9 @@ class Jsonrpc(IModule):
self.is_streaming = False self.is_streaming = False
# Create module commands (Mandatory) # Create module commands (Mandatory)
self.ctx.Irc.build_command(1, self.module_name, 'jsonrpc', 'Activate the JSON RPC Live connection [ON|OFF]') self.ctx.Commands.build_command(1, self.module_name, 'jsonrpc', 'Activate the JSON RPC Live connection [ON|OFF]')
self.ctx.Irc.build_command(1, self.module_name, 'jruser', 'Get Information about a user using JSON RPC') self.ctx.Commands.build_command(1, self.module_name, 'jruser', 'Get Information about a user using JSON RPC')
self.ctx.Irc.build_command(1, self.module_name, 'jrinstances', 'Get number of instances') self.ctx.Commands.build_command(1, self.module_name, 'jrinstances', 'Get number of instances')
try: try:
self.Rpc = ConnectionFactory(self.ctx.Config.DEBUG_LEVEL).get(self.ctx.Config.JSONRPC_METHOD) self.Rpc = ConnectionFactory(self.ctx.Config.DEBUG_LEVEL).get(self.ctx.Config.JSONRPC_METHOD)
@@ -138,7 +138,6 @@ class Jsonrpc(IModule):
channel=self.ctx.Config.SERVICE_CHANLOG channel=self.ctx.Config.SERVICE_CHANLOG
) )
self.ctx.Base.create_asynctask(thds.thread_unsubscribe(self)) self.ctx.Base.create_asynctask(thds.thread_unsubscribe(self))
# await self.update_configuration('jsonrpc', 0)
self.ctx.Commands.drop_command_by_module(self.module_name) self.ctx.Commands.drop_command_by_module(self.module_name)
self.ctx.Logs.debug(f"Unloading {self.module_name}") self.ctx.Logs.debug(f"Unloading {self.module_name}")
return None return None

View File

@@ -53,11 +53,11 @@ class Test(IModule):
""" """
# Create module commands (Mandatory) # Create module commands (Mandatory)
self.ctx.Irc.build_command(0, self.module_name, 'test-command', 'Execute a test command') self.ctx.Commands.build_command(0, self.module_name, 'test-command', 'Execute a test command')
self.ctx.Irc.build_command(0, self.module_name, 'asyncio', 'Create a new asynchron task!') self.ctx.Commands.build_command(0, self.module_name, 'asyncio', 'Create a new asynchron task!')
self.ctx.Irc.build_command(1, self.module_name, 'test_level_1', 'Execute a level 1 test command') self.ctx.Commands.build_command(1, self.module_name, 'test_level_1', 'Execute a level 1 test command')
self.ctx.Irc.build_command(2, self.module_name, 'test_level_2', 'Execute a level 2 test command') self.ctx.Commands.build_command(2, self.module_name, 'test_level_2', 'Execute a level 2 test command')
self.ctx.Irc.build_command(3, self.module_name, 'test_level_3', 'Execute a level 3 test command') self.ctx.Commands.build_command(3, self.module_name, 'test_level_3', 'Execute a level 3 test command')
# Build the default configuration model (Mandatory) # Build the default configuration model (Mandatory)
self._mod_config = self.ModConfModel(param_exemple1='str', param_exemple2=1) self._mod_config = self.ModConfModel(param_exemple1='str', param_exemple2=1)