myircbot/plugins/give.py
2025-05-29 22:58:53 +02:00

37 lines
1.3 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class GivePlugin:
"""Plugin para ejecutar un comando y enviar el resultado a otro usuario."""
def __init__(self, plugins):
self.plugins = plugins
def run(self, sender, *args):
"""Ejecuta un comando y envía el resultado como '<usuario>: <salida_del_comando>'."""
if len(args) < 2:
return " Uso: `.give <usuario> <comando> [argumentos]`"
usuario = args[0] # Primer argumento es el usuario
comando = args[1] # Segundo argumento es el comando a ejecutar
parametros = args[2:] # El resto son los argumentos del comando
if comando == "give":
return " No puedes usar 'give' dentro de 'give'."
if comando not in self.plugins:
return f" El comando '{comando}' no existe."
try:
plugin_or_func = self.plugins[comando]
if callable(plugin_or_func):
resultado = plugin_or_func(sender, *parametros)
else:
resultado = plugin_or_func.run(sender, *parametros)
return f" {usuario}: {resultado}"
except Exception as e:
return f" Error al ejecutar '{comando}': {str(e)}"
def help(self):
return " Usa `.give <usuario> <comando> [argumentos]` para ejecutar un comando y enviar el resultado como '<usuario>: <resultado>'."