use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Bean by Xirado.
the class BanCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
Member sender = event.getMember();
Guild guild = event.getGuild();
if (guild == null) {
LOGGER.error("Received /ban command with empty guild!");
return;
}
User targetUser = event.getOption("user").getAsUser();
Member targetMember = event.getOption("user").getAsMember();
String reason = event.getOption("reason") == null ? null : event.getOption("reason").getAsString();
int delDays = event.getOption("del_days") != null ? (int) Math.max(0, Math.min(7, event.getOption("del_days").getAsLong())) : 0;
if (targetMember != null) {
if (sender.getIdLong() == targetMember.getIdLong()) {
ctx.reply(EmbedUtil.errorEmbed(ctx.getLocalized("commands.ban.cannot_ban_self"))).setEphemeral(true).queue();
return;
}
if (!sender.canInteract(targetMember)) {
ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.ban.you_cannot_ban_this_member"))).setEphemeral(true).queue();
return;
}
if (ctx.getGuildData().isModerator(targetMember)) {
ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.ban.cannot_ban_moderator"))).setEphemeral(true).queue();
return;
}
if (!guild.getSelfMember().canInteract(targetMember)) {
ctx.reply(EmbedUtil.noEntryEmbed(ctx.getLocalized("commands.ban.i_cannot_ban_this_member"))).setEphemeral(true).queue();
return;
}
}
String reasonString = reason == null ? ctx.getLocalized("commands.noreason") : reason;
EmbedBuilder dmEmbed = new EmbedBuilder().setColor(CaseType.BAN.getEmbedColor()).setAuthor(ctx.getLocalized("commands.ban.you_have_been_banned", guild.getName()), null, guild.getIconUrl()).addField("Moderator", sender.getAsMention() + " (" + sender.getUser().getAsTag() + ")", true);
if (reason != null)
dmEmbed.addField(ctx.getLocalized("commands.reason"), reasonString, true);
event.deferReply(true).flatMap(hook -> targetUser.openPrivateChannel()).flatMap((c) -> c.sendMessageEmbeds(dmEmbed.build())).mapToResult().flatMap((result) -> guild.ban(targetUser, delDays, reason)).queue((x) -> {
ModCase modCase = ModCase.createModCase(CaseType.BAN, guild.getIdLong(), targetUser.getIdLong(), sender.getIdLong(), reason);
MessageEmbed confirmationEmbed = new EmbedBuilder().setColor(EmbedUtil.SUCCESS_COLOR).setAuthor(ctx.getLocalized("commands.ban.has_been_banned", targetUser.getAsTag()), null, targetUser.getEffectiveAvatarUrl()).addField(ctx.getLocalized("commands.reason"), reasonString, true).addField(ctx.getLocalized("commands.duration"), "∞", true).build();
event.getHook().sendMessageEmbeds(confirmationEmbed).queue();
if (ctx.getGuildData().getLogChannel() != null) {
TextChannel logChannel = ctx.getGuildData().getLogChannel();
MessageEmbed logEmbed = new EmbedBuilder().setColor(CaseType.BAN.getEmbedColor()).setAuthor("Ban • " + targetUser.getAsTag(), null, targetUser.getEffectiveAvatarUrl()).addField(ctx.getLocalized("commands.reason"), reasonString, true).addField("Moderator", sender.getAsMention() + " (" + sender.getUser().getAsTag() + ")", true).addField(ctx.getLocalized("commands.duration"), "∞", true).setFooter(ctx.getLocalized("commands.user_id", targetUser.getIdLong())).build();
logChannel.sendMessageEmbeds(logEmbed).queue(s -> {
}, e -> {
});
}
}, e -> event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed(ctx.getLocalized("general.unknown_error_occured"))).setEphemeral(true).queue());
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Bean by Xirado.
the class UnbanCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
Guild guild = event.getGuild();
if (guild == null)
return;
User user = event.getOption("user").getAsUser();
event.deferReply(true).flatMap(ban -> guild.unban(user)).flatMap(ban -> event.getHook().sendMessageEmbeds(EmbedUtil.successEmbed(user.getAsTag() + " has been unbanned!"))).queue(null, new ErrorHandler().handle(ErrorResponse.UNKNOWN_BAN, (e) -> event.getHook().sendMessageEmbeds(EmbedUtil.errorEmbed("This user is not banned!")).queue()));
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Bean by Xirado.
the class PlayerCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
GuildAudioPlayer player = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
AudioTrack track = player.getPlayer().getPlayingTrack();
boolean isRepeat = player.getScheduler().isRepeat();
boolean isPaused = player.getPlayer().isPaused();
event.reply("One moment...").queue(x -> player.playerSetup((GuildMessageChannel) event.getChannel(), (success) -> event.getHook().deleteOriginal().queue(), (error) -> event.reply("An error occurred!").setEphemeral(true).queue()));
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project LightboltMeeting by LightboltMeeting.
the class RemoveAdminSubcommand method handleMeetingCommand.
@Override
protected ReplyCallbackAction handleMeetingCommand(SlashCommandInteractionEvent event, LocaleConfig locale, SystemsConfig.MeetingConfig config, MeetingRepository repo) throws SQLException {
var idOption = event.getOption("meeting-id");
var userOption = event.getOption("user");
if (userOption == null || idOption == null) {
return Responses.error(event, locale.getCommand().getMISSING_ARGUMENTS());
}
var id = (int) idOption.getAsLong();
var user = userOption.getAsUser();
var com = locale.getMeeting().getCommand();
var meetings = repo.getByUserId(event.getUser().getIdLong());
Optional<Meeting> meetingOptional = meetings.stream().filter(m -> m.getId() == id).findFirst();
if (meetingOptional.isEmpty()) {
return Responses.error(event, String.format(com.getMEETING_NOT_FOUND(), id));
}
var meeting = meetingOptional.get();
var admins = meeting.getAdmins();
if (Arrays.stream(admins).anyMatch(x -> x == user.getIdLong())) {
new MeetingManager(event.getJDA(), meeting).removeAdmin(user);
return Responses.success(event, com.getADMINS_REMOVE_SUCCESS_TITLE(), String.format(com.getADMINS_REMOVE_SUCCESS_DESCRIPTION(), user.getAsMention(), meeting.getTitle()));
} else {
return Responses.error(event, String.format(com.getMEETING_ADMIN_NOT_FOUND(), user.getAsMention()));
}
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Ninbot by Nincodedo.
the class SlashCommandEventMessageExecutorTest method executeFiveMessageAction.
@Test
void executeFiveMessageAction() {
SlashCommandInteractionEvent slashCommandEvent = Mockito.mock(SlashCommandInteractionEvent.class);
ReplyCallbackAction replyAction = Mockito.mock(ReplyCallbackAction.class);
when(slashCommandEvent.reply(any(Message.class))).thenReturn(replyAction);
messageExecutor = new SlashCommandEventMessageExecutor(slashCommandEvent);
messageExecutor.addMessageResponse("wow");
messageExecutor.addMessageResponse("wooow");
messageExecutor.addMessageResponse("wooooow");
messageExecutor.addMessageResponse("wooow");
messageExecutor.addMessageResponse("wow");
messageExecutor.executeActions();
verify(slashCommandEvent, times(5)).reply(any(Message.class));
}
Aggregations