use of net.shadorc.overwatch4j.OverwatchPlayer 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);
}
}
Aggregations