diff --git a/languages/en-GB.yml b/languages/en-GB.yml index 75d3f1129..7146c3355 100644 --- a/languages/en-GB.yml +++ b/languages/en-GB.yml @@ -693,6 +693,7 @@ command: steal: "Steal money from other users!" work: "Get your own money from doing work!" giveaway: "Manage Giveaways!" + avatar: "Get the Avatar of an User!" category: info: "Used to gather information or provide information." moderation: "Moderation Tools that can help you manager Users or prevent rule breaking on the Server." diff --git a/src/main/java/de/presti/ree6/addons/Addon.java b/src/main/java/de/presti/ree6/addons/Addon.java index 45551efb5..0777379d6 100644 --- a/src/main/java/de/presti/ree6/addons/Addon.java +++ b/src/main/java/de/presti/ree6/addons/Addon.java @@ -79,6 +79,14 @@ public File getFile() { return file; } + /** + * Get the ClassLoader of the Addon. + * @return ClassLoader. + */ + public ClassLoader getClassLoader() { + return addonInterface.getClass().getClassLoader(); + } + /** * Get everything in a single String. * diff --git a/src/main/java/de/presti/ree6/addons/AddonLoader.java b/src/main/java/de/presti/ree6/addons/AddonLoader.java index 4c1418b12..c7fc64c39 100644 --- a/src/main/java/de/presti/ree6/addons/AddonLoader.java +++ b/src/main/java/de/presti/ree6/addons/AddonLoader.java @@ -151,7 +151,7 @@ public static Addon loadAddon(String fileName) throws IOException { // Get the Addon Class. Class addonClass = getClass(urlClassLoader, classPath); - // If valid call the onEnable methode. + // If valid, call the onEnable methode. if (addonClass != null) { log.info("[AddonManager] Loaded {} ({}) by {}", name, version, author); addonInterface = (AddonInterface) addonClass.getDeclaredConstructor().newInstance(); diff --git a/src/main/java/de/presti/ree6/commands/impl/info/Avatar.java b/src/main/java/de/presti/ree6/commands/impl/info/Avatar.java new file mode 100644 index 000000000..05bf7dd5b --- /dev/null +++ b/src/main/java/de/presti/ree6/commands/impl/info/Avatar.java @@ -0,0 +1,83 @@ +package de.presti.ree6.commands.impl.info; + +import de.presti.ree6.bot.BotConfig; +import de.presti.ree6.commands.Category; +import de.presti.ree6.commands.CommandEvent; +import de.presti.ree6.commands.interfaces.Command; +import de.presti.ree6.commands.interfaces.ICommand; +import de.presti.ree6.language.LanguageService; +import de.presti.ree6.utils.others.UserUtil; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.CommandData; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.internal.interactions.CommandDataImpl; + +/** + * Allows you to get the profile picture of anyone. + */ +@Command(name = "avatar", description = "command.description.avatar", category = Category.INFO) +public class Avatar implements ICommand { + + /** + * @inheritDoc + */ + @Override + public void onPerform(CommandEvent commandEvent) { + if (commandEvent.isSlashCommand()) { + OptionMapping targetOption = commandEvent.getOption("target"); + + if (targetOption != null && targetOption.getAsMember() != null) { + sendAvatar(targetOption.getAsUser(), commandEvent); + } else { + sendAvatar(commandEvent.getMember().getUser(), commandEvent); + } + + } else { + if (commandEvent.getArguments().length == 1) { + if (commandEvent.getMessage().getMentions().getUsers().isEmpty()) { + commandEvent.reply(commandEvent.getResource("message.default.noMention.user"), 5); + commandEvent.reply(commandEvent.getResource("message.default.usage","avatar @user"), 5); + } else { + sendAvatar(commandEvent.getMessage().getMentions().getUsers().get(0), commandEvent); + } + } else { + sendAvatar(commandEvent.getMember().getUser(), commandEvent); + } + } + } + + /** + * @inheritDoc + */ + @Override + public CommandData getCommandData() { + return new CommandDataImpl("avatar", LanguageService.getDefault("command.description.avatar")) + .addOptions(new OptionData(OptionType.USER, "target", "The User whose profile you want.").setRequired(true)); + } + + /** + * @inheritDoc + */ + @Override + public String[] getAlias() { + return new String[0]; + } + + /** + * Sends the Profile picture of a User. + * @param member The User to get the Profile from. + * @param commandEvent The CommandEvent. + */ + public void sendAvatar(User member, CommandEvent commandEvent) { + EmbedBuilder em = new EmbedBuilder(); + + em.setTitle(member.getEffectiveName() + (UserUtil.isSupporter(member) ? " " : ""), member.getEffectiveAvatarUrl()); + em.setImage(member.getEffectiveAvatarUrl()); + em.setFooter("Requested by " + commandEvent.getMember().getEffectiveName() + " - " + BotConfig.getAdvertisement(), commandEvent.getMember().getEffectiveAvatarUrl()); + + commandEvent.reply(em.build()); + } +} diff --git a/src/main/java/de/presti/ree6/utils/others/UserUtil.java b/src/main/java/de/presti/ree6/utils/others/UserUtil.java index 2a22ce2ca..d011c285a 100644 --- a/src/main/java/de/presti/ree6/utils/others/UserUtil.java +++ b/src/main/java/de/presti/ree6/utils/others/UserUtil.java @@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.ISnowflake; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; @@ -224,7 +225,7 @@ private static void addRole(Guild guild, Member member, Role role) { * @param member the User of the current Guild to check. * @return true if the User has supported Ree6 via Donations, false if not. */ - public static boolean isSupporter(Member member) { + public static boolean isSupporter(ISnowflake member) { Guild ree6Guild = BotWorker.getShardManager().getGuildById(805149057004732457L); if (ree6Guild != null) {