AltitudeBot/src/main/java/com/alttd/util/Util.java

58 lines
2.2 KiB
Java
Raw Normal View History

2022-03-09 21:37:44 +00:00
package com.alttd.util;
2022-03-31 20:08:50 +00:00
import com.alttd.config.MessagesConfig;
import com.alttd.templates.Parser;
import com.alttd.templates.Template;
import net.dv8tion.jda.api.EmbedBuilder;
2022-03-09 21:37:44 +00:00
import net.dv8tion.jda.api.entities.Member;
2022-03-31 20:08:50 +00:00
import net.dv8tion.jda.api.entities.MessageEmbed;
2022-03-09 21:37:44 +00:00
import net.dv8tion.jda.api.entities.Role;
2022-03-31 20:08:50 +00:00
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
2022-03-09 21:37:44 +00:00
2022-03-31 20:08:50 +00:00
import java.awt.*;
2022-03-09 21:37:44 +00:00
import java.util.List;
import java.util.stream.Collectors;
public class Util {
public static List<Long> getGroupIds(Member member) {
return member.getRoles().stream()
.map(Role::getIdLong)
.collect(Collectors.toList());
}
2022-03-31 20:08:50 +00:00
public static void handleFailure(Throwable failure) {
Logger.warning(failure.getMessage());
}
public static MessageEmbed guildOnlyCommand(String commandName) {
return new EmbedBuilder()
.setTitle("Guild Only")
.setDescription(Parser.parse(MessagesConfig.GUILD_ONLY_MESSAGE, Template.of("command", commandName)))
.setColor(Color.RED)
.build();
}
public static MessageEmbed noPermission(String commandName) {
return new EmbedBuilder()
.setTitle("No Permission")
.setDescription(Parser.parse(MessagesConfig.NO_PERMISSION_MESSAGE, Template.of("command", commandName)))
.setColor(Color.RED)
.build();
}
public static MessageEmbed invalidCommand(String commandName, String error, SlashCommandInteraction interaction) {
EmbedBuilder embedBuilder = new EmbedBuilder()
.setTitle("Invalid Command")
.setDescription(Parser.parse(MessagesConfig.INVALID_COMMAND_ARGUMENTS,
Template.of("command", commandName),
Template.of("error", error)))
.setColor(Color.RED);
for (OptionMapping option : interaction.getOptions()) {
embedBuilder.addField(option.getName(), option.getAsString(), false);
}
return embedBuilder.build();
}
2022-03-09 21:37:44 +00:00
}