diff --git a/core/src/api/java/sciwhiz12/janitor/api/module/ModuleKey.java b/core/src/api/java/sciwhiz12/janitor/api/module/ModuleKey.java index 837c53f..de35bee 100644 --- a/core/src/api/java/sciwhiz12/janitor/api/module/ModuleKey.java +++ b/core/src/api/java/sciwhiz12/janitor/api/module/ModuleKey.java @@ -3,16 +3,19 @@ package sciwhiz12.janitor.api.module; import com.google.common.base.Preconditions; import java.util.Objects; +import javax.annotation.Nullable; public class ModuleKey { private final String moduleID; + private final String moduleName; private final Class type; - public ModuleKey(String storageID, Class type) { + public ModuleKey(String storageID, @Nullable String moduleName, Class type) { Preconditions.checkNotNull(storageID, "Module ID must not be null"); Preconditions.checkArgument(!storageID.isBlank(), "Module ID must not be empty or blank"); Preconditions.checkNotNull(type, "Class type must not be null"); this.moduleID = storageID; + this.moduleName = Objects.requireNonNullElse(moduleName, moduleID); this.type = type; } @@ -20,6 +23,10 @@ public class ModuleKey { return moduleID; } + public String getModuleName() { + return moduleName; + } + public Class getType() { return type; } diff --git a/core/src/api/java/sciwhiz12/janitor/api/utils/MessageHelper.java b/core/src/api/java/sciwhiz12/janitor/api/utils/MessageHelper.java index 18c9b48..d3195be 100644 --- a/core/src/api/java/sciwhiz12/janitor/api/utils/MessageHelper.java +++ b/core/src/api/java/sciwhiz12/janitor/api/utils/MessageHelper.java @@ -44,6 +44,7 @@ public final class MessageHelper { .with(head + ".name", user::getName) .with(head + ".discriminator", user::getDiscriminator) .with(head + ".tag", user::getAsTag) + .with(head + ".avatar", user::getAvatarUrl) .with(head + ".flags", user.getFlags()::toString); } diff --git a/core/src/main/java/sciwhiz12/janitor/commands/CommandRegistryImpl.java b/core/src/main/java/sciwhiz12/janitor/commands/CommandRegistryImpl.java index aad3350..9342f4d 100644 --- a/core/src/main/java/sciwhiz12/janitor/commands/CommandRegistryImpl.java +++ b/core/src/main/java/sciwhiz12/janitor/commands/CommandRegistryImpl.java @@ -3,6 +3,8 @@ package sciwhiz12.janitor.commands; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.dv8tion.jda.api.events.GenericEvent; @@ -13,6 +15,7 @@ import sciwhiz12.janitor.JanitorBotImpl; import sciwhiz12.janitor.api.command.Command; import sciwhiz12.janitor.api.command.CommandRegistry; import sciwhiz12.janitor.api.config.CoreConfigs; +import sciwhiz12.janitor.commands.bot.AboutCommand; import sciwhiz12.janitor.commands.bot.ShutdownCommand; import sciwhiz12.janitor.commands.misc.HelloCommand; import sciwhiz12.janitor.commands.misc.OKCommand; @@ -25,6 +28,8 @@ import java.util.function.Function; import static sciwhiz12.janitor.api.Logging.COMMANDS; import static sciwhiz12.janitor.api.Logging.JANITOR; +import static sciwhiz12.janitor.api.utils.CommandHelper.argument; +import static sciwhiz12.janitor.api.utils.CommandHelper.literal; public class CommandRegistryImpl implements CommandRegistry, EventListener { private final JanitorBotImpl bot; @@ -40,6 +45,7 @@ public class CommandRegistryImpl implements CommandRegistry, EventListener { addCommand(OKCommand::new); addCommand(HelloCommand::new); addCommand(ShutdownCommand::new); + addCommand(AboutCommand::new); addCommand((reg) -> new CmdListCommand((CommandRegistryImpl) reg)); } diff --git a/core/src/main/java/sciwhiz12/janitor/commands/bot/AboutCommand.java b/core/src/main/java/sciwhiz12/janitor/commands/bot/AboutCommand.java new file mode 100644 index 0000000..32e49e5 --- /dev/null +++ b/core/src/main/java/sciwhiz12/janitor/commands/bot/AboutCommand.java @@ -0,0 +1,43 @@ +package sciwhiz12.janitor.commands.bot; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import sciwhiz12.janitor.JanitorBotImpl; +import sciwhiz12.janitor.api.command.BaseCommand; +import sciwhiz12.janitor.api.command.CommandRegistry; +import sciwhiz12.janitor.api.module.ModuleKey; +import sciwhiz12.janitor.api.utils.MessageHelper; + +import java.util.Objects; +import java.util.stream.Collectors; + +import static sciwhiz12.janitor.api.config.CoreConfigs.COMMAND_PREFIX; +import static sciwhiz12.janitor.api.utils.CommandHelper.literal; + +public class AboutCommand extends BaseCommand { + public AboutCommand(CommandRegistry registry) { + super(registry); + } + + @Override + public LiteralArgumentBuilder getNode() { + return literal("about") + .executes(ctx -> { + Package pkg = JanitorBotImpl.class.getPackage(); + messages().getRegularMessage("general/about") + .with("bot.name", () -> Objects.requireNonNullElse(pkg.getImplementationTitle(), "Janitor")) + .with("bot.version", () -> Objects.requireNonNullElse(pkg.getImplementationVersion(), "in-dev")) + .with("bot.guild_count", () -> String.valueOf(getBot().getDiscord().getGuilds().size())) + .with("bot.modules.count", () -> String.valueOf(getBot().getModuleManager().getActiveModules().size())) + .with("bot.modules.names", + () -> getBot().getModuleManager().getActiveModules().stream() + .map(ModuleKey::getModuleName) + .collect(Collectors.joining(", ")) + ) + .apply(MessageHelper.member("bot.member", ctx.getSource().getGuild().getSelfMember())) + .with("guild.command_prefix", () -> config(ctx.getSource()).forGuild(COMMAND_PREFIX)) + .send(getBot(), ctx.getSource().getChannel()).queue(); + return 1; + }); + } +} diff --git a/core/src/main/java/sciwhiz12/janitor/messages/RegularMessageBuilder.java b/core/src/main/java/sciwhiz12/janitor/messages/RegularMessageBuilder.java index a590d7d..3361fba 100644 --- a/core/src/main/java/sciwhiz12/janitor/messages/RegularMessageBuilder.java +++ b/core/src/main/java/sciwhiz12/janitor/messages/RegularMessageBuilder.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; +import javax.annotation.Nullable; public class RegularMessageBuilder implements RegularMessage.Builder { private final RegularMessage message; @@ -74,7 +75,7 @@ public class RegularMessageBuilder implements RegularMessage.Builder ID = new ModuleKey<>("moderation", ModerationModule.class); + ModuleKey ID = new ModuleKey<>("moderation", "Moderation", ModerationModule.class); NoteStorage getNotes(Guild guild);