Search in sources :

Example 1 with EightBallResponse

use of tk.ardentbot.core.misc.web.models.EightBallResponse in project Ardent by adamint.

the class EightBall method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (args.length == 1) {
        sendTranslatedMessage("Type something so the 8ball has something to respond to!", channel, user);
    } else {
        String query = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
        try {
            String json = Unirest.get("https://8ball.delegator.com/magic/JSON/" + URLEncoder.encode(query)).asString().getBody();
            EightBallResponse eightBallResponse = GuildUtils.getShard(guild).gson.fromJson(json, EightBallResponse.class);
            sendTranslatedMessage(eightBallResponse.getMagic().getAnswer(), channel, user);
        } catch (UnirestException e) {
            sendTranslatedMessage("I can't answer that question!", channel, user);
            e.printStackTrace();
        }
    }
}
Also used : EightBallResponse(tk.ardentbot.core.misc.web.models.EightBallResponse) UnirestException(com.mashape.unirest.http.exceptions.UnirestException)

Aggregations

UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 EightBallResponse (tk.ardentbot.core.misc.web.models.EightBallResponse)1