fix NewsChannel erkennung

This commit is contained in:
Ocame
2025-07-23 12:01:02 +02:00
parent 3a6d822ead
commit c3764aab26
5 changed files with 51 additions and 17 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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,15 +88,30 @@ class SocketServerRunnable implements Runnable {
String response = ""; String response = "";
try { try {
TextChannel textchannel = jda.getTextChannelById(channelId); if(jda.getNewsChannelById(channelId) != null) {
if (textchannel.canTalk()) { NewsChannel textchannel = jda.getNewsChannelById(channelId);
jsonResponse.put("status", "success") if (textchannel.canTalk()) {
.put("name", textchannel.getName()) jsonResponse.put("status", "success")
.put("serverName", textchannel.getGuild().getName()); .put("name", textchannel.getName())
.put("serverName", textchannel.getGuild().getName());
}
else {
jsonResponse.put("status", "fail");
}
} }
else { 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) { catch (NullPointerException e) {
jsonResponse.put("status", "error"); jsonResponse.put("status", "error");

View File

@ -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) {

View File

@ -47,11 +47,20 @@ public abstract class BaseNotifier <T extends BaseNotifier<T>> {
} }
Long[] channelIds = SQLiteStorage.getChannelIds(); Long[] channelIds = SQLiteStorage.getChannelIds();
if(targetChannel != null) { if(targetChannel != null) {
Objects.requireNonNull(jda.getTextChannelById(targetChannel)) if (jda.getNewsChannelById(targetChannel) != null) {
// .sendMessage("Hier ist ein Text vor dem Embed <@&423156046115242005> :") Objects.requireNonNull(jda.getNewsChannelById(targetChannel))
// .setEmbeds(outputBox.build()) // .sendMessage("Hier ist ein Text vor dem Embed <@&423156046115242005> :")
.sendMessageEmbeds(outputBox.build()) // .setEmbeds(outputBox.build())
.queue(); .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) { 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();
@ -59,8 +68,17 @@ public abstract class BaseNotifier <T extends BaseNotifier<T>> {
else { else {
for (Long channelId : channelIds ) { for (Long channelId : channelIds ) {
try { try {
if (Objects.requireNonNull(jda.getTextChannelById(channelId)).canTalk()) if(jda.getTextChannelById(channelId) != null) {
Objects.requireNonNull(jda.getTextChannelById(channelId)).sendMessageEmbeds(outputBox.build()).queue(); 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) { catch (NullPointerException e) {
LoggerUtil.log("error", "BaseNotifier", "keine Rechte zu senden in " + channelId); LoggerUtil.log("error", "BaseNotifier", "keine Rechte zu senden in " + channelId);