Code Optimierung
This commit is contained in:
@ -378,7 +378,7 @@ public class FanFiktionReader {
|
|||||||
Document sendToFav = fetcher.fetchHtml(URL + "/?a=q&a1=v&t=addstory&lbi=popup-addtofav-body&ar=1&action=i", postData);
|
Document sendToFav = fetcher.fetchHtml(URL + "/?a=q&a1=v&t=addstory&lbi=popup-addtofav-body&ar=1&action=i", postData);
|
||||||
if(sendToFav.getElementsByClass("successbox").isEmpty()) {
|
if(sendToFav.getElementsByClass("successbox").isEmpty()) {
|
||||||
LoggerUtil.log("error", "Reader", "Story konnte nicht hinzugefügt werden");
|
LoggerUtil.log("error", "Reader", "Story konnte nicht hinzugefügt werden");
|
||||||
new InfoNotifier(jda).setMessagetext("Story " + ffid + "konnte nicht hinzugefügt werden. \n" + sendToFav.toString()).sendOutput();
|
new InfoNotifier(jda).setMessagetext("Story " + ffid + "konnte nicht hinzugefügt werden. \n" + sendToFav).sendOutput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException | InterruptedException e) {
|
catch (IOException | InterruptedException e) {
|
||||||
|
|||||||
@ -33,6 +33,7 @@ public class Main {
|
|||||||
TimeUnit.SECONDS.sleep(10);
|
TimeUnit.SECONDS.sleep(10);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
|
LoggerUtil.log("error", "Main", "Sleeptimer erzuegt Fehler" + e.getMessage());
|
||||||
|
|
||||||
}
|
}
|
||||||
FanFiktionReader ffr = new FanFiktionReader(jda);
|
FanFiktionReader ffr = new FanFiktionReader(jda);
|
||||||
@ -56,7 +57,7 @@ public class Main {
|
|||||||
delay[0] = ffr.getTime();
|
delay[0] = ffr.getTime();
|
||||||
|
|
||||||
|
|
||||||
LoggerUtil.log("info", "Main", "neue Zeit: " + (Long.toString(Math.round(delay[0] / 60 * 10)/10) ));
|
LoggerUtil.log("info", "Main", "neue Zeit: " + (Long.toString(Math.round((float) delay[0] / 60 * 10)/10) ));
|
||||||
|
|
||||||
// Plane die Aufgabe erneut mit dem neuen Intervall
|
// Plane die Aufgabe erneut mit dem neuen Intervall
|
||||||
scheduledFuture.get().cancel(false);
|
scheduledFuture.get().cancel(false);
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package de.ocame.ffdiscordbot;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
class SocketServerRunnable implements Runnable {
|
class SocketServerRunnable implements Runnable {
|
||||||
|
|
||||||
@ -54,7 +53,6 @@ class SocketServerRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
catch (IOException | NullPointerException e) {
|
catch (IOException | NullPointerException e) {
|
||||||
LoggerUtil.log("error", "SocketRunnable", "Fehler bei der Kommunikation mit dem Client: " + e.getMessage());
|
LoggerUtil.log("error", "SocketRunnable", "Fehler bei der Kommunikation mit dem Client: " + e.getMessage());
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +63,7 @@ class SocketServerRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
private Boolean channelCheckAction(JSONObject jsonData, PrintWriter out) {
|
private Boolean channelCheckAction(JSONObject jsonData, PrintWriter out) {
|
||||||
JSONObject jsonResponse= new JSONObject();
|
JSONObject jsonResponse= new JSONObject();
|
||||||
Long channelId = null;
|
long channelId;
|
||||||
|
|
||||||
Object channelIdObj = jsonData.get("channelId");
|
Object channelIdObj = jsonData.get("channelId");
|
||||||
if(channelIdObj.equals("")) {
|
if(channelIdObj.equals("")) {
|
||||||
@ -76,8 +74,7 @@ class SocketServerRunnable implements Runnable {
|
|||||||
if (channelIdObj instanceof Number) {
|
if (channelIdObj instanceof Number) {
|
||||||
channelId = ((Number) channelIdObj).longValue();
|
channelId = ((Number) channelIdObj).longValue();
|
||||||
}
|
}
|
||||||
else if (channelIdObj instanceof String) {
|
else if (channelIdObj instanceof String channelIdStr) {
|
||||||
String channelIdStr = (String) channelIdObj;
|
|
||||||
channelId = Long.parseLong(channelIdStr);
|
channelId = Long.parseLong(channelIdStr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -85,8 +82,6 @@ class SocketServerRunnable implements Runnable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String response = "";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(jda.getNewsChannelById(channelId) != null) {
|
if(jda.getNewsChannelById(channelId) != null) {
|
||||||
NewsChannel textchannel = jda.getNewsChannelById(channelId);
|
NewsChannel textchannel = jda.getNewsChannelById(channelId);
|
||||||
|
|||||||
@ -12,7 +12,6 @@ import java.util.regex.Pattern;
|
|||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AchievementManager {
|
public class AchievementManager {
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import net.dv8tion.jda.api.requests.RestAction;
|
|||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
public class ChatReader extends ListenerAdapter {
|
public class ChatReader extends ListenerAdapter {
|
||||||
|
|
||||||
RestAction<?> latestUpdate = null;
|
RestAction<?> latestUpdate = null;
|
||||||
private Set<String> ChannelWhitelist;
|
private final Set<String> ChannelWhitelist;
|
||||||
|
|
||||||
public ChatReader() {
|
public ChatReader() {
|
||||||
ChannelWhitelist = new HashSet<>();
|
ChannelWhitelist = new HashSet<>();
|
||||||
@ -63,7 +62,7 @@ public class ChatReader extends ListenerAdapter {
|
|||||||
if(!ChannelWhitelist.contains(event.getChannel().getId())) {
|
if(!ChannelWhitelist.contains(event.getChannel().getId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println(event.getReaction().toString());
|
System.out.println(event.getReaction());
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================================================================================
|
// =========================================================================================
|
||||||
@ -90,7 +89,7 @@ public class ChatReader extends ListenerAdapter {
|
|||||||
event.getChannel().getIterableHistory()
|
event.getChannel().getIterableHistory()
|
||||||
.forEachAsync(message -> {
|
.forEachAsync(message -> {
|
||||||
messages.add(message);
|
messages.add(message);
|
||||||
System.out.println(message.getType().toString());
|
System.out.println(message.getType());
|
||||||
handleProgressUpdate(progressMessage, filePath, messages.size());
|
handleProgressUpdate(progressMessage, filePath, messages.size());
|
||||||
return messages.size() < MAX_DESIRED;
|
return messages.size() < MAX_DESIRED;
|
||||||
})
|
})
|
||||||
@ -152,7 +151,7 @@ public class ChatReader extends ListenerAdapter {
|
|||||||
|
|
||||||
private void writeMessageToFile(FileWriter fileWriter, Message message) {
|
private void writeMessageToFile(FileWriter fileWriter, Message message) {
|
||||||
try {
|
try {
|
||||||
fileWriter.write("Time: " + message.getTimeCreated().toString() + "\n");
|
fileWriter.write("Time: " + message.getTimeCreated() + "\n");
|
||||||
fileWriter.write("Author: " + message.getAuthor().getId() + "\n");
|
fileWriter.write("Author: " + message.getAuthor().getId() + "\n");
|
||||||
fileWriter.write("Message ID: " + message.getId() + "\n");
|
fileWriter.write("Message ID: " + message.getId() + "\n");
|
||||||
fileWriter.write("Content: " + message.getContentRaw() + "\n");
|
fileWriter.write("Content: " + message.getContentRaw() + "\n");
|
||||||
@ -168,7 +167,7 @@ public class ChatReader extends ListenerAdapter {
|
|||||||
reaction.retrieveUsers().queue(users -> {
|
reaction.retrieveUsers().queue(users -> {
|
||||||
StringBuilder reactionUsers = new StringBuilder();
|
StringBuilder reactionUsers = new StringBuilder();
|
||||||
for (User user : users) {
|
for (User user : users) {
|
||||||
if (reactionUsers.length() > 0) reactionUsers.append("|");
|
if (!reactionUsers.isEmpty()) reactionUsers.append("|");
|
||||||
reactionUsers.append(user.getId());
|
reactionUsers.append(user.getId());
|
||||||
}
|
}
|
||||||
reactionFuture.complete("Reaction: " + emojiName + ": " + reactionUsers + "\n");
|
reactionFuture.complete("Reaction: " + emojiName + ": " + reactionUsers + "\n");
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package de.ocame.ffdiscordbot.achievements;
|
|||||||
|
|
||||||
import de.ocame.ffdiscordbot.ConfigLoader;
|
import de.ocame.ffdiscordbot.ConfigLoader;
|
||||||
import de.ocame.ffdiscordbot.LoggerUtil;
|
import de.ocame.ffdiscordbot.LoggerUtil;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
@ -32,7 +33,8 @@ public class MySQLStorage {
|
|||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LoggerUtil.log("error", "MySQL", "Fehler beim Herstellen der Verbindung zur MySQL-Datenbank: " + e.getMessage());
|
LoggerUtil.log("error", "MySQL", "Fehler beim Herstellen der Verbindung zur MySQL-Datenbank: " + e.getMessage());
|
||||||
e.printStackTrace();
|
//e.printStackTrace();
|
||||||
|
LoggerFactory.getLogger("MySQL").error("Stack: ", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
|
|||||||
@ -107,14 +107,14 @@ public class DefaultHtmlFetcher implements HtmlFetcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class SerializableCookie {
|
private static class SerializableCookie {
|
||||||
private String uri;
|
private final String uri;
|
||||||
private String name;
|
private final String name;
|
||||||
private String value;
|
private final String value;
|
||||||
private String path;
|
private final String path;
|
||||||
private String domain;
|
private final String domain;
|
||||||
private long maxAge;
|
private final long maxAge;
|
||||||
private boolean secure;
|
private final boolean secure;
|
||||||
private boolean httpOnly;
|
private final boolean httpOnly;
|
||||||
|
|
||||||
SerializableCookie(HttpCookie cookie) {
|
SerializableCookie(HttpCookie cookie) {
|
||||||
this.uri = cookie.getDomain();
|
this.uri = cookie.getDomain();
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import java.util.Map;
|
|||||||
// Handles notifications about new chapters
|
// Handles notifications about new chapters
|
||||||
public class ChapterNotifier extends BaseNotifier<ChapterNotifier> {
|
public class ChapterNotifier extends BaseNotifier<ChapterNotifier> {
|
||||||
|
|
||||||
private DataChapter chapter;
|
private final DataChapter chapter;
|
||||||
private DataStory story;
|
private final DataStory story;
|
||||||
|
|
||||||
public ChapterNotifier(JDA jda, DataChapter chapter, DataStory story) {
|
public ChapterNotifier(JDA jda, DataChapter chapter, DataStory story) {
|
||||||
super(jda);
|
super(jda);
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import net.dv8tion.jda.api.JDA;
|
|||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class InfoNotifier extends BaseNotifier<InfoNotifier> {
|
public class InfoNotifier extends BaseNotifier<InfoNotifier> {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user