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