anpasssung DB Verbindung und Ini ausgabe

This commit is contained in:
Sebastian Zeidler
2019-08-09 17:13:55 +02:00
parent 2b72562170
commit 2f91ce6e4f
8 changed files with 95 additions and 6 deletions

1
build.gradle Normal file → Executable file
View File

@ -25,6 +25,7 @@ repositories {
dependencies {
compile "net.dv8tion:JDA:$jdaVersion"
compile "org.slf4j:slf4j-simple:1.6.1"
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
}
repositories {

8
shadowrun.cfg Normal file → Executable file
View File

@ -14,3 +14,11 @@ en.error2=\ I don't understanding %command%
en.noNegativ=\ there must not be a negative throw
en.language= I write now English, maybe
en.emptyCommand=\ The %command% command need a Value
db.on=true
db.typ=mysql
db.host=localhost
db.port=3306
db.database=shadowrun_log
db.name=root
db.pw=root

View File

@ -34,7 +34,7 @@ public class base {
try {
input = new FileInputStream("shadowrun.cfg");
config.load(input);
if(!config.containsKey("db.typ")) {
if(!config.containsKey("db.typ") || (config.containsKey("db.on") && !config.getProperty("db.on").equals("true"))) {
active = false;
}

View File

@ -4,6 +4,8 @@ import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class db_connect extends DB.base {
@ -50,7 +52,41 @@ public class db_connect extends DB.base {
close();
}
/**
*
* @param channelId
* @return
*/
public Map<String, String> getChannelSettings(String channelId) {
Map<String, String> result = new HashMap<>();
result.put("lang", "de");
if(!isActive()) {
result.put("sqlActive", "0");
return result;
}
open();
try {
conn = getConn();
String SQL_SELECT = "SELECT * FROM shadowrun_channelSettings where channelId = ?";
PreparedStatement preparedStatement = conn.prepareStatement(SQL_SELECT);
preparedStatement.setString(1, channelId);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
result.remove("lang");
result.put("lang", rs.getString("lang"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
close();
return result;
}
}
/*
@ -65,5 +101,15 @@ public class db_connect extends DB.base {
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
;
CREATE TABLE `shadowrun_log` (
`id` INT NOT NULL AUTO_INCREMENT,
`zeitstempel` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`channelId` VARCHAR(50) NOT NULL DEFAULT '0',
`lang` VARCHAR(255) NOT NULL DEFAULT 'de'
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
;
*/

View File

@ -21,6 +21,7 @@ public class dice extends ListenerAdapter {
private String prefixIni;
private String prefixZitat;
private String prefixTest;
private String prefixCId;
private language langDe = new language("de");
private language langEn = new language("en");
@ -38,6 +39,7 @@ public class dice extends ListenerAdapter {
this.prefixIni = "/ini";
this.prefixTest = "/rollTest";
this.prefixZitat = "/zitat";
this.prefixCId = "/cid";
this.db = new db_connect();
}
@ -46,7 +48,8 @@ public class dice extends ListenerAdapter {
if ((!event.getMessage().getContentRaw().startsWith(this.prefixSr)
&& !event.getMessage().getContentRaw().startsWith(this.prefixIni)
&& !event.getMessage().getContentRaw().startsWith(this.prefixZitat)
&& !event.getMessage().getContentRaw().startsWith(this.prefixTest))
&& !event.getMessage().getContentRaw().startsWith(this.prefixTest)
&& !event.getMessage().getContentRaw().startsWith(this.prefixCId))
|| (event.getChannelType() != ChannelType.TEXT && event.getChannelType() != ChannelType.PRIVATE)) {
return;
}
@ -78,6 +81,8 @@ public class dice extends ListenerAdapter {
this.rollTest(event);
else if (event.getMessage().getContentRaw().startsWith(this.prefixZitat))
this.zitat(event);
else if (event.getMessage().getContentRaw().startsWith(this.prefixCId))
this.cid(event);
}
}
@ -448,6 +453,9 @@ public class dice extends ListenerAdapter {
int dice = new Random().nextInt(600);
event.getChannel().sendMessage(quotes[dice%6]).queue();
}
private void cid(MessageReceivedEvent event) {
event.getChannel().sendMessage(getAsMention(event) + " " + event.getChannel().getId()).queue();
}
private String getEffectiveName(MessageReceivedEvent event) {
if(event.getMember() == null) {

View File

@ -139,19 +139,33 @@ public class shadowrun implements Runnable{
EmbedBuilder outputBox = new EmbedBuilder();
outputBox.setColor(Color.BLACK);
outputBox.setTitle("Initiative:");
String channelId = "542202034330271759";
while (in.hasNextLine()) {
message = in.nextLine().trim();
if(message.trim().equals("FIN")) {
break;
}
String[] msgParts = message.split("\\|",3);
//jda.getUserById(msgParts[0]).getName();
if(message.startsWith("out:")) {
String[] msgParts = message.split(":", 2);
if(!msgParts[1].equals(""))
channelId = msgParts[1];
}
else {
outputBox.addField( msgParts[0], msgParts[1], false);
String[] msgParts = message.split("\\|");
//jda.getUserById(msgParts[0]).getName();
StringBuilder iniTicks = new StringBuilder();
iniTicks.append(msgParts[1]);
for(int i = 2; i < msgParts.length; i++) {
iniTicks.append("\t - \t ");
iniTicks.append(msgParts[i]);
}
outputBox.addField(msgParts[0], iniTicks.toString(), false);
}
out.println("ACKSend");
}
jda.getTextChannelById("542202034330271759").sendMessage(outputBox.build()).queue();
jda.getTextChannelById(channelId).sendMessage(outputBox.build()).queue();
}
}
}

View File

@ -0,0 +1,4 @@
package core;
public class Controller {
}

8
src/main/java/core/sample.fxml Executable file
View File

@ -0,0 +1,8 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="core.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>