var scriptName = "ReallyHardSpammer";
var scriptAuthor = "cancername";
var scriptVersion = 1.0;

// the function that generates the random string
function grs(len, charSet) {
    charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var randomString = '';
    for (var i = 0; i < len; i++) {
        var randomPoz = Math.floor(Math.random() * charSet.length);
        randomString += charSet.substring(randomPoz, randomPoz + 1);
    }
    return randomString;
}

function FlyModule() {

    var mode = value.createList("Mode", ["Normal", "AxoChat"], "Normal");
    var mesg = value.createText("Message", "SPAM"); // the message
    var sepa = value.createText("Separator", "---"); // the string that separates garbage and message
    var len1 = value.createInteger("BeforeLegth", 55, 0, 256); // spam before message
    var len2 = value.createInteger("AfterLength", 256, 0, 256); // spam after message
    var dely = value.createInteger("DelayTicks", 40, 2, 120); // ticks to wait

    // actually add the values
    this.addValues = function (values) {
        values.add(mode);
        values.add(mesg);
        values.add(sepa);
        values.add(len1);
        values.add(len2);
        values.add(dely);

    };

    //the usual shit
    this.getName = function () {
        return "ReallyHardSpammer";
    };

    this.getDescription = function () {
        return "SPAMS REALLY HARD";
    };

    this.getCategory = function () {
        return "Fun";

    };

    this.onUpdate = function () {
        // get to spamming
        if (mode.get() == "Normal") {
            if (mc.thePlayer.ticksExisted % dely.get() == 0) {
                mc.thePlayer.sendChatMessage(grs(len1.get()) + sepa.get() + mesg.get() + sepa.get() + grs(len2.get()));
            }
        } else {
            if (mc.thePlayer.ticksExisted % dely.get() == 0) {
                commandManager.executeCommand(".chat" + " " + grs(len1.get()) + sepa.get() + mesg.get() + sepa.get() + grs(len2.get()));
            }
        }
    };

    this.onEnable = function () {

    };
    this.onDisable = function () {

    };
}
var flyModule = new FlyModule();
var flyModuleClient;

function onEnable() {
    flyModuleClient = moduleManager.registerModule(flyModule);
}

function onDisable() {
    moduleManager.unregisterModule(flyModuleClient);
}