use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project OrderlyDiscordBot by IceLeiYu.
the class MusicBot method displayQueue.
public void displayQueue(GenericInteractionCreateEvent event, boolean search, Guild guild, SelectMenuInteractionEvent SelectMenuInteractionEvent) {
List<String> lang = Main.language.getGuildLang(guild.getId());
GuildMusicManager musicManager = getMusicManager(guild);
TrackScheduler scheduler = musicManager.scheduler;
if (scheduler.musicInfo == null) {
try {
if (event instanceof SelectMenuInteractionEvent)
((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_MUSIC), 0xFF0000)).queue();
} catch (Exception ignored) {
}
return;
}
scheduler.calculatePauseTime();
MessageEmbed[] embed = playStatus(event.getMember(), scheduler);
if (musicManager.guild.getSelfMember().getVoiceState().getChannel() == null) {
if (search)
SelectMenuInteractionEvent.replyEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).setEphemeral(true).queue();
else {
if (event instanceof SelectMenuInteractionEvent)
((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
else if (event instanceof SlashCommandInteractionEvent)
((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
}
return;
}
String vcID = musicManager.guild.getSelfMember().getVoiceState().getChannel().getId();
if (search) {
SelectMenuInteractionEvent.replyEmbeds(embed[0], embed[1]).setEphemeral(true).addActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
} else {
if (event instanceof SelectMenuInteractionEvent)
((SelectMenuInteractionEvent) event).getHook().editOriginalComponents().setEmbeds(embed[0], embed[1]).setActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
else if (event instanceof SlashCommandInteractionEvent)
((SlashCommandInteractionEvent) event).getHook().editOriginalComponents().setEmbeds(embed[0], embed[1]).setActionRows(controlButtons(event.getMember().getId(), scheduler.musicPause, scheduler.loopStatus, vcID)).queue();
}
if (event.getGuild().getId().equals("882605953382514718"))
event.getGuild().getTextChannelById("884070398742888478").sendMessageEmbeds(embed[0], embed[1]).setActionRows(controlButtons("", scheduler.musicPause, scheduler.loopStatus, vcID)).content(event.getUser().getAsTag()).queue();
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project OrderlyDiscordBot by IceLeiYu.
the class MusicBot method connectVC.
@SuppressWarnings("ALL")
private void connectVC(Guild guild, VoiceChannel vc, GenericInteractionCreateEvent event, Consumer consumer) {
if (!guild.getAudioManager().isConnected()) {
try {
guild.getAudioManager().openAudioConnection(vc);
} catch (Exception e) {
List<String> lang = Main.language.getGuildLang(event.getGuild().getId());
if (event instanceof SelectMenuInteractionEvent)
((SelectMenuInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
else if (event instanceof SlashCommandInteractionEvent)
((SlashCommandInteractionEvent) event).getHook().editOriginalEmbeds(createEmbed(lang.get(MUSICBOT_NO_CONNECT_PERMISSION), 0xFF0000)).queue();
return;
}
final MusicBot bot = this;
guild.getAudioManager().setConnectionListener(new ConnectionListener() {
@Override
public void onStatusChange(ConnectionStatus connectionStatus) {
if (connectionStatus == ConnectionStatus.CONNECTED) {
consumer.accept(null);
if (workCount == 0) {
jda.getPresence().setStatus(OnlineStatus.DO_NOT_DISTURB);
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.COMPETING, "來點歌吧!"));
}
workCount++;
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.LISTENING, workCount + " 個頻道"));
guild.getAudioManager().setConnectionListener(null);
// 新增bot到頻道
musicBotManager.setBotToChannel(guild.getId(), vc.getId(), bot);
if (guild.getSelfMember().getPermissions().contains(Permission.VOICE_DEAF_OTHERS))
guild.getSelfMember().deafen(true).queue();
}
}
@Override
public void onPing(long l) {
}
@Override
public void onUserSpeaking(User user, boolean b) {
}
});
} else
consumer.accept(null);
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project JavaBot by Java-Discord.
the class HelpChannelManager method unreserveChannelByOwner.
private void unreserveChannelByOwner(TextChannel channel, User owner, Interaction interaction) {
var optionalReservation = getReservationForChannel(channel.getIdLong());
if (optionalReservation.isEmpty()) {
log.warn("Could not find current reservation data for channel {}. Unreserving the channel without thanks.", channel.getAsMention());
unreserveChannel(channel);
return;
}
var reservation = optionalReservation.get();
// Ask the user for some feedback about the help channel, if possible.
getParticipantsSinceReserved(channel).thenAcceptAsync(participants -> {
List<Member> potentialHelpers = new ArrayList<>(participants.size());
for (var entry : participants.entrySet()) {
if (!entry.getKey().getUser().equals(owner))
potentialHelpers.add(entry.getKey());
}
if (potentialHelpers.isEmpty()) {
InteractionHook hook;
if (interaction.getType() == InteractionType.COMPONENT) {
hook = ((ButtonInteractionEvent) interaction).getHook();
} else if (interaction.getType() == InteractionType.COMMAND) {
hook = ((SlashCommandInteractionEvent) interaction).getHook();
} else {
throw new IllegalStateException("Unable to obtain Interaction Hook!");
}
Responses.info(hook, "Channel Unreserved", "Your channel has been unreserved.").queue();
unreserveChannel(channel).queue();
return;
}
potentialHelpers.sort((o1, o2) -> {
int c = Integer.compare(participants.get(o1).size(), participants.get(o2).size());
if (c == 0)
return o1.getEffectiveName().compareTo(o2.getEffectiveName());
return c;
});
sendThanksButtonsMessage(potentialHelpers, reservation, interaction, channel);
try {
setTimeout(channel, 5);
} catch (SQLException e) {
e.printStackTrace();
}
});
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project triumph-cmds by TriumphTeam.
the class SlashCommandListener method onSlashCommandInteraction.
/**
* Handler for the slash commands.
* Needs to map the given result to the correct arguments to be used.
*
* @param event The slash command event.
*/
@Override
public void onSlashCommandInteraction(@NotNull final SlashCommandInteractionEvent event) {
final String name = event.getName();
SlashCommand<S> command = commandManager.getCommand(name);
if (command == null) {
final Guild guild = event.getGuild();
if (guild == null)
return;
command = commandManager.getCommand(guild, name);
}
if (command == null)
return;
final S sender = senderMapper.map(new SlashCommandSender(event));
final String subCommandName = event.getSubcommandName();
final Map<String, String> args = event.getOptions().stream().map(it -> Maps.immutableEntry(it.getName(), it.getAsString())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
command.execute(sender, subCommandName != null ? subCommandName : Default.DEFAULT_CMD_NAME, args);
}
use of net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent in project Bean by Xirado.
the class QueueCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
ButtonPaginator.Builder builder = new ButtonPaginator.Builder(event.getJDA()).setEventWaiter(Bean.getInstance().getEventWaiter()).setItemsPerPage(10).setTimeout(1, TimeUnit.MINUTES);
int page = 1;
if (event.getOption("page") != null)
page = (int) event.getOption("page").getAsLong();
GuildAudioPlayer guildAudioPlayer = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
Queue<AudioTrack> queue = guildAudioPlayer.getScheduler().getQueue();
if (queue.isEmpty()) {
if (guildAudioPlayer.getPlayer().getPlayingTrack() != null) {
if (guildAudioPlayer.getScheduler().isRepeat())
ctx.sendSimpleEmbed("\uD83D\uDD01 **Currently playing** " + Util.titleMarkdown(guildAudioPlayer.getPlayer().getPlayingTrack()));
else
ctx.sendSimpleEmbed("**Currently playing** " + Util.titleMarkdown(guildAudioPlayer.getPlayer().getPlayingTrack()));
} else
ctx.replyError("There is no music playing!").queue();
return;
}
String[] tracks = queue.stream().map(x -> Util.titleMarkdown(x, false) + " (<@" + x.getUserData(TrackInfo.class).getRequesterIdLong() + ">)").toArray(String[]::new);
builder.setTitle(getQueueTitle(guildAudioPlayer)).setItems(tracks).addAllowedUsers(event.getUser().getIdLong()).setColor(Color.decode("#452350"));
int finalPage = page;
event.deferReply().queue(hook -> builder.build().paginate(hook.sendMessage(""), finalPage));
}
Aggregations