mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-20 00:25:18 +00:00
服务器控制台和ConsoleLogChannel输出Discord聊天消息
This commit is contained in:
parent
ad66073e00
commit
cc04ed8de4
3 changed files with 34 additions and 5 deletions
|
|
@ -56,7 +56,7 @@ public class Config {
|
|||
|
||||
public String highMspt = "**服务器 MSPT (%mspt%) 高于 %msptLimit%!**";
|
||||
|
||||
public String consoleLogMessage = "[%timestamp%] [INFO] %message%";
|
||||
public String consoleLogMessage = "[%time%] [INFO] %message%";
|
||||
}
|
||||
|
||||
public static class TextsEN {
|
||||
|
|
@ -74,7 +74,7 @@ public class Config {
|
|||
|
||||
public String highMspt = "**Server MSPT (%mspt%) is above %msptLimit%!**";
|
||||
|
||||
public String consoleLogMessage = "[%timestamp%] [INFO] %message%";
|
||||
public String consoleLogMessage = "[%time%] [INFO] %message%";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import net.dv8tion.jda.api.entities.Member;
|
|||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.utils.MarkdownSanitizer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
|
@ -15,11 +16,19 @@ import net.minecraft.util.Formatting;
|
|||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static top.xujiayao.mcdiscordchat.Main.CHANNEL;
|
||||
import static top.xujiayao.mcdiscordchat.Main.CONFIG;
|
||||
import static top.xujiayao.mcdiscordchat.Main.CONSOLE_LOG_CHANNEL;
|
||||
import static top.xujiayao.mcdiscordchat.Main.JDA;
|
||||
import static top.xujiayao.mcdiscordchat.Main.LOGGER;
|
||||
import static top.xujiayao.mcdiscordchat.Main.MINECRAFT_LAST_RESET_TIME;
|
||||
import static top.xujiayao.mcdiscordchat.Main.MINECRAFT_SEND_COUNT;
|
||||
import static top.xujiayao.mcdiscordchat.Main.SIMPLE_DATE_FORMAT;
|
||||
import static top.xujiayao.mcdiscordchat.Main.TEXTS;
|
||||
|
||||
public class DiscordEventListener extends ListenerAdapter {
|
||||
|
||||
|
|
@ -42,6 +51,28 @@ public class DiscordEventListener extends ListenerAdapter {
|
|||
|
||||
StringBuilder message = new StringBuilder(EmojiParser.parseToAliases(e.getMessage().getContentDisplay()));
|
||||
|
||||
StringBuilder consoleMessage = new StringBuilder()
|
||||
.append("[Discord] <")
|
||||
.append(Objects.requireNonNull(e.getMember()).getEffectiveName())
|
||||
.append("> ")
|
||||
.append(message);
|
||||
|
||||
LOGGER.info(consoleMessage.toString());
|
||||
|
||||
if (!CONFIG.generic.consoleLogChannelId.isEmpty()) {
|
||||
if ((System.currentTimeMillis() - MINECRAFT_LAST_RESET_TIME) > 20000) {
|
||||
MINECRAFT_SEND_COUNT = 0;
|
||||
MINECRAFT_LAST_RESET_TIME = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
MINECRAFT_SEND_COUNT++;
|
||||
if (MINECRAFT_SEND_COUNT <= 20) {
|
||||
CONSOLE_LOG_CHANNEL.sendMessage(TEXTS.consoleLogMessage()
|
||||
.replace("%time%", SIMPLE_DATE_FORMAT.format(new Date()))
|
||||
.replace("%message%", MarkdownSanitizer.escape(consoleMessage.toString()))).queue();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 处理Markdown(message)
|
||||
|
||||
if (!e.getMessage().getAttachments().isEmpty()) {
|
||||
|
|
@ -86,8 +117,6 @@ public class DiscordEventListener extends ListenerAdapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 控制台和ConsoleLogChannel也要输出
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
Object instance = FabricLoader.getInstance().getGameInstance();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class MixinMinecraftServer {
|
|||
MINECRAFT_SEND_COUNT++;
|
||||
if (MINECRAFT_SEND_COUNT <= 20) {
|
||||
CONSOLE_LOG_CHANNEL.sendMessage(TEXTS.consoleLogMessage()
|
||||
.replace("%timestamp%", SIMPLE_DATE_FORMAT.format(new Date()))
|
||||
.replace("%time%", SIMPLE_DATE_FORMAT.format(new Date()))
|
||||
.replace("%message%", MarkdownSanitizer.escape(message.getString()))).queue();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue