SteamWar/BungeeCore
Archiviert
13
2

Reworked Checklist Channel, Working ErrorLogger
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: Lixfel <git-5w3l@lixfel.de>
Dieser Commit ist enthalten in:
Lixfel 2024-06-27 15:33:00 +02:00
Ursprung b3a987f9a5
Commit a15bd4aa83
4 geänderte Dateien mit 54 neuen und 58 gelöschten Zeilen

Datei anzeigen

@ -20,71 +20,63 @@
package de.steamwar.velocitycore; package de.steamwar.velocitycore;
import de.steamwar.sql.SWException; import de.steamwar.sql.SWException;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
import org.apache.logging.log4j.core.config.Property;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class ErrorLogger extends Handler /*AbstractAppender*/ { public class ErrorLogger extends AbstractAppender {
ErrorLogger(){ ErrorLogger() {
//super("SW ErrorLogger", filter, layout, false, null); super("SW ErrorLogger", null, null, false, Property.EMPTY_ARRAY);
//((LoggerContext) org.apache.logging.log4j.LogManager.getContext(false)).getConfiguration().addAppender(this); start();
VelocityCore.getLogger().addHandler(this);
LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.getConfiguration().addAppender(this);
context.getRootLogger().addAppender(this);
context.updateLoggers();
} }
void unregister(){ void unregister() {
Logger.getGlobal().removeHandler(this); LoggerContext context = (LoggerContext) LogManager.getContext(false);
((AbstractConfiguration) context.getConfiguration()).removeAppender(getName());
context.getRootLogger().removeAppender(this);
context.updateLoggers();
} }
@Override @Override
public void publish(LogRecord logRecord) { public void append(LogEvent event) {
if(logRecord.getLevel().intValue() < Level.WARNING.intValue()) if(event.getLevel().isLessSpecificThan(Level.WARN))
return; return;
String message = logRecord.getParameters() != null ? MessageFormat.format(logRecord.getMessage(), logRecord.getParameters()) : logRecord.getMessage(); String message = event.getMessage().getFormattedMessage();
for(String reason : ignoreContains) for(String reason : ignoreContains)
if(message.contains(reason)) if(message.contains(reason))
return; return;
ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream(); ByteArrayOutputStream stacktraceOutput = new ByteArrayOutputStream();
if(logRecord.getThrown() != null) if(event.getThrown() != null)
logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput)); event.getThrown().printStackTrace(new PrintStream(stacktraceOutput));
String stacktrace = stacktraceOutput.toString(); String stacktrace = stacktraceOutput.toString();
if (stacktrace.contains("ErrorLogger")) { if (stacktrace.contains("ErrorLogger"))
return; return;
}
SWException.log(message, stacktrace); SWException.log(message, stacktrace);
} }
@Override
public void flush() {
//ignored
}
@Override
public void close() {
//ignored
}
private static final List<String> ignoreContains; private static final List<String> ignoreContains;
static { static {
List<String> contains = new ArrayList<>(); List<String> contains = new ArrayList<>();
ignoreContains = Collections.unmodifiableList(contains); ignoreContains = Collections.unmodifiableList(contains);
} }
/*@Override
public void append(LogEvent event) {
}*/
} }

Datei anzeigen

@ -169,7 +169,7 @@ public class CheckCommand extends SWCommand {
} }
public static List<SchematicNode> getSchemsToCheck(){ public static List<SchematicNode> getSchemsToCheck(){
List<SchematicNode> schematicList = new LinkedList<>(); List<SchematicNode> schematicList = new ArrayList<>();
for (SchematicType type : SchematicType.values()) { for (SchematicType type : SchematicType.values()) {
if (type.check()) if (type.check())

Datei anzeigen

@ -147,7 +147,7 @@ public class DiscordBot {
.build()) .build())
.setActionRows(ActionRow.of(Arrays.stream(DiscordTicketType.values()).map(DiscordTicketType::toButton).toArray(Button[]::new))), DiscordTicketHandler::openTicket); .setActionRows(ActionRow.of(Arrays.stream(DiscordTicketType.values()).map(DiscordTicketType::toButton).toArray(Button[]::new))), DiscordTicketHandler::openTicket);
eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get); eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get);
StaticMessageChannel checklistChannel = new StaticMessageChannel(config.channel("checklist"), ChecklistChannel::get); ChecklistChannel checklistChannel = new ChecklistChannel(config.channel("checklist"));
announcementChannel = new DiscordChannel(config.channel("announcement")) { announcementChannel = new DiscordChannel(config.channel("announcement")) {
@Override @Override

Datei anzeigen

@ -19,34 +19,38 @@
package de.steamwar.velocitycore.discord.channels; package de.steamwar.velocitycore.discord.channels;
import de.steamwar.velocitycore.commands.CheckCommand; import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass; import de.steamwar.velocitycore.commands.CheckCommand;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import java.awt.*; import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@UtilityClass public class ChecklistChannel extends DiscordChannel {
public class ChecklistChannel {
public MessageBuilder get() { private final List<Integer> lastSchematics = new ArrayList<>();
EmbedBuilder embedBuilder = new EmbedBuilder()
.setColor(Color.GRAY)
.setTitle("Check List")
.setAuthor("SteamWar", "https://www.steamwar.de");
CheckCommand.getSchemsToCheck().forEach(schematic -> { public ChecklistChannel(String channel) {
StringBuilder st = new StringBuilder(); super(channel);
st.append("Typ: ").append(schematic.getSchemtype().getKuerzel());
st.append("\nVon: ").append(SteamwarUser.get(schematic.getOwner()).getUserName());
String checker = CheckCommand.getChecker(schematic);
if (checker != null) {
st.append("\nWird Geprüft von: ").append(checker);
} }
embedBuilder.addField(schematic.getName(), st.toString(), true);
});
return StaticMessageChannel.toMessageBuilder(embedBuilder); public void update() {
List<SchematicNode> schems = CheckCommand.getSchemsToCheck();
int currentListSize = schems.size();
lastSchematics.removeIf(id -> schems.stream().noneMatch(schem -> schem.getId() == id));
schems.removeIf(schem -> lastSchematics.contains(schem.getId()));
for(SchematicNode schem : schems) {
send(StaticMessageChannel.toMessageBuilder(new EmbedBuilder()
.setColor(Color.GRAY)
.setTitle("Check List (" + currentListSize + ")")
.setAuthor("SteamWar", "https://www.steamwar.de")
.addField(schem.getName(), "Typ: " + schem.getSchemtype().getKuerzel() + "\nVon: " + SteamwarUser.get(schem.getOwner()).getUserName(), true)));
lastSchematics.add(schem.getId());
}
} }
} }