fix NewsChannel erkennung
This commit is contained in:
@ -1,11 +1,11 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'application'
|
id 'application'
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
id("com.gradleup.shadow") version "8.3.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
application.mainClass = "de.ocame.ffdiscordbot.Main"
|
application.mainClass = "de.ocame.ffdiscordbot.Main"
|
||||||
group 'de.ocame'
|
group 'de.ocame'
|
||||||
version '1.3-SNAPSHOT'
|
version '1.4-SNAPSHOT'
|
||||||
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public class Main {
|
|||||||
.setActivity(Activity.playing("mit der Marine fangen"))
|
.setActivity(Activity.playing("mit der Marine fangen"))
|
||||||
.setStatus(OnlineStatus.ONLINE)
|
.setStatus(OnlineStatus.ONLINE)
|
||||||
.setAutoReconnect(true)
|
.setAutoReconnect(true)
|
||||||
.addEventListeners(new ChatReader())
|
//.addEventListeners(new ChatReader())
|
||||||
.build();/**/
|
.build();/**/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package de.ocame.ffdiscordbot;
|
package de.ocame.ffdiscordbot;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.concrete.NewsChannel;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -8,6 +9,7 @@ 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 {
|
||||||
|
|
||||||
@ -86,6 +88,18 @@ class SocketServerRunnable implements Runnable {
|
|||||||
String response = "";
|
String response = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if(jda.getNewsChannelById(channelId) != null) {
|
||||||
|
NewsChannel textchannel = jda.getNewsChannelById(channelId);
|
||||||
|
if (textchannel.canTalk()) {
|
||||||
|
jsonResponse.put("status", "success")
|
||||||
|
.put("name", textchannel.getName())
|
||||||
|
.put("serverName", textchannel.getGuild().getName());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jsonResponse.put("status", "fail");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
TextChannel textchannel = jda.getTextChannelById(channelId);
|
TextChannel textchannel = jda.getTextChannelById(channelId);
|
||||||
if (textchannel.canTalk()) {
|
if (textchannel.canTalk()) {
|
||||||
jsonResponse.put("status", "success")
|
jsonResponse.put("status", "success")
|
||||||
@ -96,6 +110,9 @@ class SocketServerRunnable implements Runnable {
|
|||||||
jsonResponse.put("status", "fail");
|
jsonResponse.put("status", "fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
catch (NullPointerException e) {
|
catch (NullPointerException e) {
|
||||||
jsonResponse.put("status", "error");
|
jsonResponse.put("status", "error");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,6 @@ public class MySQLStorage {
|
|||||||
// Verbindung erstellen
|
// Verbindung erstellen
|
||||||
String url = "jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
|
String url = "jdbc:mysql://" + host + ":" + port + "/" + database + "?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
|
||||||
connection = DriverManager.getConnection(url, username, password);
|
connection = DriverManager.getConnection(url, username, password);
|
||||||
System.out.println("Erfolgreich mit der Datenbank verbunden!");
|
|
||||||
LoggerUtil.log("info", "MySQL", "Erfolgreich mit der Datenbank verbunden!");
|
LoggerUtil.log("info", "MySQL", "Erfolgreich mit der Datenbank verbunden!");
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@ -47,20 +47,38 @@ public abstract class BaseNotifier <T extends BaseNotifier<T>> {
|
|||||||
}
|
}
|
||||||
Long[] channelIds = SQLiteStorage.getChannelIds();
|
Long[] channelIds = SQLiteStorage.getChannelIds();
|
||||||
if(targetChannel != null) {
|
if(targetChannel != null) {
|
||||||
|
if (jda.getNewsChannelById(targetChannel) != null) {
|
||||||
|
Objects.requireNonNull(jda.getNewsChannelById(targetChannel))
|
||||||
|
// .sendMessage("Hier ist ein Text vor dem Embed <@&423156046115242005> :")
|
||||||
|
// .setEmbeds(outputBox.build())
|
||||||
|
.sendMessageEmbeds(outputBox.build())
|
||||||
|
.queue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
Objects.requireNonNull(jda.getTextChannelById(targetChannel))
|
Objects.requireNonNull(jda.getTextChannelById(targetChannel))
|
||||||
// .sendMessage("Hier ist ein Text vor dem Embed <@&423156046115242005> :")
|
// .sendMessage("Hier ist ein Text vor dem Embed <@&423156046115242005> :")
|
||||||
// .setEmbeds(outputBox.build())
|
// .setEmbeds(outputBox.build())
|
||||||
.sendMessageEmbeds(outputBox.build())
|
.sendMessageEmbeds(outputBox.build())
|
||||||
.queue();
|
.queue();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if(Objects.requireNonNull(channelIds).length == 0) {
|
else if(Objects.requireNonNull(channelIds).length == 0) {
|
||||||
Objects.requireNonNull(jda.getTextChannelById(542202034330271759L)).sendMessageEmbeds(outputBox.build()).queue();
|
Objects.requireNonNull(jda.getTextChannelById(542202034330271759L)).sendMessageEmbeds(outputBox.build()).queue();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (Long channelId : channelIds ) {
|
for (Long channelId : channelIds ) {
|
||||||
try {
|
try {
|
||||||
|
if(jda.getTextChannelById(channelId) != null) {
|
||||||
if (Objects.requireNonNull(jda.getTextChannelById(channelId)).canTalk())
|
if (Objects.requireNonNull(jda.getTextChannelById(channelId)).canTalk())
|
||||||
Objects.requireNonNull(jda.getTextChannelById(channelId)).sendMessageEmbeds(outputBox.build()).queue();
|
Objects.requireNonNull(jda.getTextChannelById(channelId)).sendMessageEmbeds(outputBox.build()).queue();
|
||||||
|
} else if (jda.getNewsChannelById(channelId) != null) {
|
||||||
|
if (Objects.requireNonNull(jda.getNewsChannelById(channelId)).canTalk())
|
||||||
|
Objects.requireNonNull(jda.getNewsChannelById(channelId)).sendMessageEmbeds(outputBox.build()).queue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LoggerUtil.log("error", "BaseNotifier", "Kanal nicht Gefunden " + channelId);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NullPointerException e) {
|
catch (NullPointerException e) {
|
||||||
LoggerUtil.log("error", "BaseNotifier", "keine Rechte zu senden in " + channelId);
|
LoggerUtil.log("error", "BaseNotifier", "keine Rechte zu senden in " + channelId);
|
||||||
|
|||||||
Reference in New Issue
Block a user