use of net.dv8tion.jda.api.interactions.InteractionHook in project Bean by Xirado.
the class LaTeXCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
event.deferReply().queue();
InteractionHook hook = event.getHook();
String formula = event.getOption("formula").getAsString();
TeXFormula tf;
try {
tf = new TeXFormula(formula);
} catch (ParseException exception) {
hook.sendMessageEmbeds(EmbedUtil.errorEmbed("An error occurred while parsing LaTeX formula!\n```\n" + exception.getMessage() + "\n```")).queue();
return;
}
TeXIcon ti = tf.createTeXIcon(TeXConstants.STYLE_DISPLAY, 70);
BufferedImage bimg = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2d = bimg.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, ti.getIconWidth(), ti.getIconHeight());
JLabel jl = new JLabel();
jl.setForeground(new Color(0, 0, 0));
ti.paintIcon(jl, g2d, 0, 0);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ImageIO.write(bimg, "png", baos);
} catch (IOException e) {
hook.sendMessageEmbeds(EmbedUtil.errorEmbed("An error occurred!")).queue();
return;
}
hook.sendMessage("").addFile(baos.toByteArray(), "card.png").queue();
}
use of net.dv8tion.jda.api.interactions.InteractionHook in project Bean by Xirado.
the class RankCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
InteractionHook commandHook = event.getHook();
event.deferReply(false).queue();
OptionMapping optionData = event.getOption("user");
User user = optionData == null ? event.getUser() : optionData.getAsUser();
long xp = RankingSystem.getTotalXP(event.getGuild().getIdLong(), user.getIdLong());
if (xp < 100) {
if (optionData == null)
commandHook.sendMessage("You are not yet ranked!").queue();
else
commandHook.sendMessage("This member is not yet ranked!").queue();
return;
}
byte[] rankCard = RankingSystem.generateLevelCard(user, event.getGuild());
if (rankCard == null) {
commandHook.sendMessageEmbeds(EmbedUtil.errorEmbed("Could not load rank card! Please try again later!")).queue();
return;
}
commandHook.sendFile(rankCard, "card.png").queue();
}
use of net.dv8tion.jda.api.interactions.InteractionHook in project GeyserDiscordBot by GeyserMC.
the class LevelCommand method execute.
@Override
protected void execute(SlashCommandEvent event) {
Member member = event.optMember("member", event.getMember());
// Defer to wait for us to load a response and allows for files to be uploaded
InteractionHook interactionHook = event.deferReply().complete();
File levelFile = handle(member);
interactionHook.editOriginal(levelFile).queue(message -> levelFile.delete());
}
use of net.dv8tion.jda.api.interactions.InteractionHook in project JDA by DV8FromTheWorld.
the class SlashBotExample method ban.
public void ban(SlashCommandInteractionEvent event, User user, Member member) {
// Let the user know we received the command before doing anything else
event.deferReply(true).queue();
// This is a special webhook that allows you to send messages without having permissions in the channel and also allows ephemeral messages
InteractionHook hook = event.getHook();
// All messages here will now be ephemeral implicitly
hook.setEphemeral(true);
if (!event.getMember().hasPermission(Permission.BAN_MEMBERS)) {
hook.sendMessage("You do not have the required permissions to ban users from this server.").queue();
return;
}
Member selfMember = event.getGuild().getSelfMember();
if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) {
hook.sendMessage("I don't have the required permissions to ban users from this server.").queue();
return;
}
if (member != null && !selfMember.canInteract(member)) {
hook.sendMessage("This user is too powerful for me to ban.").queue();
return;
}
// optional command argument, fall back to 0 if not provided
// this last part is a method reference used to "resolve" the option value
int delDays = event.getOption("del_days", 0, OptionMapping::getAsInt);
// optional ban reason with a lazy evaluated fallback (supplier)
String reason = event.getOption("reason", // used if getOption("reason") is null (not provided)
() -> "Banned by " + event.getUser().getAsTag(), // used if getOption("reason") is not null (provided)
OptionMapping::getAsString);
// Ban the user and send a success response
event.getGuild().ban(user, delDays, reason).reason(// audit-log reason
reason).flatMap(v -> hook.sendMessage("Banned user " + user.getAsTag())).queue();
}
use of net.dv8tion.jda.api.interactions.InteractionHook in project JavaBot by Java-Discord.
the class HelpChannelManager method sendThanksButtonsMessage.
private void sendThanksButtonsMessage(List<Member> potentialHelpers, ChannelReservation reservation, Interaction interaction, TextChannel channel) {
List<ItemComponent> thanksButtons = new ArrayList<>(25);
for (var helper : potentialHelpers.subList(0, Math.min(potentialHelpers.size(), 20))) {
thanksButtons.add(new ButtonImpl("help-thank:" + reservation.getId() + ":" + helper.getId(), helper.getEffectiveName(), ButtonStyle.SUCCESS, false, Emoji.fromUnicode("❤")));
}
ActionRow controlsRow = ActionRow.of(new ButtonImpl("help-thank:" + reservation.getId() + ":done", "Unreserve", ButtonStyle.PRIMARY, false, Emoji.fromUnicode("✅")), new ButtonImpl("help-thank:" + reservation.getId() + ":cancel", "Cancel", ButtonStyle.SECONDARY, false, Emoji.fromUnicode("❌")));
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!");
}
hook.sendMessage(THANK_MESSAGE_TEXT).setEphemeral(true).queue();
List<ActionRow> rows = new ArrayList<>(5);
rows.add(controlsRow);
rows.addAll(MessageActionUtils.toActionRows(thanksButtons));
channel.sendMessage(THANK_MESSAGE_TEXT).setActionRows(rows).queue();
}
Aggregations