From c47fc83d1d1812cffd0f8bdbe63d797964f98aa2 Mon Sep 17 00:00:00 2001 From: MORIMORI0317 Date: Sat, 3 Feb 2024 19:31:45 +0900 Subject: [PATCH] =?UTF-8?q?=E7=A8=BC=E5=83=8D=E6=83=85=E5=A0=B1=E3=81=AB?= =?UTF-8?q?=E5=88=A9=E7=94=A8=E8=80=85=E6=95=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=80=81=E7=A8=BC=E5=83=8D=E6=99=82=E9=96=93=E3=81=AE=E8=A1=A8?= =?UTF-8?q?=E8=A8=98=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/discord/command/InfoCommand.java | 14 +++++++-- .../dev/felnull/itts/core/tts/TTSManager.java | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/dev/felnull/itts/core/discord/command/InfoCommand.java b/core/src/main/java/dev/felnull/itts/core/discord/command/InfoCommand.java index ece4a37..ff381ff 100644 --- a/core/src/main/java/dev/felnull/itts/core/discord/command/InfoCommand.java +++ b/core/src/main/java/dev/felnull/itts/core/discord/command/InfoCommand.java @@ -1,6 +1,6 @@ package dev.felnull.itts.core.discord.command; -import dev.felnull.fnjl.util.FNStringUtil; +import dev.felnull.itts.core.tts.TTSManager; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.build.Commands; @@ -24,6 +24,11 @@ public class InfoCommand extends BaseCommand { */ private static final String SOURCE_URL = "https://github.com/TeamFelnull/I-TTS"; + /** + * 時間を相対的に表示するフォーマット + */ + private static final String RELATIVE_TIME_FORMAT = ""; + /** * コンストラクタ */ @@ -80,14 +85,17 @@ private void oss(SlashCommandInteractionEvent e) { } private void work(SlashCommandInteractionEvent e) { + TTSManager ttsManager = getTTSManager(); + EmbedBuilder workEmbedBuilder = new EmbedBuilder(); workEmbedBuilder.setColor(getConfigManager().getConfig().getThemeColor()); workEmbedBuilder.setTitle("稼働情報"); - workEmbedBuilder.addField("稼働時間", FNStringUtil.getTimeFormat(System.currentTimeMillis() - getITTSRuntime().getStartupTime()), false); + workEmbedBuilder.addField("稼働開始時間", String.format(RELATIVE_TIME_FORMAT, getITTSRuntime().getStartupTime() / 1000), false); workEmbedBuilder.addField("参加サーバー数", e.getJDA().getGuilds().size() + "個", false); - workEmbedBuilder.addField("読み上げサーバー数", getTTSManager().getTTSCount() + "個", false); + workEmbedBuilder.addField("読み上げサーバー数", ttsManager.getTTSCount() + "個", false); + workEmbedBuilder.addField("利用者数", ttsManager.getUserCount() + "人", false); e.replyEmbeds(workEmbedBuilder.build()).setEphemeral(true).queue(); } diff --git a/core/src/main/java/dev/felnull/itts/core/tts/TTSManager.java b/core/src/main/java/dev/felnull/itts/core/tts/TTSManager.java index df3e7b4..e9ffe2d 100644 --- a/core/src/main/java/dev/felnull/itts/core/tts/TTSManager.java +++ b/core/src/main/java/dev/felnull/itts/core/tts/TTSManager.java @@ -40,6 +40,36 @@ public int getTTSCount() { return instances.size(); } + /** + * 利用者数を取得 + * + * @return 利用者数 + */ + public int getUserCount() { + List guilds = getBot().getJDA().getGuilds(); + + List ttsChannels = instances.values().stream() + .map(TTSInstance::getAudioChannel) + .toList(); + + long users = guilds.stream() + .flatMap(guild -> guild.getVoiceStates().stream()) + .filter(voiceState -> voiceState.getChannel() != null) + .filter(voiceState -> { + AudioChannelUnion channelUnion = voiceState.getChannel(); + if (channelUnion != null) { + return ttsChannels.contains(channelUnion.getIdLong()); + } + return false; + }) + .filter(TTSUtils::canListen) + // .map(GuildVoiceState::getMember) + // .distinct() + .count(); + + return (int) users; + } + /** * 読み上げチャンネルを変更 *