Skip to content

Commit

Permalink
Added a way to get the Classloader of Addons and add an Avatar command!
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Jan 3, 2024
1 parent 9ba7548 commit 511a1b8
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
1 change: 1 addition & 0 deletions languages/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/de/presti/ree6/addons/Addon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/presti/ree6/addons/AddonLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/de/presti/ree6/commands/impl/info/Avatar.java
Original file line number Diff line number Diff line change
@@ -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) ? " <a:duckswing:1070690323459735682>" : ""), member.getEffectiveAvatarUrl());
em.setImage(member.getEffectiveAvatarUrl());
em.setFooter("Requested by " + commandEvent.getMember().getEffectiveName() + " - " + BotConfig.getAdvertisement(), commandEvent.getMember().getEffectiveAvatarUrl());

commandEvent.reply(em.build());
}
}
3 changes: 2 additions & 1 deletion src/main/java/de/presti/ree6/utils/others/UserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 511a1b8

Please sign in to comment.