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; + } + /** * 読み上げチャンネルを変更 *