use of com.jagrosh.jdautilities.command.SlashCommandEvent in project MMDBot by MinecraftModDevelopment.
the class CmdCommunityChannel method execute.
/**
* Execute.
*
* @param event The {@link SlashCommandEvent CommandEvent} that triggered this Command.
*/
@Override
protected void execute(final SlashCommandEvent event) {
if (!Utils.checkCommand(this, event)) {
return;
}
final var guild = event.getGuild();
final var author = guild.getMember(event.getUser());
if (author == null) {
return;
}
Member user = event.getOption("user").getAsMember();
String channel = event.getOption("channel").getAsString();
final var categoryID = MMDBot.getConfig().getCommunityChannelCategory();
final var category = guild.getCategoryById(categoryID);
if (categoryID == 0 || category == null) {
MMDBot.LOGGER.warn("Community channel category is incorrectly configured");
event.reply("Community channel category is incorrectly configured. Please contact the bot maintainers.").queue();
return;
}
final Set<Permission> ownerPermissions = MMDBot.getConfig().getCommunityChannelOwnerPermissions();
if (ownerPermissions.isEmpty()) {
MMDBot.LOGGER.warn("Community channel owner permissions is incorrectly configured");
event.reply("Channel owner permissions is incorrectly configured. Please contact the bot maintainers.").queue();
return;
}
final Set<Permission> diff = Sets.difference(ownerPermissions, event.getGuild().getSelfMember().getPermissions());
if (!diff.isEmpty()) {
MMDBot.LOGGER.warn("Cannot assign permissions to channel owner due to insufficient permissions: {}", diff);
event.reply("Cannot assign certain permissions to channel owner due to insufficient permissions; " + "continuing anyway...").queue();
ownerPermissions.removeIf(diff::contains);
}
final List<Emote> emote = new ArrayList<>(4);
emote.addAll(guild.getEmotesByName("mmd1", true));
emote.addAll(guild.getEmotesByName("mmd2", true));
emote.addAll(guild.getEmotesByName("mmd3", true));
emote.addAll(guild.getEmotesByName("mmd4", true));
// Flavor text: if the emotes are available, use them, else just use plain MMD
final var emoteText = emote.size() == 4 ? emote.stream().map(Emote::getAsMention).collect(Collectors.joining()) : "";
final var flavorText = emoteText.isEmpty() ? "MMD" : emoteText;
MMDBot.LOGGER.info("Creating new community channel for {} ({}), named \"{}\" (command issued by {} ({}))", user.getEffectiveName(), user.getUser().getName(), channel, author.getEffectiveName(), author.getUser().getName());
category.createTextChannel(channel).flatMap(ch -> category.modifyTextChannelPositions().sortOrder(Comparator.comparing(GuildChannel::getName)).map($ -> ch)).flatMap(ch -> ch.putPermissionOverride(user).setAllow(ownerPermissions).map($ -> ch)).flatMap(ch -> ch.sendMessage(new MessageBuilder().appendFormat("Welcome %s to your new community channel, %s!%n", user.getAsMention(), ch.getAsMention()).append('\n').append("Please adhere to the Code of Conduct of the server").appendFormat(" (which can be visited from the <#%s> channel),", MMDBot.getConfig().getChannel("info.rules")).append(" specifically the Channel Policy section.").append('\n').append('\n').appendFormat("Thank you, and enjoy your new home here at %s!", flavorText).build()).map($ -> ch)).queue(c -> event.reply("Successfully created community channel at " + c.getAsMention() + "!").queue());
}
use of com.jagrosh.jdautilities.command.SlashCommandEvent in project MMDBot by MinecraftModDevelopment.
the class CmdAddTrick method execute.
@Override
protected void execute(final SlashCommandEvent event) {
if (!Utils.checkCommand(this, event)) {
return;
}
if (!event.isFromGuild()) {
event.deferReply(true).setContent("This command only works in a guild!").queue();
return;
}
if (!Utils.memberHasRole(event.getMember(), MMDBot.getConfig().getRole("bot_maintainer"))) {
event.deferReply(true).setContent("Only Bot Maintainers can use this command.").queue();
return;
}
Trick trick = trickType.createFromCommand(event);
Optional<Trick> originalTrick = Tricks.getTricks().stream().filter(t -> t.getNames().stream().anyMatch(n -> trick.getNames().contains(n))).findAny();
originalTrick.ifPresentOrElse(original -> {
Tricks.replaceTrick(original, trick);
event.reply("Updated trick!").mentionRepliedUser(false).setEphemeral(true).queue();
}, () -> {
Tricks.addTrick(trick);
event.reply("Added trick!").mentionRepliedUser(false).setEphemeral(true).queue();
});
}
Aggregations