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");
}
Aggregations