Skip to content

Commit

Permalink
稼働情報に利用者数を追加、稼働時間の表記を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
MORIMORI0317 committed Feb 3, 2024
1 parent 9f8e90e commit c47fc83
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 = "<t:%d:R>";

/**
* コンストラクタ
*/
Expand Down Expand Up @@ -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();
}
Expand Down
30 changes: 30 additions & 0 deletions core/src/main/java/dev/felnull/itts/core/tts/TTSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@ public int getTTSCount() {
return instances.size();
}

/**
* 利用者数を取得
*
* @return 利用者数
*/
public int getUserCount() {
List<Guild> guilds = getBot().getJDA().getGuilds();

List<Long> 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;
}

/**
* 読み上げチャンネルを変更
*
Expand Down

0 comments on commit c47fc83

Please sign in to comment.