package com.robothand.highqualitybot;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Hashtable;
import java.util.Scanner;

/**
 * Config.java
 *
 * Reads in properties from a specified configuration file, and provides access to the values.
 */
public class Config {
    private final File configFile;

    public String TOKEN;
    public String PREFIX;


    public Config(String path) throws FileNotFoundException {
        // set default values
        PREFIX = ".";

        configFile = new File(path);

        Scanner s = new Scanner(configFile);

        while (s.hasNextLine()) {
            String[] split = s.nextLine().split("=");
            String key, value;

            if (split.length < 2 || split[0].trim().startsWith("#")) {
                continue;
            }

            key = split[0].trim();
            value = split[1].trim();

            // place the property if it is known
            switch (key) {
                case "token":
                    TOKEN = value;
                    break;

                case "prefix":
                    PREFIX = value;
                    break;

                default:
                    System.out.println("Info: Unknown property \"" + key + "\", ignoring.");
            }

            // Check for values that would need user input
            if (TOKEN == null) {
                Scanner c = new Scanner(System.in);

                System.out.println("Warning: OAuth token not set in config. Please enter your token below:");
                System.out.print("> ");
                TOKEN = c.nextLine();

                System.out.println("Token set. Recommend setting in config file for future runs.");
            }
        }
    }
}

@@ -293,44 +293,8 @@
 g %7B%0A
-    private final File configFile;%0A%0A
     
@@ -469,168 +469,93 @@
     
-configFile = new File(path);%0A%0A        Scanner s = new Scanner(configFile);%0A%0A        while (s.hasNextLine()) %7B%0A            String%5B%5D split = s.nextLine().split(%22=
+// read config.cfg%0A        Hashtable%3CString,String%3E table = Utils.readCFG(%22config.cfg
 %22);%0A
@@ -562,20 +562,21 @@
         
-   
- 
+for (
 String k
@@ -581,199 +581,69 @@
  key
-, value;%0A%0A            if (split.length %3C 2 %7C%7C split%5B0%5D.trim().startsWith(%22#%22)) %7B%0A                continue;%0A            %7D%0A%0A            key = split%5B0%5D.trim();%0A            value = split%5B1%5D.trim(
+ : table.keySet()) %7B%0A            String value = table.get(key
 );%0A%0A
@@ -1038,21 +1038,27 @@
       %7D%0A
-%0A
+   
     
+ %7D%0A%0A
         
@@ -1104,20 +1104,16 @@
 r input%0A
-    
         
@@ -1145,20 +1145,16 @@
         
-    
 Scanner 
@@ -1178,28 +1178,24 @@
 ystem.in);%0A%0A
-    
             
@@ -1292,36 +1292,32 @@
 %22);%0A            
-   
- 
 System.out.print
@@ -1328,36 +1328,32 @@
 %22);%0A            
-    
 TOKEN = c.nextLi
@@ -1355,28 +1355,24 @@
 extLine();%0A%0A
-    
             
@@ -1451,38 +1451,24 @@
 re runs.%22);%0A
-            %7D%0A
         %7D%0A  

update Config to use readCFG() from Utils