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

@@ -73,7 +73,7 @@ class Clone(IModule):
self.ctx.Logs.debug(f"Cache Size = {self.ctx.Settings.get_cache_size()}")
# 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.Irc.Protocol.send_sjoin(self.ctx.Config.CLONE_CHANNEL)

View File

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

View File

@@ -91,9 +91,9 @@ class Jsonrpc(IModule):
self.is_streaming = False
# Create module commands (Mandatory)
self.ctx.Irc.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.Irc.build_command(1, self.module_name, 'jrinstances', 'Get number of instances')
self.ctx.Commands.build_command(1, self.module_name, 'jsonrpc', 'Activate the JSON RPC Live connection [ON|OFF]')
self.ctx.Commands.build_command(1, self.module_name, 'jruser', 'Get Information about a user using JSON RPC')
self.ctx.Commands.build_command(1, self.module_name, 'jrinstances', 'Get number of instances')
try:
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
)
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.Logs.debug(f"Unloading {self.module_name}")
return None

View File

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