Search in sources :

Example 1 with AnimeData

use of net.kodehawa.mantarobot.commands.anime.AnimeData in project MantaroBot by Mantaro.

the class AnimeCmds method anime.

@Subscribe
public void anime(CommandRegistry cr) {
    cr.register("anime", new SimpleCommand(Category.FUN) {

        @Override
        public void call(GuildMessageReceivedEvent event, String content, String[] args) {
            try {
                if (content.isEmpty()) {
                    onHelp(event);
                    return;
                }
                String connection = String.format("https://anilist.co/api/anime/search/%1s?access_token=%2s", URLEncoder.encode(content, "UTF-8"), authToken);
                String json = Utils.wgetResty(connection, event);
                AnimeData[] type = AnimeData.fromJson(json);
                if (type.length == 1) {
                    animeData(event, type[0]);
                    return;
                }
                DiscordUtils.selectList(event, type, anime -> String.format("**[%s (%s)](%s)**", anime.getTitleEnglish(), anime.getTitleJapanese(), "http://anilist.co/anime/" + anime.getId()), s -> baseEmbed(event, "Type the number of the anime you want to select.").setDescription(s).setThumbnail("https://anilist.co/img/logo_al.png").setFooter("Information provided by Anilist. Type &cancel to cancel.", event.getAuthor().getAvatarUrl()).build(), anime -> animeData(event, anime));
            } catch (JsonSyntaxException jsonException) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "No results found...").queue();
            } catch (NullPointerException nullException) {
                event.getChannel().sendMessage(EmoteReference.ERROR + "We got a wrong API result for this specific search. Maybe try another one?").queue();
            } catch (Exception exception) {
                event.getChannel().sendMessage(String.format("%s**I swear I didn't drop your favorite anime!**\n We received a ``%s`` while trying to process the command.", EmoteReference.ERROR, exception.getClass().getSimpleName())).queue();
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Anime command").setDescription("**Get anime info from AniList (For anime characters use ~>character).**").addField("Usage", "`~>anime <animename>` - **Retrieve information of an anime based on the name.**", false).addField("Parameters", "`animename` - **The name of the anime you are looking for. Keep queries similar to their english names!**", false).setColor(Color.PINK).build();
        }
    });
    cr.registerAlias("anime", "animu");
}
Also used : Module(net.kodehawa.mantarobot.core.modules.Module) Async(br.com.brjdevs.java.utils.async.Async) CharacterData(net.kodehawa.mantarobot.commands.anime.CharacterData) Utils(net.kodehawa.mantarobot.utils.Utils) DiscordUtils(net.kodehawa.mantarobot.utils.DiscordUtils) StringUtils(org.apache.commons.lang3.StringUtils) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) JSONObject(org.json.JSONObject) CommandRegistry(net.kodehawa.mantarobot.core.CommandRegistry) okhttp3(okhttp3) Subscribe(com.google.common.eventbus.Subscribe) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) JsonSyntaxException(com.google.gson.JsonSyntaxException) Category(net.kodehawa.mantarobot.core.modules.commands.base.Category) SentryHelper(net.kodehawa.mantarobot.utils.SentryHelper) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) URLEncoder(java.net.URLEncoder) List(java.util.List) AnimeData(net.kodehawa.mantarobot.commands.anime.AnimeData) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) MantaroData(net.kodehawa.mantarobot.data.MantaroData) LogUtils(net.kodehawa.mantarobot.log.LogUtils) PreLoadEvent(net.kodehawa.mantarobot.core.listeners.events.PreLoadEvent) Collections(java.util.Collections) JsonSyntaxException(com.google.gson.JsonSyntaxException) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.core.modules.commands.SimpleCommand) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) JsonSyntaxException(com.google.gson.JsonSyntaxException) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Async (br.com.brjdevs.java.utils.async.Async)1 Subscribe (com.google.common.eventbus.Subscribe)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 java.awt (java.awt)1 URLEncoder (java.net.URLEncoder)1 Collections (java.util.Collections)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Slf4j (lombok.extern.slf4j.Slf4j)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 AnimeData (net.kodehawa.mantarobot.commands.anime.AnimeData)1 CharacterData (net.kodehawa.mantarobot.commands.anime.CharacterData)1 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)1 PreLoadEvent (net.kodehawa.mantarobot.core.listeners.events.PreLoadEvent)1 Module (net.kodehawa.mantarobot.core.modules.Module)1 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)1 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)1 MantaroData (net.kodehawa.mantarobot.data.MantaroData)1