Bat/src/main/java/cc/fascinated/bat/command/impl/BotStatsCommand.java

56 lines
2.4 KiB
Java
Raw Normal View History

2024-06-27 11:28:38 +01:00
package cc.fascinated.bat.command.impl;
import cc.fascinated.bat.command.BatCommand;
2024-06-27 19:36:52 +01:00
import cc.fascinated.bat.command.CommandInfo;
2024-06-27 11:28:38 +01:00
import cc.fascinated.bat.common.EmbedUtils;
2024-06-27 13:25:12 +01:00
import cc.fascinated.bat.common.TimeUtils;
2024-06-27 11:28:38 +01:00
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import cc.fascinated.bat.service.UserService;
2024-06-27 11:28:38 +01:00
import lombok.NonNull;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.springframework.beans.factory.annotation.Autowired;
2024-06-27 11:28:38 +01:00
import org.springframework.stereotype.Component;
2024-06-27 13:25:12 +01:00
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
2024-06-27 11:28:38 +01:00
/**
* @author Fascinated (fascinated7)
*/
@Component
@CommandInfo(name = "botstats", description = "Shows the bot statistics", guildOnly = false)
2024-06-27 11:28:38 +01:00
public class BotStatsCommand extends BatCommand {
private final GuildService guildService;
private final UserService userService;
2024-06-28 03:01:21 +01:00
private final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
@Autowired
public BotStatsCommand(@NonNull GuildService guildService, @NonNull UserService userService) {
this.guildService = guildService;
this.userService = userService;
2024-06-27 11:28:38 +01:00
}
@Override
public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction interaction) {
JDA jda = DiscordService.JDA;
2024-06-27 11:45:06 +01:00
interaction.replyEmbeds(EmbedUtils.genericEmbed().setDescription(
"**Bot Statistics**\n" +
2024-06-28 04:05:41 +01:00
"➜ Guilds: **%s**\n".formatted(jda.getGuilds().size()) +
"➜ Users: **%s**\n".formatted(jda.getUsers().size()) +
2024-06-28 03:01:21 +01:00
"➜ Gateway Ping: **%sms**\n".formatted(jda.getGatewayPing()) +
"\n" +
"**Bat Statistics**\n" +
"➜ Uptime: **%s**\n".formatted(TimeUtils.format(bean.getUptime())) +
"➜ Cached Guilds: **%s**\n".formatted(guildService.getGuilds().size()) +
"➜ Cached Users: **%s**".formatted(userService.getUsers().size())
2024-06-27 11:45:06 +01:00
).build()).queue();
2024-06-27 11:28:38 +01:00
}
}