From 5ba6039d4abd8c4b568ecdb5562c7fb1673ce8a5 Mon Sep 17 00:00:00 2001 From: oko Date: Wed, 30 Mar 2022 09:39:07 -0700 Subject: [PATCH] finalize previous commit --- .../oko/Kiafumi/command/AvatarCommand.java | 2 +- .../moe/oko/Kiafumi/command/InfoCommand.java | 65 ++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/main/java/moe/oko/Kiafumi/command/AvatarCommand.java b/src/main/java/moe/oko/Kiafumi/command/AvatarCommand.java index b87b366..7a9d626 100644 --- a/src/main/java/moe/oko/Kiafumi/command/AvatarCommand.java +++ b/src/main/java/moe/oko/Kiafumi/command/AvatarCommand.java @@ -31,7 +31,7 @@ public class AvatarCommand extends CommandClass { EmbedBuilder eb = new EmbedBuilder() .setColor(EmbedUI.INFO) - .setAuthor(user.getName()) + .setAuthor(user.getName() + "#" + user.getDiscriminator()) .setImage(user.getEffectiveAvatarUrl() + "?size=2048") .setFooter(EmbedUI.BRAND) .setTimestamp(ZonedDateTime.now()); diff --git a/src/main/java/moe/oko/Kiafumi/command/InfoCommand.java b/src/main/java/moe/oko/Kiafumi/command/InfoCommand.java index c281d09..b6562a9 100644 --- a/src/main/java/moe/oko/Kiafumi/command/InfoCommand.java +++ b/src/main/java/moe/oko/Kiafumi/command/InfoCommand.java @@ -1,24 +1,83 @@ package moe.oko.Kiafumi.command; import moe.oko.Kiafumi.util.CommandInfo; +import moe.oko.Kiafumi.util.CommandType; +import moe.oko.Kiafumi.util.EmbedUI; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.List; -public class WhoIsCommand extends CommandClass{ +public class InfoCommand extends CommandClass{ @Override public boolean isEnabled() { return false; } @Override - public String getName() { return "WHOIS"; } + public String getName() { return "Info"; } @Override public void newCommand(String name, SlashCommandInteractionEvent e) { + switch (name){ + case "userinfo": + e.deferReply().queue(); + // Setup variables + final var member = e.getOptions().size() == 0 + ? e.getMember() + : e.getOption("user").getAsMember(); + final var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy"); + + // Build embed + EmbedBuilder eb1 = new EmbedBuilder() + .setColor(EmbedUI.INFO) + .setAuthor(member.getEffectiveName() + "#" + member.getUser().getDiscriminator()) + .addField("Joined Server", member.getTimeJoined().format(dTF), true) + .addField("Joined Discord", member.getTimeCreated().format(dTF), true) + .addField("Roles", member.getRoles().stream().map(Role::getName).reduce((a, b) -> a + ", " + b).orElse("None"), false) + .setThumbnail(member.getEffectiveAvatarUrl()) + .setFooter("ID: " + member.getId()) + .setTimestamp(ZonedDateTime.now()); + e.getHook().sendMessageEmbeds(eb1.build()).queue(); + return; + case "serverinfo": + e.deferReply().queue(); + // Setup variables + final var guild = e.getGuild(); + final var dTF2 = DateTimeFormatter.ofPattern("MM-dd-yyyy"); + + // Build Embed + EmbedBuilder eb2 = new EmbedBuilder() + .setColor(EmbedUI.INFO) + .setAuthor(guild.getName()) + .addField("Members", "**" + guild.getMemberCount() + "** member(s) \n Owner: " + + guild.getOwner().getEffectiveName() + "#" + guild.getOwner().getUser().getDiscriminator(), true) + .addField("Channels", "**" + guild.getTextChannels().size() + "** Text \n **" + + guild.getVoiceChannels().size() + "** Voice", true) + .addField("Other", "Roles: **" + guild.getRoles().size() + "** \n" + + "Created: " + guild.getTimeCreated().format(dTF2), true) + .setThumbnail(guild.getIconUrl()) + .setFooter("ID: " + guild.getId()); + e.getHook().sendMessageEmbeds(eb2.build()).queue(); + + } } @Override public List getSlashCommandInfo() { - return null; + List cil = new ArrayList<>(); + CommandInfo ci = new CommandInfo("userinfo", "Returns information about a user.", CommandType.COMMAND); + ci.addOption("user", "The user to get information about.", OptionType.USER, false); + + CommandInfo ci2 = new CommandInfo("serverinfo", "Returns information about the server.", CommandType.COMMAND); + + cil.add(ci); + cil.add(ci2); + + return cil; } }