from utils.deliver_relay_commands import deliverRelayCommands


class CmdCommand:
    def __init__(self, *args):
        self.cmd(*args)

    def cmd(
        self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
    ):
        if authed:
            if length > 4:
                if not spl[1].isdigit():
                    failure("Must be a number, not %s" % spl[1])
                    return
                commands = {spl[3]: [" ".join(spl[4:])]}
                success("Sending commands to relay %s as user %s" % (spl[2], spl[3]))
                deliverRelayCommands(int(spl[1]), commands, user=spl[2])
                return
            else:
                incUsage("cmd")
                return
        else:
            incUsage(None)
