grundlegente Umstellung + Earthdawn Implemntation

This commit is contained in:
Ocame
2025-07-06 16:22:48 +02:00
parent 10c8c9900f
commit e2b9694e09
48 changed files with 1488 additions and 638 deletions

View File

@ -0,0 +1,191 @@
package de.ocame.wuerfelbot.Shadowrun;
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 de.ocame.wuerfelbot.DB.base {
Connection conn;
public db_connect() {
if(!isActive())
return;
open();
try {
conn = getConn();
ResultSet rs = conn.prepareStatement("show tables like \"shadowrun_log\"").executeQuery();
while (rs.next()) {
String s = rs.getString(1);
System.out.println(s);
}
}
catch (SQLException e) {
e.printStackTrace();
}
close();
}
public void insertDice(String userName, String userId, String command, String result, String kanal, long MsgID, String wurfdaten) {
if(!isActive())
return;
open();
try {
conn = getConn();
String SQL_INSERT = "INSERT INTO shadowrun_log (benutzer, benutzerId, wurf, ergebnis, kanal, msgId, wurfdaten) VALUES (?,?,?,?,?,?,?)";
PreparedStatement preparedStatement = conn.prepareStatement(SQL_INSERT);
preparedStatement.setString(1, userName);
preparedStatement.setString(2, userId);
preparedStatement.setString(3, command);
preparedStatement.setString(4, result);
preparedStatement.setString(5, kanal);
preparedStatement.setLong(6, MsgID);
preparedStatement.setString(7, wurfdaten);
preparedStatement.executeUpdate();
}
catch (SQLException e) {
e.printStackTrace();
}
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;
}
public void setChannelSettings(String channelId, String Sprache, String ServerId, String Kanalname) {
if(!isActive()) {
return;
}
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();
if (rs.next()) {
String SQL_Update = "UPDATE shadowrun_channelSettings SET lang = ? WHERE channelId = ?";
preparedStatement = conn.prepareStatement(SQL_Update);
preparedStatement.setString(1, Sprache);
preparedStatement.setString(2, channelId);
preparedStatement.executeUpdate();
}
else {
String SQL_INSERT = "INSERT INTO shadowrun_channelSettings (channelId, lang, serverId, kanalname) VALUES (?,?,?,?)";
preparedStatement = conn.prepareStatement(SQL_INSERT);
preparedStatement.setString(1, channelId);
preparedStatement.setString(2, Sprache);
preparedStatement.setString(3, ServerId);
preparedStatement.setString(4, Kanalname);
preparedStatement.executeUpdate();
}
close();
return;
}
catch (SQLException e) {
e.printStackTrace();
}
close();
}
public Map<String, String> getMesssage(Long MsgId) {
Map<String, String> result = new HashMap<>();
if(!isActive()) {
return result;
}
result.put("lang", "de");
open();
try {
conn = getConn();
String SQL_SELECT = "SELECT * FROM shadowrun_log where MsgID = ?";
PreparedStatement preparedStatement = conn.prepareStatement(SQL_SELECT);
preparedStatement.setLong(1, MsgId);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
result.put("benutzerId", rs.getString("benutzerId"));
result.put("wurfdaten", rs.getString("wurfdaten"));
}
}
catch (SQLException e) {
e.printStackTrace();
}
close();
return result;
}
}
/*
CREATE TABLE `shadowrun_log` (
`id` INT NOT NULL AUTO_INCREMENT,
`zeitstempel` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`wurf` VARCHAR(255) NOT NULL DEFAULT '0',
`ergebnis` VARCHAR(255) NOT NULL DEFAULT '0',
`benutzer` VARCHAR(255) NOT NULL DEFAULT '0',
`benutzerId` VARCHAR(255) NOT NULL DEFAULT '0',
`kanal` VARCHAR(50) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
;
CREATE TABLE `shadowrun_channelSettings` (
`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',
`serverId` VARCHAR(255) NULL,
`kanalname` VARCHAR(255) NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
;
*/

View File

@ -0,0 +1,632 @@
package de.ocame.wuerfelbot.Shadowrun;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import java.awt.*;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class dice extends ListenerAdapter {
private final String prefixSr;
private final String prefixIni;
private final String prefixZitat;
private final String prefixTest;
private final String prefixCId;
private final language langDe = new language("de");
private final language langEn = new language("en");
private final help helpDe = new help("de");
private final help helpEn = new help("En");
private language activLang;
private help activHelp;
private final db_connect db;
private final Map<String, String> channelList = new HashMap<>();
public dice() {
this.prefixSr = "/sr";
this.prefixIni = "/ini";
this.prefixTest = "/rollTest";
this.prefixZitat = "/zitat";
this.prefixCId = "/cid";
helpDe.add("Alle Befehle können in einen Channel geschrieben werden oder per Direkt Nachricht gesender werden");
helpDe.add(this.prefixSr + "Zahl", "Würfelt Zahl x W6. Gewürfelte 5. und 6. Werden als Erfolge gezählt, 1. als Misserfolge.\n" +
"Erreicht oder übersteigt die Anzhal der 1. die hälfte der gewürfelten Würfel, zählt dies als ein Patzer. Gibt es mind. 1 Erfolg wird die Markierung der Ausgabe Gelb." +
"wird aber kein Erfolg gewürfelt zählt dies als Kritischer Patzer und die Markierung wird Rot **Wichtig: Vor- und Nachteile die Einfluss auf die Patzer Changse haben werden nicht berücksichtigt");
helpDe.add(this.prefixSr + "+ Zahl", "Gleich wie bei " + this.prefixSr + "Zahl. Mit dem Unterschied dass alle gewürfelten 6. ein zuzätlichen Würfel generien.");
helpDe.add(this.prefixSr + " Zahl_1 + Zahl_2", "Würfelt Zahl_2 x W6 und addiert Zahl_1 hinzu, um die Initative zu bestimmen");
helpDe.add(this.prefixIni + " Zahl_1 + Zahl_2", "Synonym für " + this.prefixSr + " Zahl_1 + Zahl_2");
helpDe.add(this.prefixCId, "Gibt aktuelle Channel ID zurück");
this.db = new db_connect();
}
@Override
public void onMessageReceived(MessageReceivedEvent event) {
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.prefixCId))
|| (event.getChannelType() != ChannelType.TEXT && event.getChannelType() != ChannelType.PRIVATE)) {
return;
}
if(!channelList.containsKey(event.getChannel().getId())) {
Map<String, String> Einstellungen = db.getChannelSettings(event.getChannel().getId());
channelList.put(event.getChannel().getId(), Einstellungen.get("lang"));
}
switch (channelList.get(event.getChannel().getId())) {
case "de":
activLang = langDe;
break;
case "en":
activLang = langEn;
break;
default:
activLang = langDe;
}
User author = event.getAuthor();
if (event.getMessage().getContentRaw().startsWith(this.prefixSr))
this.srroll(event);
else if (event.getMessage().getContentRaw().startsWith(this.prefixIni))
this.ini(event);
else if (event.getMessage().getContentRaw().startsWith(this.prefixTest))
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);
}
/*@Override
public void onMessageReactionAdd(MessageReactionAddEvent event) {
User user = event.getUser();
if(!channelList.containsKey(event.getChannel().getId())) {
Map<String, String> Einstellungen = db.getChannelSettings(event.getChannel().getId());
channelList.put(event.getChannel().getId(), Einstellungen.get("lang").toString());
}
switch (channelList.get(event.getChannel().getId())) {
case "de":
activLang = langDe;
break;
case "en":
activLang = langEn;
break;
default:
activLang = langDe;
}
if (!user.isBot()) {
if(event.getReactionEmote().getId().equals("517528156014510111")) { // SR Reaktion - reroll
reaktionRerollEdge(event);
}
else if(event.getReactionEmote().getId().equals("517545127376322596")) { // ausgedehnte probe
extensionroll(event);
}
}
}*/
/**
* rolltest
*
* @param event JDA Event
*/
private void rollTest(MessageReceivedEvent event) {
EmbedBuilder test = new EmbedBuilder();
test.setTitle("Das ist ein Test");
test.setColor(Color.red);
test.setDescription("Text " + getAsMention(event));
int[] verteilung = new int[6];
int[] verteilung2 = new int[6];
int[] verteilung3 = new int[6];
int dice1, dice2, dice3;
try {
String[] MsgParts_exl_Mention = event.getMessage().getContentRaw().split(" ");
int rounds = Integer.parseInt(MsgParts_exl_Mention[1]);
if(rounds <= 0) {
event.getChannel().sendMessage("Nope").queue();
return;
}
for(int i = 0; i < rounds; i++) {
dice1 = new Random().nextInt(6);
dice2 = new SecureRandom().nextInt(6);
//dice3 = new ThreadLocalRandom().current().nextInt(6);
dice3 = ThreadLocalRandom.current().nextInt(0, 6);
verteilung[dice1]++;
verteilung2[dice2]++;
verteilung3[dice3]++;
}
for(int i = 0; i < 6; i++) {
float pro = verteilung[i]*100f/rounds;
test.addField(Integer.toString(i+1), verteilung[i] + " - " + String.format("%.2f", pro) + "%", true);
}
test.addBlankField(false);
for(int i = 0; i < 6; i++) {
float pro = verteilung2[i]*100f/rounds;
test.addField(Integer.toString(i+1), verteilung2[i] + " - " + String.format("%.2f", pro) + "%", true);
}
test.addBlankField(false);
for(int i = 0; i < 6; i++) {
float pro = verteilung3[i]*100f/rounds;
test.addField(Integer.toString(i+1), verteilung3[i] + " - " + String.format("%.2f", pro) + "%", true);
}
event.getChannel().sendMessageEmbeds(test.build()).queue();
}
catch (NumberFormatException e) {
event.getChannel().sendMessage("Nope").queue();
}
catch (Exception e) {
System.out.println("problem: " + e.getMessage());
}
}
/**
* rolltest
*
* @param event JDA Event
*/
private void srroll(MessageReceivedEvent event) {
int numberOfDice = 1;
int diceart = 6;
boolean edge = false;
try {
// Prüfen ob Edge wurf
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+"+") || event.getMessage().getContentRaw().startsWith(this.prefixSr+" +")) {
edge = true;
}
// korrikiert Edge eingabe von /sr + zu /sr+
String ContentRaw = event.getMessage().getContentRaw();
if(event.getMessage().getContentRaw().startsWith(this.prefixSr+" +")) {
ContentRaw = ContentRaw.replace(this.prefixSr+" +", this.prefixSr+"+ ").replace(" ", " ");
}
// Prüfen ob Leerer Command gesendet wird
String[] MsgParts = ContentRaw.split(" ", 2);
if(MsgParts.length < 2) {
String message = activLang.emptyCommand;
message = message.replace("%command%", this.prefixSr);
event.getChannel().sendMessage(getAsMention(event) + message).queue();
return;
}
if(MsgParts[1].contains("+")) {
this.ini(event);
return;
}
if(MsgParts[1].trim().matches(".*[^0-9].*")) { // es wurden andere zeichen als Zahlen gefunden
if(MsgParts[1].trim().equalsIgnoreCase("de")) {
activLang = langDe;
channelList.put(event.getChannel().getId(), "de");
event.getChannel().sendMessage(getAsMention(event) + activLang.language).queue();
db.setChannelSettings(event.getChannel().getId(), "de", event.getGuild().getId(), event.getChannel().getName());
return;
}
else if(MsgParts[1].trim().equalsIgnoreCase("en")) {
activLang = langEn;
channelList.put(event.getChannel().getId(), "en");
event.getChannel().sendMessage(getAsMention(event) + activLang.language).queue();
db.setChannelSettings(event.getChannel().getId(), "en", event.getGuild().getId(), event.getChannel().getName());
return;
}
if(MsgParts[1].trim().toLowerCase().replace(" ", "").matches("([0-9]*)[dw]([0-9].*)")) { // format besteh aus (Zahlen)d(Zahlen) oder (Zahlen)w(Zahlen)
String[] diceInterpreter = MsgParts[1].trim().toLowerCase().replace(" ", "").split("[wd]");
try {
diceart = Integer.parseInt(diceInterpreter[1]);
numberOfDice = Integer.parseInt(diceInterpreter[0]);
}
catch (NumberFormatException e) {
String message = activLang.error;
message = message.replace("%command%", MsgParts[1].trim().toLowerCase());
event.getChannel().sendMessage(getAsMention(event) + message).queue();
return;
}
}
else {
String message = activLang.error;
message = message.replace("%command%", MsgParts[1].trim());
event.getChannel().sendMessage(getAsMention(event) + message).queue();
return;
}
}
else {
try {
numberOfDice = Integer.parseInt(MsgParts[1].trim().replace(" ", ""));
}
catch (NumberFormatException e) {
String message = activLang.error;
message = message.replace("%command%", MsgParts[1].trim());
event.getChannel().sendMessage(getAsMention(event) + message).queue();
return;
}
}
srrollOut(numberOfDice, diceart, edge, event.getChannel(), event.getAuthor(), getEffectiveName(event), event.getMessage().getContentRaw(), -1, 0, event.getJDA());
}
catch (NumberFormatException e) {
event.getChannel().sendMessage("Nope").queue();
}
catch (Exception e) {
System.out.println("problem: " + e.getMessage());
}
}
/**
* srrollOut
*
* @param numberOfDice
* @param diceart
* @param edge
* @param channel
* @param user
* @param effectiveName
* @param inputMessage
* @param hitBasis
* @param type
*/
private void srrollOut(int numberOfDice, int diceart, boolean edge, MessageChannel channel, User user, String effectiveName, String inputMessage, int hitBasis, int type, JDA jda) {
EmbedBuilder outputBox = new EmbedBuilder();
int[] verteilung = new int[diceart];
int dice1;
StringBuilder result = new StringBuilder();
StringBuilder rollString = new StringBuilder();
int hits = 0;
boolean glitches = false;
try {
if(numberOfDice <= 0) {
String message = activLang.noNegativ;
channel.sendMessage(user.getAsMention() + message).queue();
return;
}
int bonusEdegeDice = 0;
int dicecorrection = hitBasis < 0 ? 0 : hitBasis;
for(int i = 0; i < numberOfDice+bonusEdegeDice; i++) {
dice1 = new Random().nextInt(diceart);
if(edge && dice1 == 5)
bonusEdegeDice++;
if(dice1 >= 4) {
hits++;
}
verteilung[dice1]++;
if((dice1 >= 4) || (dice1 == 0))
result.append("**").append(dice1+1).append("**");
else
result.append(dice1+1);
result.append(" ");
}
if (verteilung[0] > (numberOfDice+bonusEdegeDice+dicecorrection)/2f) { // Patzer nur bei über er Hälfte an 1er
glitches = true;
}
if(hits+dicecorrection == 0 && !glitches) { // kein Erfolg, kein Patzer
outputBox.setColor(Color.gray);
}
else if(hits+dicecorrection == 0 && glitches) { // kritischer Patzer
outputBox.setColor(Color.red);
}
else if(glitches) { // Patzer
outputBox.setColor(Color.yellow);
}
else { // Erfolg
outputBox.setColor(Color.green);
}
String addition = "";
if(bonusEdegeDice > 0) {
addition = " + " + bonusEdegeDice + activLang.dice + diceart;
}
String message = "";
if(type == 1) {
message = activLang.resultText;
//%numberOfDice%%dice%%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
message = message.replace("%numberOfDice%", String.valueOf(numberOfDice)).replace("%diceart%", String.valueOf(diceart)).replace("%EdgeDice%", addition).replace("%hits%", hits + "\t Gesamt: " + (hits + hitBasis)).replace("%oneHits%", String.valueOf(verteilung[0]));
outputBox.setTitle(effectiveName + " Edgereroll " + message);
}
if(type == 2) {
message = activLang.resultTextExtent;
//%numberOfDice%%dice%%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
message = message.replace("%numberOfDice%", String.valueOf(numberOfDice)).replace("%diceart%", String.valueOf(diceart)).replace("%EdgeDice%", addition).replace("%hits%", hits + "\t Gesamt: " + (hits + hitBasis)).replace("%oneHits%", String.valueOf(verteilung[0]));
outputBox.setTitle(effectiveName + " Ausgedehnt " + message);
}
else {
message = activLang.resultText;
//%numberOfDice%%dice%%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
message = message.replace("%numberOfDice%", String.valueOf(numberOfDice)).replace("%diceart%", String.valueOf(diceart)).replace("%EdgeDice%", addition).replace("%hits%", String.valueOf(hits)).replace("%oneHits%", String.valueOf(verteilung[0]));
outputBox.setTitle(effectiveName + message);
}
outputBox.setDescription("(" + result.toString().trim() + ")");
//outputBox.appendDescription("\r" + jda.getEmoteById("517528156014510111").getAsMention() + " Edge reroll");
//outputBox.appendDescription("\r" + jda.getEmoteById("517545127376322596").getAsMention() + " Ausgedehnte Probe");
//JDA::getEmoteById();
for(int i = 0; i < diceart; i++) {
float pro = verteilung[i]*100f/numberOfDice;
//outputBox.addField(Integer.toString(i+1), Integer.toString(verteilung[i]) + " - " + String.format("%.2f", pro) + "%", true);
}
rollString.append(numberOfDice).append("|").append(hits+dicecorrection).append("|").append(verteilung[0]);
//event.getChannel().sendMessage(outputBox.build()).queue();
long[] messageId = new long[1];
boolean finalEdge = edge;
String finalRollData = rollString.toString();
channel.sendMessageEmbeds(outputBox.build()).queue(message1 -> {
if(!finalEdge && type == 0) {
//message1.addReaction("sr:517528156014510111").queue();
}
if(!finalEdge && (type == 0 || type == 2)) {
//message1.addReaction("test:517545127376322596").queue();
}
messageId[0] = message1.getIdLong();
if(channel.getType() == ChannelType.PRIVATE) {
db.insertDice(user.getName(), user.getId(), inputMessage, result.toString().trim(), channel.getId(), messageId[0], finalRollData);
}
else {
db.insertDice(user.getName(), user.getId(), inputMessage, result.toString().trim(), channel.getId(), messageId[0], finalRollData);
}
});
}
catch (NumberFormatException e) {
channel.sendMessage("Nope").queue();
}
catch (Exception e) {
System.out.println("problem: " + e.getMessage());
}
}
private void ini(MessageReceivedEvent event) {
EmbedBuilder outputBox = new EmbedBuilder();
int dice1;
int numberOfDice = 1;
int diceart = 6;
int iniBase = 0;
int ini = 0;
StringBuilder result = new StringBuilder();
try {
String[] MsgParts = event.getMessage().getContentRaw().split(" ", 2);
if(MsgParts.length < 2) { // Leerer Befehl
String message = activLang.emptyCommand;
message = message.replace("%command%", this.prefixIni);
event.getChannel().sendMessage(getAsMention(event) + message).queue();
return;
}
if(MsgParts[1].trim().matches(".*[^0-9].*")) { // es wurden andere zeichen als Zahlen gefunden
if(MsgParts[1].trim().equalsIgnoreCase("de")) {
activLang = langDe;
channelList.put(event.getChannel().getId(), "de");
event.getChannel().sendMessage(getAsMention(event) + activLang.language).queue();
return;
}
else if(MsgParts[1].trim().equalsIgnoreCase("en")) {
activLang = langEn;
channelList.put(event.getChannel().getId(), "en");
event.getChannel().sendMessage(getAsMention(event) + activLang.language).queue();
return;
}
String[] iniParts = MsgParts[1].trim().toLowerCase().split("\\+", 2);
messageInterpreter mI = new messageInterpreter(event, activLang);
if(iniParts.length == 1) { // Nachricht hat kein + Zeichen
mI.inputInterpreter(iniParts[0]);
if(mI.isNum()) {
numberOfDice = mI.getIntResult();
}
else if(mI.isDice()) {
diceart = mI.getDiceart();
numberOfDice = mI.getNumberOfDice();
}
}
else {
mI.inputInterpreter(iniParts[0]); // Vor dem +
if(mI.isNum()) {
iniBase = mI.getIntResult();
}
else if(mI.isDice()) {
iniBase = mI.getNumberOfDice();
}
mI.inputInterpreter(iniParts[1]); // Nach dem +
if(mI.isNum()) {
numberOfDice = mI.getIntResult();
}
else if(mI.isDice()) {
diceart = mI.getDiceart();
numberOfDice = mI.getNumberOfDice();
}
}
}
else {
try {
numberOfDice = Integer.parseInt(MsgParts[1].trim().replace(" ", ""));
}
catch (NumberFormatException e) {
String message = activLang.error;
message = message.replace("%command%", MsgParts[1].trim());
event.getChannel().sendMessage(getAsMention(event) + message).queue();
return;
}
}
if(numberOfDice <= 0) {
String message = activLang.noNegativ;
event.getChannel().sendMessage(getAsMention(event) + message).queue();
return;
}
ini += iniBase;
for(int i = 0; i < numberOfDice; i++) {
dice1 = new Random().nextInt(diceart);
result.append(dice1+1).append(" ");
ini += (dice1+1);
}
outputBox.setColor(new Color(104, 34, 139));
String message = "%iniBase%+%numberOfDice%w%diceart%\tIni: %ini%"; //activLang.resultText;
//%numberOfDice%%dice%%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
message = message.replace("%numberOfDice%", String.valueOf(numberOfDice)).replace("%diceart%", String.valueOf(diceart))
.replace("%iniBase%", String.valueOf(iniBase)).replace("%ini%", String.valueOf(ini));
outputBox.setTitle(getEffectiveName(event) + message);
outputBox.setDescription(iniBase + " + (" + result.toString().trim().replace(" ", "+") + ")");
event.getChannel().sendMessageEmbeds(outputBox.build()).queue();
}
catch (NumberFormatException e) {
event.getChannel().sendMessage("Nope").queue();
}
catch (IllegalArgumentException e) {
event.getChannel().sendMessage(e.getMessage()).queue();
}
catch (Exception e) {
System.out.println("problem: " + e.getMessage());
}
}
private void zitat(MessageReceivedEvent event) {
String[] quotes = new String[7];
quotes[0] = "*quiek quiek quiek*";
quotes[1] = "(\\\\______/)\n" +
"( ͡ ͡° ͜ ʖ ͡ ͡°) *snuff snuff*\n" +
"\\\\╭☞ \\\\╭☞\n";
quotes[2] = "(づ。◕‿‿◕。)づ";
quotes[3] = "zzzZZZZZzzZZ";
quotes[4] = "piiiep";
quotes[5] = "grrrrr";
//quotes[6] = "ʕᵔᴥᵔʔ =*Auto translator*=> In meiner psychophysischen Konstituton manifestiert sich eine absolute Dominanz positiver Effekte für die Individualität Deiner Person. ";
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) {
return "";
}
return event.getMember().getEffectiveName() + " ";
}
private String getAsMention(MessageReceivedEvent event) {
if(event.getMember() == null) {
return "";
}
return event.getMember().getAsMention() + " ";
}
private void reaktionRerollEdge(MessageReactionAddEvent event) {
Map<String, String> wurf = db.getMesssage(event.getMessageIdLong());
if(!wurf.containsKey("benutzerId")) {
return;
}
else if(!wurf.get("benutzerId").equals(event.getUserId())) {
return;
}
String[] wurfParts = wurf.get("wurfdaten").split("\\|");
int dice = Integer.parseInt(wurfParts[0]);
int hits = Integer.parseInt(wurfParts[1]);
int miss = Integer.parseInt(wurfParts[2]);
String effectName = "";
if(event.getMember().getEffectiveName() != "") {
effectName = event.getMember().getEffectiveName();
}
srrollOut(dice-hits, 6, false, event.getChannel(), event.getUser(), effectName, "Edege Reroll", hits, 1, event.getJDA());
}
private void extensionroll(MessageReactionAddEvent event) {
Map<String, String> wurf = db.getMesssage(event.getMessageIdLong());
if(!wurf.containsKey("benutzerId")) {
return;
}
else if(!wurf.get("benutzerId").equals(event.getUserId())) {
return;
}
String[] wurfParts = wurf.get("wurfdaten").split("\\|");
int dice = Integer.parseInt(wurfParts[0]);
int hits = Integer.parseInt(wurfParts[1]);
int miss = Integer.parseInt(wurfParts[2]);
String effectName = "";
if(event.getMember().getEffectiveName() != "") {
effectName = event.getMember().getEffectiveName();
}
if(dice == 1) {
event.getChannel().sendMessage(event.getUser().getAsMention() + " mehr geht nicht, du hast **" + hits + "** Erfolge").queue();
}
else {
srrollOut(dice - 1, 6, false, event.getChannel(), event.getUser(), effectName, "Extent Roll", hits, 2, event.getJDA());
}
}
}

View File

@ -0,0 +1,28 @@
package de.ocame.wuerfelbot.Shadowrun;
public class help {
private final StringBuilder hilfstext;
private final String sprache;
public help(String sprache) {
this.sprache = sprache;
hilfstext = new StringBuilder();
}
public void add(String befehl, String hilftext) {
if(this.hilfstext.length() > 0)
this.hilfstext.append("\n\n");
this.add("**" + befehl + "** " + hilftext);
}
public void add(String hilftext) {
this.hilfstext.append(hilftext);
}
public void send() {
StringBuilder ausgabe = new StringBuilder();
}
}

View File

@ -0,0 +1,93 @@
package de.ocame.wuerfelbot.Shadowrun;
import java.io.*;
import java.util.Properties;
public class language {
public String language = "Deutsch";
public String emptyCommand = " der %command% befehl benötigt einen Wert";
public String error = " Irgend was dummes ist passiert beim Verstehen von %command%";
public String error2 = " Irgend was dummes ist passiert beim Verstehen von %command%";
public String noNegativ = " es darf kein Negativen Wurf geben";
public String dice = "w";
public String resultText = " %numberOfDice%w%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
public String resultTextExtent = " %numberOfDice%w%diceart% %EdgeDice%:\tErfolge: %hits%\tMisserfolge: %oneHits%";
public String basisresultText = " %numberOfDice%w%diceart%:";
public language() {
this.readConfig();
}
/**
*
* @param lang Srache
*/
public language(String lang) {
this.readConfig(lang);
}
public void readConfig() {
this.readConfig("de");
}
public void readConfig(String lang) {
FileInputStream input = null;
OutputStream output = null;
Properties config = new Properties();
try {
File f = new File("shadowrun.cfg");
if (f.isFile() && f.canRead()) {
input = new FileInputStream("shadowrun.cfg");
config.load(input);
if(config.containsKey(lang + ".language"))
this.language = config.getProperty(lang + ".language");
if(config.containsKey(lang + ".emptyCommand"))
this.emptyCommand = config.getProperty(lang + ".emptyCommand");
if(config.containsKey(lang + ".error"))
this.error = config.getProperty(lang + ".error");
if(config.containsKey(lang + ".error2"))
this.error2 = config.getProperty(lang + ".error2");
if(config.containsKey(lang + ".noNegativ"))
this.noNegativ = config.getProperty(lang + ".noNegativ");
if(config.containsKey(lang + ".dice"))
this.dice = config.getProperty(lang + ".dice");
if(config.containsKey(lang + ".resultText"))
this.resultText = config.getProperty(lang + ".resultText");
if(config.containsKey(lang + ".resultTextExtent"))
this.resultText = config.getProperty(lang + ".resultTextExtent");
if(config.containsKey(lang + ".basisresultText"))
this.resultText = config.getProperty(lang + ".basisresultText");
}
else {
output = new FileOutputStream("shadowrun.cfg");
config.setProperty(lang + ".language", this.language);
config.setProperty(lang + ".emptyCommand", this.emptyCommand);
config.setProperty(lang + ".error", this.error);
config.setProperty(lang + ".error2", this.error2);
config.setProperty(lang + ".noNegativ", this.noNegativ);
config.setProperty(lang + ".dice", this.dice);
config.setProperty(lang + ".resultText", this.resultText);
config.setProperty(lang + ".resultTextExtent", this.resultTextExtent);
config.setProperty(lang + ".basisresultText", this.basisresultText);
config.store(output, null);
}
} catch (Exception e) {
}
finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

View File

@ -0,0 +1,83 @@
package de.ocame.wuerfelbot.Shadowrun;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.util.Scanner;
public class messageInterpreter {
private Integer diceart = 6;
private Integer numberOfDice = 1;
private Integer typ = 0;
private Integer intResult = 0;
private final language activLang;
private final MessageReceivedEvent event;
public Integer getDiceart() {
return diceart;
}
public Integer getNumberOfDice() {
return numberOfDice;
}
public Integer getIntResult() {
return intResult;
}
public boolean isNum() {
return typ == 1;
}
public boolean isDice() {
return typ == 2;
}
/**
*
* @param event JDA Event
* @param activLang Aktive Sprache
*/
public messageInterpreter(MessageReceivedEvent event, language activLang) {
this.event = event;
this.activLang = activLang;
}
private void reset() {
diceart = 6;
numberOfDice = 1;
typ = 0;
intResult = 0;
}
public void inputInterpreter(String Input) {
reset();
Scanner sc = new Scanner(Input.trim());
if(sc.hasNextInt()) { // ist eine Zahl
typ = 1;
intResult = Integer.parseInt(Input.trim());
}
else {
if (Input.trim().toLowerCase().replace(" ", "").matches("([0-9]*)[dw]([0-9].*)")) { // format besteh aus (Zahlen)d(Zahlen) oder (Zahlen)w(Zahlen)
String[] diceInterpreter = Input.trim().toLowerCase().replace(" ", "").split("[wd]");
try {
diceart = Integer.parseInt(diceInterpreter[1]);
numberOfDice = Integer.parseInt(diceInterpreter[0]);
typ = 2;
} catch (NumberFormatException e) {
String message = activLang.error;
message = message.replace("%command%", Input.trim().toLowerCase());
//event.getChannel().sendMessage(event.getMember().getAsMention() + message).queue();
typ = -1;
throw new IllegalArgumentException( message );
}
}
else {
String message = activLang.error;
message = message.replace("%command%", Input.trim().toLowerCase());
typ = -1;
throw new IllegalArgumentException( message );
}
}
}
}