<commit_before>package dev.nincodedo.ninbot.components.hugemoji;

import com.vdurmont.emoji.EmojiManager;
import com.vdurmont.emoji.EmojiParser;
import dev.nincodedo.ninbot.common.Emojis;
import dev.nincodedo.ninbot.common.command.slash.SlashCommand;
import dev.nincodedo.ninbot.common.message.MessageExecutor;
import dev.nincodedo.ninbot.common.message.SlashCommandEventMessageExecutor;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class HugemojiCommand implements SlashCommand {

    @Override
    public MessageExecutor<SlashCommandEventMessageExecutor> executeCommandAction(
            @NotNull SlashCommandInteractionEvent slashCommandEvent) {
        var messageExecutor = new SlashCommandEventMessageExecutor(slashCommandEvent);
        var possibleEmoteString = slashCommandEvent.getOption(HugemojiCommandName.Option.EMOTE.get(),
                OptionMapping::getAsString);
        List<Emote> emoteList = new ArrayList<>();
        List<String> emojiList = new ArrayList<>();
        if (EmojiManager.isEmoji(possibleEmoteString)) {
            emojiList = new ArrayList<>(EmojiParser.extractEmojis(possibleEmoteString));
        } else if (possibleEmoteString.contains(":")) {
            var stringEmote = possibleEmoteString.split(":")[1];
            emoteList = slashCommandEvent.getGuild().getEmotesByName(stringEmote, true);
        }
        if (!emoteList.isEmpty()) {
            try {
                var emote = emoteList.get(0);
                var imageFileType = emote.getImageUrl().substring(emote.getImageUrl().lastIndexOf('.'));
                InputStream file = new URL(emote.getImageUrl()).openStream();
                slashCommandEvent.replyEmbeds(new EmbedBuilder().setImage(
                                "attachment://" + emote.getName() + imageFileType).build())
                        .addFile(file, emote.getName() + imageFileType)
                        .queue();
            } catch (IOException e) {
                messageExecutor.addEphemeralMessage(Emojis.CROSS_X);<commit_msg>Fix hugemoji command to send image properly<commit_after>package dev.nincodedo.ninbot.components.hugemoji;

import com.vdurmont.emoji.EmojiManager;
import com.vdurmont.emoji.EmojiParser;
import dev.nincodedo.ninbot.common.Emojis;
import dev.nincodedo.ninbot.common.command.slash.SlashCommand;
import dev.nincodedo.ninbot.common.message.MessageExecutor;
import dev.nincodedo.ninbot.common.message.SlashCommandEventMessageExecutor;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class HugemojiCommand implements SlashCommand {

    @Override
    public MessageExecutor<SlashCommandEventMessageExecutor> executeCommandAction(
            @NotNull SlashCommandInteractionEvent slashCommandEvent) {
        var messageExecutor = new SlashCommandEventMessageExecutor(slashCommandEvent);
        var possibleEmoteString = slashCommandEvent.getOption(HugemojiCommandName.Option.EMOTE.get(),
                OptionMapping::getAsString);
        List<Emote> emoteList = new ArrayList<>();
        List<String> emojiList = new ArrayList<>();
        if (EmojiManager.isEmoji(possibleEmoteString)) {
            emojiList = new ArrayList<>(EmojiParser.extractEmojis(possibleEmoteString));
        } else if (possibleEmoteString.contains(":")) {
            var stringEmote = possibleEmoteString.split(":")[1];
            emoteList = slashCommandEvent.getGuild().getEmotesByName(stringEmote, true);
        }
        if (!emoteList.isEmpty()) {
            try {
                var emote = emoteList.get(0);
                var imageFileType = emote.getImageUrl().substring(emote.getImageUrl().lastIndexOf('.'));
                InputStream file = new URL(emote.getImageUrl()).openStream();
                slashCommandEvent.replyFile(file, emote.getName() + imageFileType).queue();
            } catch (IOException e) {
                messageExecutor.addEphemeralMessage(Emojis.CROSS_X);
{'fraction_non_alphanumeric': 0.10490894695170229, 'fraction_numerical': 0.004156769596199525, 'mean_word_length': 3.807802093244529, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7323374', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1499, 'n_words': 221}