DogCommand.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:GoupilBot 作者:
@Override
protected void execute(CommandEvent event) {
    if (event.isFromType(ChannelType.TEXT)) {
        String id = Constant.getTextChannelConf().getProperty(event.getGuild().getId());
        if (id != null) {
            if (!event.getChannel().getId().equals(id)) {
                return;
            }
        }
    }
    // use Unirest to poll an API
    Unirest.get("https://random.dog/woof.json").asJsonAsync(new Callback<JsonNode>() {

        // The API call was successful
        @Override
        public void completed(HttpResponse<JsonNode> hr) {
            event.reply(new EmbedBuilder()
                    .setColor(event.isFromType(ChannelType.TEXT) ? event.getSelfMember().getColor() : Color.GREEN)
                    .setImage(hr.getBody().getObject().getString("url"))
                    .build());
        }

        // The API call failed
        @Override
        public void failed(UnirestException ue) {
            event.reactError();
        }

        // The API call was cancelled (this should never happen)
        @Override
        public void cancelled() {
            event.reactError();
        }
    });
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号