diff --git a/build.gradle b/build.gradle index 966e9a1..dac17f7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,13 +5,11 @@ plugins { group 'BOT' -version '10.1' +version '1.0.0' def jdaVersion = '4.2.0_225' -def jdautilitiesVersion = '2.1.5' def jsonsimpleVersion = '1.1.1' def jodatimeVersion = '2.10.6' -def jdbcVersion = '8.0.19' def self4JVersion = '1.7.30' def log4jVersion = '2.13.3' def JSON = '4.12.0' @@ -26,10 +24,8 @@ repositories { dependencies { compile "net.dv8tion:JDA:$jdaVersion" -// compile "com.jagrosh:jda-utilities:$jdautilitiesVersion" compile group: 'com.googlecode.json-simple', name: 'json-simple', version: jsonsimpleVersion compile group: 'joda-time', name: 'joda-time', version: jodatimeVersion -// compile group: 'mysql', name: 'mysql-connector-java', version: jdbcVersion compile group: 'org.slf4j', name: 'slf4j-api', version: self4JVersion compile group: 'org.slf4j', name: 'slf4j-log4j12', version: self4JVersion compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4jVersion diff --git a/src/main/java/IO/Bash.java b/src/main/java/IO/Bash.java deleted file mode 100644 index 8a9ec82..0000000 --- a/src/main/java/IO/Bash.java +++ /dev/null @@ -1,22 +0,0 @@ -package IO; - -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class Bash { - - public static void runBash(String command){ - - LoggerFactory.getLogger(Bash.class).debug("run bash command: " + command); - - String[] cmd = new String[]{"/bin/sh", command}; - try { - Runtime.getRuntime().exec(cmd); - } catch (IOException e){ - LoggerFactory.getLogger(Bash.class).error(e.getMessage()); - } - - - } -} diff --git a/src/main/java/IO/MySQL.java b/src/main/java/IO/MySQL.java deleted file mode 100644 index 2a10643..0000000 --- a/src/main/java/IO/MySQL.java +++ /dev/null @@ -1,204 +0,0 @@ -package IO; - -import org.joda.time.Period; -import org.json.simple.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.sql.*; -import java.util.Timer; -import java.util.TimerTask; - -public class MySQL { - - private final Logger logger = LoggerFactory.getLogger(MySQL.class); - - //////////////////////Variablen////////////////////////// - private Connection conn; - private Statement stmt; - private ResultSet something; - private String driverName = "com.mysql.cj.jdbc.Driver"; - private JSONObject config; - - /** - * Creates connection to Database - * - * Inspired by https://www.vogella.com/tutorials/MySQLJava/article.html - * - * @param config Bot config for data - */ - public MySQL(JSONObject config) { - this.config = config; - - try { - //load driver / config driver - logger.debug("Lade DB Treiber"); - Class driver_class = Class.forName(driverName); - Driver dbdriver = (Driver) driver_class.newInstance(); - DriverManager.registerDriver(dbdriver); - - try { - logger.debug("Create connection to Database"); - //Create connection - conn = DriverManager.getConnection("jdbc:" + config.get("SQLServerUrl") + config.get("SQLDBNname") + config.get("SQLDBparameter"), (String) config.get("SQLDBUser"), (String) config.get("SQLDBPassword")); - } catch (SQLException e) { - logger.error(e.getMessage()); - } - } catch (Exception e){ - logger.error(e.getMessage()); - } - - // GetS selfchek going - Timer timer = new Timer(); - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - stmt = conn.createStatement(); - - //SQL Command - something = stmt.executeQuery("SELECT 1 FROM Guild;"); - } catch (Exception e){ - logger.error("Database is down! Reconnect!"); - reload(); - } - } - }, - 1000L, 1000*60*15L); - } - - /** - * prepare, execute a SQL query and returns result - * - * @param pInput SQL Query as String - * @return ResultSet Result of query as ResultSet - */ - public ResultSet mySQLDataQuery(String pInput){ - logger.debug("execute SQLQuerry: " + pInput); - - try { - //Create statement - stmt = conn.createStatement(); - - //SQL Command - something = stmt.executeQuery(pInput); - } catch (SQLNonTransientConnectionException ex) { - logger.error(ex.getMessage()); - - //Something happend reload connection - reload(); - //redo querry - //return mySQLDataQuery(pInput); - - } catch (SQLException e){ - logger.error(e.getMessage()); - } - return something; - } - - /** - * prepare, execute a SQLUpdate query and returns result - * checks for simple SQL injection - * - * @param pInput SQL Query Blueprint as String - * @param pParameter Data for Blueprint - * @return key ID of created data INDEX - */ - public int mySQLDataUpdate(String pInput, String[] pParameter){ - logger.debug("execute SQLUpdate:" + pInput); - int key = -1; - - PreparedStatement stmt = null; - - try { - conn.setAutoCommit(false); - - //set Blueprint - stmt = conn.prepareStatement(pInput); - - // Replace Wildcards with Data - for(int i = 0; i < pParameter.length; i++){ - - stmt.setString(i+1, pParameter[i]); - } - - //logger.debug("Execute update"); - stmt.executeUpdate(); - conn.commit(); - - //get generated INDEX IDs - conn.setAutoCommit(false); - Statement stmt2 = null; - stmt2 = conn.createStatement(); - ResultSet tmp = stmt2.executeQuery("SELECT LAST_INSERT_ID();"); - - if(tmp.next()){ - key = Integer.parseInt(tmp.getString(1)); - } - - } catch (SQLNonTransientConnectionException ex) { - logger.error(ex.getMessage()); - //Something happend reload connection - reload(); - //redo querry - //return mySQLDataUpdate(pInput, pParameter); - - } catch (SQLException e ) { - logger.error(e.getMessage()); - } - - return key; - } - - /** - * closes current connection and reload it - */ - private void reload(){ - cleanUp(); - - try { - //load driver / config driver - logger.debug("Lade DB Treiber"); - Class driver_class = Class.forName(driverName); - Driver dbdriver = (Driver) driver_class.newInstance(); - DriverManager.registerDriver(dbdriver); - - try { - logger.debug("Create connection to Database"); - //Create connection - conn = DriverManager.getConnection("jdbc:" + config.get("SQLServerUrl") + config.get("SQLDBNname") + config.get("SQLDBparameter"), (String) config.get("SQLDBUser"), (String) config.get("SQLDBPassword")); - } catch (SQLException e) { - logger.error(e.getMessage()); - } - } catch (Exception e){ - logger.error(e.getMessage()); - } - } - - /** - * Inspired by https://www.vogella.com/tutorials/MySQLJava/article.html - * - * CleanUp of SQL connection - */ - public void cleanUp(){ - logger.debug("Close database connection"); - try { - if (something != null) - something.close(); - - if (stmt != null) - stmt.close(); - - conn.setAutoCommit(true); - - if (conn != null) - conn.close(); - - something = null; - stmt = null; - conn = null; - } catch(SQLException e){ - e.printStackTrace(); - } - } -} \ No newline at end of file