Search in sources :

Example 1 with Main

use of net.polarbub.botv2.Main in project universa by UniversaBlockchain.

the class CLIMainTest method createMain.

static Main createMain(String name, boolean nolog) throws InterruptedException {
    String path = new File("src/test_node_config_v2/" + name).getAbsolutePath();
    System.out.println(path);
    String[] args = new String[] { "--test", "--config", path, nolog ? "--nolog" : "" };
    Main main = new Main(args);
    try {
        main.config.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s"));
    } catch (KeyAddress.IllegalAddressException e) {
        e.printStackTrace();
    }
    try {
        // main.config.getKeysWhiteList().add(CLIMain.getPrivateKey().getPublicKey());
        main.config.getAddressesWhiteList().add(new KeyAddress(CLIMain.getPrivateKey().getPublicKey(), 0, true));
    } catch (IOException e) {
        e.printStackTrace();
    }
    // main.config.getKeysWhiteList().add(main.config.getUIssuerKey());
    main.waitReady();
    return main;
}
Also used : KeyAddress(com.icodici.crypto.KeyAddress) IOException(java.io.IOException) File(java.io.File) Main(com.icodici.universa.node2.Main)

Example 2 with Main

use of net.polarbub.botv2.Main in project SoftUni by kostovhg.

the class p14_ExportToExcel method main.

public static void main(String[] args) throws IOException {
    ArrayList<Object[]> allLines = new ArrayList<>();
    allLines.add(new Object[] { "FN", "First name", "Last Name", "Email", "Age", "Group", "Grade1", "Grade2", "Grade3", "Grade4", "Phones" });
    new BufferedReader(new FileReader("StudentsData.txt")).lines().map(x -> x.split("\\t")).filter(x -> !x[0].equals("FN")).forEach(allLines::add);
    // Create workbook and worksheet object
    int rowStart = 2;
    int columnStart = 0;
    int totalRows = allLines.size();
    int totalCols = allLines.get(0).length;
    int rowEnd = totalRows + rowStart - 1;
    int colEnd = totalCols + columnStart - 1;
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("SoftUniOOPCourseResults");
    CellStyle style1 = workbook.createCellStyle();
    style1.setAlignment(HorizontalAlignment.RIGHT);
    XSSFDataFormat intFormat = workbook.createDataFormat();
    style1.setDataFormat(intFormat.getFormat("0"));
    CellStyle style2 = workbook.createCellStyle();
    XSSFDataFormat strFormat = workbook.createDataFormat();
    style2.setDataFormat(strFormat.getFormat("General"));
    style2.setAlignment(HorizontalAlignment.LEFT);
    XSSFRow row;
    XSSFCell cell;
    // Create an object of type XSSFTable
    XSSFTable myTable = sheet.createTable();
    // Get CTTable object
    CTTable cttable = myTable.getCTTable();
    cttable.setTotalsRowShown(false);
    // Define the required style1 for the table
    CTTableStyleInfo table_style = cttable.addNewTableStyleInfo();
    table_style.setName("TableStyleLight14");
    // Set table style option
    table_style.setShowColumnStripes(false);
    table_style.setShowRowStripes(true);
    // define the data range including headers
    AreaReference my_data_range = new AreaReference(new CellReference(rowStart, columnStart), new CellReference(rowEnd, colEnd));
    // Set range to the table
    cttable.setRef(my_data_range.formatAsString());
    cttable.setDisplayName("Students");
    cttable.setName("Students");
    cttable.setId(1L);
    CTTableColumns columns = cttable.addNewTableColumns();
    CTAutoFilter autoFilter = cttable.addNewAutoFilter();
    columns.setCount(totalCols);
    // Define Header Information for the table
    for (int i = columnStart; i <= colEnd; i++) {
        CTTableColumn column = columns.addNewTableColumn();
        column.setName(allLines.get(0)[i].toString());
        column.setId(i + 1);
    }
    sheet.setAutoFilter(new CellRangeAddress(rowStart, rowStart, columnStart, colEnd));
    // Add remaining Table data
    row = sheet.createRow((short) 0);
    cell = row.createCell((short) 0);
    sheet.addMergedRegion(new CellRangeAddress(0, rowStart - 1, columnStart, colEnd));
    cell.setCellValue("SoftUni OOP Course Results");
    CellStyle bolded = workbook.createCellStyle();
    bolded.setAlignment(HorizontalAlignment.CENTER);
    XSSFFont myFont = workbook.createFont();
    myFont.setBold(true);
    myFont.setFontHeightInPoints((short) 30);
    bolded.setFont(myFont);
    cell.setCellStyle(bolded);
    int rowNum = rowStart;
    for (Object[] datatype : allLines) {
        XSSFRow inRow = sheet.createRow(rowNum++);
        int colNum = columnStart;
        for (Object field : datatype) {
            XSSFCell inCell = inRow.createCell(colNum++);
            if (isInt(field)) {
                inCell.setCellStyle(style1);
                inCell.setCellType(CellType.NUMERIC);
                inCell.setCellValue((Double) field);
            } else {
                inCell.setCellStyle(style2);
                inCell.setCellType(CellType.STRING);
                inCell.setCellValue((String) field);
            }
        }
    }
    for (int i = 1; i <= 11; i++) {
        sheet.autoSizeColumn(i);
    }
    try {
        FileOutputStream outputStream = new FileOutputStream(FILE_NAME);
        workbook.write(outputStream);
        workbook.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Done");
}
Also used : org.apache.poi.ss.usermodel(org.apache.poi.ss.usermodel) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) org.apache.poi.xssf.usermodel(org.apache.poi.xssf.usermodel) AreaReference(org.apache.poi.ss.util.AreaReference) java.io(java.io) org.openxmlformats.schemas.spreadsheetml.x2006.main(org.openxmlformats.schemas.spreadsheetml.x2006.main) CellReference(org.apache.poi.ss.util.CellReference) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) CellReference(org.apache.poi.ss.util.CellReference) AreaReference(org.apache.poi.ss.util.AreaReference) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 3 with Main

use of net.polarbub.botv2.Main in project MC-Server-Bot by polarbub.

the class Main method main.

public static void main(String[] args) throws InterruptedException, LoginException, IOException {
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        if (stopHard || (Main.serverThread.serverRunning && !Main.serverThread.serverStarted)) {
            Main.serverThread.p.destroy();
            return;
        } else if (Main.serverThread.serverStarted) {
            stopHard = true;
            System.out.println("\nWarning, killing running server!\nSend SIGINT again to hard stop the server.\nStrangely this doesn't print the normal server stopping lines even though it is stopping it cleanly.\nThe process with exit when the server is stopped.");
            // FIX: This doesn't print out the normal stopping text. The BR doesn't have anything in it. This is a won't fix.
            Main.serverThread.commandUse("stop");
            while (Main.serverThread.serverRunning) {
                // wait for server off
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        bot.shutdown();
    }));
    runTimeArgs = args;
    try {
        config.readConfig();
    } catch (IOException e) {
        System.out.println("Invalid config file location");
        configLoadedFailure = true;
        throw e;
    } catch (NullPointerException e) {
        System.out.println("Invalid config file");
        configLoadedFailure = true;
        throw e;
    } catch (IndexOutOfBoundsException e) {
        System.out.println("No config file declared, please append config file location to command used to start bot");
        configLoadedFailure = true;
        throw e;
    }
    if (backupTime > 0) {
        String statusText = runProgString(new ProcessBuilder("git", "status"));
        if (statusText.startsWith("fatal: ")) {
            boolean printed = false;
            if (statusText.startsWith("fatal: unsafe repository ('" + serverDir + "' is owned by someone else)\n" + "To add an exception for this directory, call:")) {
                System.out.println(statusText);
                printed = true;
            } else if (statusText.startsWith("fatal: not a git repository")) {
                System.out.println("fatal: '" + serverDir + "' is not a git initialized repo\n" + "To make a git repo there call, call:\n" + "\n" + "        git init " + serverDir + "\n");
                printed = true;
            }
            if (!printed) {
                System.out.println(statusText);
            }
            bot.shutdown();
            System.exit(1);
        }
    }
    // start the console in a thread
    inThread.start();
    // Start the console out
    outThread.start();
    // Start status thing
    statusThread.start();
}
Also used : IOException(java.io.IOException) net.polarbub.botv2.server.runProg.runProgString(net.polarbub.botv2.server.runProg.runProgString)

Example 4 with Main

use of net.polarbub.botv2.Main in project universa by UniversaBlockchain.

the class CLIMainTest method createLocalNetwork.

public static void createLocalNetwork() throws Exception {
    for (int i = 0; i < 3; i++) localNodes.add(createMain("node" + (i + 1), false));
    Main main = localNodes.get(0);
    assertEquals("http://localhost:8080", main.myInfo.internalUrlString());
    assertEquals("http://localhost:8080", main.myInfo.publicUrlString());
    assertEquals(main.cache, main.node.getCache());
}
Also used : Main(com.icodici.universa.node2.Main)

Example 5 with Main

use of net.polarbub.botv2.Main in project MC-Server-Bot by polarbub.

the class config method readConfig.

public static void readConfig() throws IOException, InterruptedException, LoginException {
    YamlMapping config = Yaml.createYamlInput(new File(Main.runTimeArgs[0])).readYamlMapping();
    YamlMapping backupConfig = config.yamlMapping("BACKUP");
    YamlMapping discordConfig = config.yamlMapping("DISCORD_BOT");
    YamlMapping minecraftConfig = config.yamlMapping("MC_SERVER");
    permissionsConfig = config.yamlMapping("PERMISSIONS");
    serverArgs.clear();
    YamlSequence startCMD = minecraftConfig.yamlSequence("startCMD");
    if (System.getProperty("os.name").equals("Linux")) {
        StringBuilder s = new StringBuilder();
        int i = 0;
        for (YamlNode node : startCMD) {
            s.append(startCMD.string(i));
            s.append(" ");
            i++;
        }
        s.delete(s.length() - 1, s.length());
        serverArgs.add(s.toString());
    } else {
        int i = 0;
        for (YamlNode node : startCMD) {
            serverArgs.add(startCMD.string(i));
            i++;
        }
    }
    webHookURL = new URL(discordConfig.string("chatBridgeWebHookURL"));
    // Get the channel IDs
    token = discordConfig.string("TOKEN");
    pre = discordConfig.string("PREFIX");
    // init discord jda
    bot = JDABuilder.createLight(token, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES).addEventListeners(new Main()).build();
    while (!String.valueOf(bot.getStatus()).equals("CONNECTED")) {
        // wait for connected
        Thread.sleep(10);
    }
    Thread.sleep(1000);
    consoleChannel = bot.getTextChannelById(discordConfig.longNumber("CONSOLE_CHANNEL"));
    chatBridgeChannel = bot.getTextChannelById(discordConfig.longNumber("CHAT_CHANNEL"));
    test = discordConfig.string("test");
    // Add all normal regexs to list
    normalPatterns.clear();
    YamlSequence normalRegexes = minecraftConfig.yamlSequence("normalRegexes");
    for (YamlNode regexNode : normalRegexes) {
        net.polarbub.botv2.config.normalPattern NormalPattern = new normalPattern();
        YamlMapping regexSequence = regexNode.asMapping().yamlMapping("regex");
        NormalPattern.pattern = Pattern.compile(regexSequence.string("string"));
        NormalPattern.dataGroup = regexSequence.integer("contentGroup");
        normalPatterns.add(NormalPattern);
    }
    // Add all named regexs to list
    namedPatterns.clear();
    YamlSequence namedRegexs = minecraftConfig.yamlSequence("webHookRegexes");
    for (YamlNode regexNode : namedRegexs) {
        net.polarbub.botv2.config.namedPattern NamedPattern = new namedPattern();
        YamlMapping regexSequence = regexNode.asMapping().yamlMapping("regex");
        NamedPattern.pattern = Pattern.compile(regexSequence.string("string"));
        if (regexSequence.string("prefix").equals("\"\"")) {
            NamedPattern.prefix = "";
        } else {
            NamedPattern.prefix = regexSequence.string("prefix");
        }
        NamedPattern.dataGroup = regexSequence.integer("contentGroup");
        NamedPattern.nameGroup = regexSequence.integer("nameGroup");
        namedPatterns.add(NamedPattern);
    }
    startPattern = Pattern.compile(minecraftConfig.string("startRegex"));
    startPattern = Pattern.compile("^\\[\\d\\d:\\d\\d:\\d\\d] \\[Server thread\\/INFO\\]: Done \\(\\d+.\\d+s\\)! For help, type \"help");
    pingPort = minecraftConfig.integer("pingPort");
    queryPort = minecraftConfig.integer("queryPort");
    realIP = minecraftConfig.string("realIP");
    showIP = minecraftConfig.string("showIP");
    backupTime = backupConfig.longNumber("backup_time");
    if (backupTime < 0)
        throw new IllegalArgumentException("Backup Time cannon be less than zero");
    backupWarn = backupConfig.longNumber("backup_alert");
    serverDir = backupConfig.string("gitDirectory");
    gitsavereturnPattern = Pattern.compile(backupConfig.string("gitsavereturnRegex"));
}
Also used : URL(java.net.URL) YamlSequence(com.amihaiemil.eoyaml.YamlSequence) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) File(java.io.File) Main(net.polarbub.botv2.Main)

Aggregations

Main (com.icodici.universa.node2.Main)2 File (java.io.File)2 IOException (java.io.IOException)2 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)1 YamlNode (com.amihaiemil.eoyaml.YamlNode)1 YamlSequence (com.amihaiemil.eoyaml.YamlSequence)1 KeyAddress (com.icodici.crypto.KeyAddress)1 java.io (java.io)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Main (net.polarbub.botv2.Main)1 net.polarbub.botv2.server.runProg.runProgString (net.polarbub.botv2.server.runProg.runProgString)1 org.apache.poi.ss.usermodel (org.apache.poi.ss.usermodel)1 AreaReference (org.apache.poi.ss.util.AreaReference)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 CellReference (org.apache.poi.ss.util.CellReference)1 org.apache.poi.xssf.usermodel (org.apache.poi.xssf.usermodel)1 org.openxmlformats.schemas.spreadsheetml.x2006.main (org.openxmlformats.schemas.spreadsheetml.x2006.main)1