Search in sources :

Example 1 with OverwatchException

use of net.shadorc.overwatch4j.exception.OverwatchException in project Shadbot by Shadorc.

the class OverwatchCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    List<String> splitArgs = StringUtils.split(context.getArg());
    if (!Utils.isInRange(splitArgs.size(), 1, 3)) {
        throw new MissingArgumentException();
    }
    LoadingMessage loadingMsg = new LoadingMessage("Loading Overwatch profile...", context.getChannel());
    try {
        OverwatchPlayer player;
        String username = null;
        Platform platform = null;
        if (splitArgs.size() == 1) {
            username = splitArgs.get(0);
            loadingMsg.send();
            player = new OverwatchPlayer(username);
        } else {
            platform = this.getPlatform(splitArgs.get(0));
            username = splitArgs.get(1);
            loadingMsg.send();
            player = new OverwatchPlayer(username, platform);
        }
        EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName("Overwatch Stats").withAuthorIcon("http://vignette4.wikia.nocookie.net/overwatch/images/b/bd/Overwatch_line_art_logo_symbol-only.png").withAuthorUrl(player.getProfileURL()).withThumbnail(player.getIconUrl()).appendDescription(String.format("Stats for user **%s**", player.getName())).appendField("Level", Integer.toString(player.getLevel()), true).appendField("Competitive rank", Integer.toString(player.getRank()), true).appendField("Wins", Integer.toString(player.getWins()), true).appendField("Game time", player.getTimePlayed(), true).appendField("Top hero (Time played)", this.getTopThreeHeroes(player.getList(TopHeroesStats.TIME_PLAYED)), true).appendField("Top hero (Eliminations per life)", this.getTopThreeHeroes(player.getList(TopHeroesStats.ELIMINATIONS_PER_LIFE)), true);
        loadingMsg.edit(embed.build());
    } catch (OverwatchException err) {
        loadingMsg.edit(Emoji.MAGNIFYING_GLASS + " " + err.getMessage());
    } catch (IOException err) {
        loadingMsg.delete();
        Utils.handle("getting information from Overwatch profile", context, err);
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) Platform(net.shadorc.overwatch4j.enums.Platform) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) LoadingMessage(me.shadorc.shadbot.utils.object.LoadingMessage) IOException(java.io.IOException) OverwatchException(net.shadorc.overwatch4j.exception.OverwatchException) OverwatchPlayer(net.shadorc.overwatch4j.OverwatchPlayer)

Aggregations

IOException (java.io.IOException)1 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)1 LoadingMessage (me.shadorc.shadbot.utils.object.LoadingMessage)1 OverwatchPlayer (net.shadorc.overwatch4j.OverwatchPlayer)1 Platform (net.shadorc.overwatch4j.enums.Platform)1 OverwatchException (net.shadorc.overwatch4j.exception.OverwatchException)1 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)1