[Script] FileSpammer

Avatar

By Senk Ju 20 November 2018 23:01

Administrator · 463 comments

FileSpammer


I made a script which allows you to spam the content of a text file.

2018-11-21_00-07-01.gif

How to use:
1.) Import the script file or place it inside the scripts folder.
2.) Type .filespammer path <path-to-file-to-spam> into the chat.

Use .filespammer to see all options.

Code

var scriptName = "FileSpammer";
var scriptAuthor = "Senk Ju";
var scriptVersion = 1.0;

var File = Java.type("java.io.File");
var FileReader = Java.type("java.io.FileReader");
var BufferedReader = Java.type("java.io.BufferedReader");
var FileWriter = Java.type("java.io.FileWriter");
var BufferedWriter = Java.type("java.io.BufferedWriter");
var Timer = Java.type("java.util.Timer");

var config = {
    spamFilePath: "",
    spamDelay: 1000,
    appendRandom: true
}

var chatPrefix = "§8[§9FileSpam§8]";

function log(message, isError) {
    if (isError) {
        chat.print(chatPrefix + " §c" + message);
    } else {
        chat.print(chatPrefix + " §f" + message);
    }
}

function readFile(filePath) {
    try {
        var file = new File(filePath);
        var reader = new BufferedReader(new FileReader(file));
        var content = [];
        var line;

        while ((line = reader.readLine()) !== null) {
            content.push(line);
        }

        return content;
    } catch (err) {
        log("Unable to open file!", true);

        throw err;
    }
}

function writeFile(path, string) {
    try {
        writer = new BufferedWriter(new FileWriter(path));
        writer.write(string);

        writer.close();
    } catch (err) {}
}

function saveConfig() {
    var configJSON = JSON.stringify(config);

    writeFile(mc.mcDataDir + "/filespammer.json", configJSON);
}

function loadConfig() {
    try {
        config = JSON.parse(readFile(mc.mcDataDir + "/filespammer.json").join(""));
    } catch (err) {}
}

function randomString(length) {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    for (var i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    }

    return text;
}

function setInterval(func, milliseconds) {
    var timer = new Timer("setInterval", true);

    timer.schedule(function () {
        func();
    }, milliseconds, milliseconds);

    return timer;
}

function clearInterval(timer) {
    timer.cancel();
}

function setTimeout(func, milliseconds) {
    var timer = new Timer("setTimeout", true);
    timer.schedule(function () {
        func();
    }, milliseconds);

    return timer;
}

function FileSpammerModule() {
    var spamInterval;

    this.getName = function () {
        return "FileSpammer";
    }

    this.getDescription = function () {
        return "Spams the chat from a text file.";
    };

    this.getCategory = function () {
        return "Misc";
    }

    this.onEnable = function () {
        if (!config.spamFilePath) {
            log("Please specify a spam file using '.filespammer path <path>' before enabling this module!", true);

            var spamFileModule = moduleManager.getModule(this.getName());

            setTimeout(function () {
                spamFileModule.setState(false);
            }, 100);

            return;
        }

        var spamFile = readFile(config.spamFilePath);
        var spamIndex = 0;

        spamInterval = setInterval(function () {
            if (config.appendRandom) {
                mc.thePlayer.sendChatMessage(spamFile[spamIndex] + " [" + randomString(8) + "]");
            } else {
                mc.thePlayer.sendChatMessage(spamFile[spamIndex]);
            }

            if (spamIndex < spamFile.length - 1) {
                spamIndex++;
            } else {
                spamIndex = 0;
            }
        }, config.spamDelay);
    }

    this.onDisable = function () {
        clearInterval(spamInterval);
    }
}

function FileSpammerCommand() {
    this.getName = function () {
        return "filespammer";
    }

    this.getAliases = function () {
        return ["fs"];
    }

    this.execute = function (args) {
        if (args.length < 2) {
            log("Syntax Error: .filespammer <path/delay/appendRandom>", true);
            return;
        }

        switch (args[1].toLowerCase()) {
            case "path":
                if (args.length < 3) {
                    log("Syntax Error: .filespammer path <path>", true);
                    return;
                }

                config.spamFilePath = args[2];
                log("Set FileSpammer path to " + config.spamFilePath, false);
                saveConfig();

                break;

            case "delay":
                if (args.length < 3) {
                    log("Syntax Error: .filespammer delay <ms>", true);
                    return;
                }

                var input = parseInt(args[2]);

                if (input < 0) {
                    log("Please enter a value higher than 0", true);
                    return;
                }

                config.spamDelay = input;
                log("Set FileSpammer delay to " + input, false);
                saveConfig();

                break;

            case "appendrandom":
                config.appendRandom = !config.appendRandom;
                log("Set FileSpammer appendRandom to " + config.appendRandom, false);
                saveConfig();

                break;

            default:
                log("Syntax Error: .filespammer <path/delay/appendRandom>", true);
        }
    }
}

var fileSpammerModule = new FileSpammerModule();
var fileSpammerCommand = new FileSpammerCommand();

var fileSpammerModuleClient;
var fileSpammerCommandClient;

function onEnable() {
    loadConfig();

    fileSpammerModuleClient = moduleManager.registerModule(fileSpammerModule);
    fileSpammerCommandClient = commandManager.registerCommand(fileSpammerCommand);
}

function onDisable() {
    moduleManager.unregisterModule(fileSpammerModuleClient);
    commandManager.unregisterCommand(fileSpammerCommandClient);
}

CCBlueX Co-Owner

Avatar

By lolwhat2 21 November 2018 05:32

Member · 40 comments

An ad skip link right next to a version you can just copy and paste... Which one to choose...

Edit: someone removed the ad skip link but it was here http://dl.ccbluex.net/download/skip/ind … =236ad6eaf

Last edited by lolwhat2 (21 November 2018 21:18)

Avatar

By 1KrUtOy1 22 November 2018 15:25

Member · 16 comments

Suggestion
Add delay between spamming again
Add boolean: repeat
if false it will stop after end of file


Discord: _KrUtOy_#7701

Avatar

By Max 24 November 2018 15:22

Member · 15 comments

Kannst du noch adden das mann Ö Ä = $ [ Zeicchen etc mit dem spammer schreiben kann?