zwichenstand
This commit is contained in:
@ -5,6 +5,7 @@ import net.dv8tion.jda.core.entities.ChannelType;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import okhttp3.internal.Internal;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -14,11 +15,13 @@ import java.security.SecureRandom;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class dice extends ListenerAdapter {
|
||||
|
||||
private String prefixSr;
|
||||
private String prefixIni;
|
||||
private String prefixZitat;
|
||||
private String prefixTest;
|
||||
|
||||
@ -33,13 +36,18 @@ public class dice extends ListenerAdapter {
|
||||
|
||||
public dice() {
|
||||
this.prefixSr = "/sr";
|
||||
this.prefixIni = "/ini";
|
||||
this.prefixTest = "/rollTest";
|
||||
this.prefixZitat = "/zitat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
if ((!event.getMessage().getContentRaw().startsWith(this.prefixSr) && !event.getMessage().getContentRaw().startsWith(this.prefixZitat) && !event.getMessage().getContentRaw().startsWith(this.prefixTest)) || event.getChannelType() != ChannelType.TEXT) {
|
||||
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.getChannelType() != ChannelType.TEXT) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -64,9 +72,11 @@ public class dice extends ListenerAdapter {
|
||||
if (!author.isBot()) {
|
||||
if (event.getMessage().getContentRaw().startsWith(this.prefixSr))
|
||||
this.roll(event);
|
||||
if (event.getMessage().getContentRaw().startsWith(this.prefixTest))
|
||||
else if (event.getMessage().getContentRaw().startsWith(this.prefixIni))
|
||||
this.ini(event);
|
||||
else if (event.getMessage().getContentRaw().startsWith(this.prefixTest))
|
||||
this.rollTest(event);
|
||||
if (event.getMessage().getContentRaw().startsWith(this.prefixZitat))
|
||||
else if (event.getMessage().getContentRaw().startsWith(this.prefixZitat))
|
||||
this.zitat(event);
|
||||
}
|
||||
}
|
||||
@ -298,6 +308,138 @@ public class dice extends ListenerAdapter {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private void ini(MessageReceivedEvent event) {
|
||||
|
||||
EmbedBuilder outputBox = new EmbedBuilder();
|
||||
|
||||
int[] verteilung = new int[6];
|
||||
int dice1;
|
||||
int numberOfDice = 1;
|
||||
int diceart = 6;
|
||||
StringBuilder result = new StringBuilder("");
|
||||
|
||||
try {
|
||||
String[] MsgParts = event.getMessage().getContentRaw().split(" ", 2);
|
||||
if(MsgParts.length < 2) {
|
||||
String message = activLang.emptyCommand;
|
||||
message = message.replace("%command%", this.prefixIni);
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + message).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if(MsgParts[1].trim().matches(".*[^0-9].*")) { // es wurden andere zeichen als Zahlen gefunden
|
||||
if(MsgParts[1].trim().toLowerCase().equals("de")) {
|
||||
activLang = langDe;
|
||||
channelList.put(event.getChannel().getId(), "de");
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + activLang.language).queue();
|
||||
return;
|
||||
}
|
||||
else if(MsgParts[1].trim().toLowerCase().equals("en")) {
|
||||
activLang = langEn;
|
||||
channelList.put(event.getChannel().getId(), "en");
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + activLang.language).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String[] iniParts = MsgParts[1].trim().toLowerCase().split("\\+", 2);
|
||||
if(iniParts.length == 1) {
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
if(true) {
|
||||
this.inputInterpreter(event, iniParts[0]);
|
||||
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]);
|
||||
verteilung = new int[diceart];
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
String message = activLang.error;
|
||||
message = message.replace("%command%", MsgParts[1].trim().toLowerCase());
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + message).queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = activLang.error;
|
||||
message = message.replace("%command%", MsgParts[1].trim());
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + 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(event.getMember().getAsMention() + message).queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
if(MsgParts[1].trim().toLowerCase().replace(" ", "").matches("^([0-9]*\\+)?[0-9]*([dw][0-9]*)?(\\+[0-9]*)?")) { // format besteh aus (Zahlen)+(Zahlen)d(Zahlen) oder (Zahlen)d(Zahlen)+(Zahlen)
|
||||
String[] diceInterpreter = MsgParts[1].trim().toLowerCase().replace(" ", "").split("\\+");
|
||||
try {
|
||||
diceart = Integer.parseInt(diceInterpreter[1]);
|
||||
numberOdDice = Integer.parseInt(diceInterpreter[0]);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + " Irgent was dummes ist passiert beim Verstehen von " + MsgParts[1].trim().toLowerCase()).queue();
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
if(numberOfDice <= 0) {
|
||||
String message = activLang.noNegativ;
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + message).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < numberOfDice; i++) {
|
||||
dice1 = new Random().nextInt(diceart);
|
||||
|
||||
verteilung[dice1]++;
|
||||
result.append(dice1+1).append(" ");
|
||||
}
|
||||
outputBox.setColor(new Color(104, 34, 139));
|
||||
|
||||
|
||||
String addition = "";
|
||||
|
||||
String 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);
|
||||
outputBox.setTitle(event.getMember().getEffectiveName() + " " + message);
|
||||
|
||||
|
||||
outputBox.setDescription("(" + result.toString().trim() + ")");
|
||||
|
||||
event.getChannel().sendMessage(outputBox.build()).queue();
|
||||
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
event.getChannel().sendMessage("Nope").queue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("problem: " + e.getMessage());
|
||||
} finally {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private void zitat(MessageReceivedEvent event) {
|
||||
String[] quotes = new String[7];
|
||||
@ -318,5 +460,28 @@ public class dice extends ListenerAdapter {
|
||||
event.getChannel().sendMessage(quotes[dice%6]).queue();
|
||||
}
|
||||
|
||||
private void inputInterpreter(MessageReceivedEvent event, String Input) {
|
||||
Scanner sc = new Scanner(Input.trim());
|
||||
Integer diceart = 6;
|
||||
Integer numberOfDice = 1;
|
||||
|
||||
if(sc.hasNextInt()) { // ist eine Zahl
|
||||
|
||||
}
|
||||
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]);
|
||||
} catch (NumberFormatException e) {
|
||||
String message = activLang.error;
|
||||
message = message.replace("%command%", Input.trim().toLowerCase());
|
||||
event.getChannel().sendMessage(event.getMember().getAsMention() + message).queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user