use of net.kodehawa.mantarobot.commands.anime.CharacterData in project MantaroBot by Mantaro.
the class AnimeCmds method character.
@Subscribe
public void character(CommandRegistry cr) {
cr.register("character", new SimpleCommand(Category.FUN) {
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
try {
if (content.isEmpty()) {
onHelp(event);
return;
}
String url = String.format("https://anilist.co/api/character/search/%1s?access_token=%2s", URLEncoder.encode(content, "UTF-8"), authToken);
String json = Utils.wgetResty(url, event);
CharacterData[] character = CharacterData.fromJson(json);
if (character.length == 1) {
characterData(event, character[0]);
return;
}
DiscordUtils.selectList(event, character, character1 -> String.format("**[%s %s](%s)**", character1.getLastName() == null ? "" : character1.getLastName(), character1.getFirstName(), "http://anilist.co/character/" + character1.getId()), s -> baseEmbed(event, "Type the number of the character 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(), character1 -> characterData(event, character1));
} 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 d-drop your waifu, please forgive me!**\nI got ``%s`` while trying to process this command.", EmoteReference.ERROR, exception.getClass().getSimpleName())).queue();
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Character command").setDescription("**Get character info from AniList (For anime use `~>anime`).**").addField("Usage", "`~>character <name>` - **Retrieve information of a charactrer based on the name.**", false).addField("Parameters", "`name` - **The name of the character you are looking for. Keep queries similar to their romanji names!**", false).setColor(Color.PINK).build();
}
});
cr.registerAlias("character", "char");
}
use of net.kodehawa.mantarobot.commands.anime.CharacterData in project MantaroBot by Mantaro.
the class Character method onStart.
@Override
public boolean onStart(GameLobby lobby) {
try {
GameStatsManager.log(name());
characterNameL = new ArrayList<>();
characterName = CollectionUtils.random(NAMES.get());
String url = String.format("https://anilist.co/api/character/search/%1s?access_token=%2s", URLEncoder.encode(characterName, "UTF-8"), authToken);
String json = Utils.wget(url, null);
CharacterData character = CharacterData.fromJsonFirst(json);
String imageUrl = character.getMedImageUrl();
// Allow for replying with only the first name.
if (characterName.contains(" ") && !characterName.contains("Sailor")) {
characterNameL.add(characterName.split(" ")[0]);
}
characterNameL.add(characterName);
sendEmbedImage(lobby.getChannel(), imageUrl, eb -> eb.setTitle("Guess the character", null).setFooter("You have 10 attempts and 60 seconds. (Type end to end the game)", null)).queue();
return true;
} catch (Exception e) {
if (e instanceof JsonSyntaxException) {
lobby.getChannel().sendMessage(EmoteReference.WARNING + "Report this in the official server please. Failed to setup game for pre-saved character: " + characterName).queue();
return false;
}
lobby.getChannel().sendMessage(EmoteReference.ERROR + "Error while setting up a game.").queue();
log.warn("Exception while setting up a game", e);
return false;
}
}
Aggregations