/*
 * Skybot, a multipurpose discord bot
 *      Copyright (C) 2017 - 2018  Duncan "duncte123" Sterken & Ramid "ramidzkh" Khan & Maurice R S "Sanduhr32"
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package ml.duncte123.skybot.commands.fun;

import me.duncte123.botCommons.web.WebUtils;
import me.duncte123.botCommons.web.WebUtils.EncodingType;
import ml.duncte123.skybot.objects.command.Command;
import ml.duncte123.skybot.objects.command.CommandCategory;
import ml.duncte123.skybot.objects.command.CommandContext;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;

import java.io.IOException;
import java.util.List;

import static ml.duncte123.skybot.utils.MessageUtils.sendMsg;

public class YodaSpeakCommand extends Command {
    @Override
    public void executeCommand(@NotNull CommandContext ctx) {

        GuildMessageReceivedEvent event = ctx.getEvent();
        List<String> args = ctx.getArgs();

        if (args.size() < 1) {
            sendMsg(event, "Correct usage: `" + PREFIX + getName() + " <A sentence.>`");
            return;
        }

        WebUtils.ins.prepareRaw(WebUtils.defaultRequest()
                .url("https://apis.duncte123.me/yoda?sentence=" + StringUtils.join(args, "+"))
//                .url("http://localhost/yoda?sentence=" + StringUtils.join(args, "+"))
                .addHeader("X-user-id", event.getJDA().getSelfUser().getId())
                .addHeader("X-client-token", event.getJDA().getToken())
                .addHeader("Accept", EncodingType.APPLICATION_JSON.getType())
                .build(), Response::body).async(
                (body) -> {
                    try {
                        final String res = body.string();
                        logger.debug("Yoda response: " + res);
                        final JSONObject json = new JSONObject(res);
                        sendMsg(event, json.getString("sentence"));
                    } catch (IOException e) {
                        e.printStackTrace();
                        sendMsg(event, "Yoda is asleep tell my developers to wake him up");
                    }
                },
                error -> {
                    error.printStackTrace();
                    sendMsg(event, "Yoda is asleep tell my developers to wake him up");
                }
        );

    }

    @Override
    public String help() {
        return "Convert your sentences into yoda speak.\n" +
                "Usage: `" + PREFIX + getName() + " <A sentence.>`";
    }

    @Override
    public String getName() {
        return "yoda";
    }

    @Override
    public CommandCategory getCategory() {
        return CommandCategory.FUN;
    }
}

@@ -967,16 +967,67 @@
 ngType;%0A
+import me.duncte123.weebJava.helpers.QueryBuilder;%0A
 import m
@@ -1911,55 +1911,47 @@
     
-WebUtils.ins.prepareRaw(WebUtils.defaultRequest
+QueryBuilder builder = new QueryBuilder
 ()%0A 
@@ -1962,27 +1962,30 @@
            .
-url
+append
 (%22https://ap
@@ -2008,105 +2008,44 @@
 yoda
-?sentence=%22 + StringUtils.join(args, %22+%22))%0A//                .url(%22http://localhost/yoda?
+%22)%0A                .append(%22
 sentence
 =%22 +
@@ -2044,12 +2044,10 @@
 ence
-=%22 +
+%22,
  Str
@@ -2094,27 +2094,20 @@
   .a
-ddHeader(%22X-user-id
+ppend(%22token
 %22, e
@@ -2127,96 +2127,111 @@
 .get
-SelfUser().getId())%0A                .addHeader(%22X-client-token%22, event.getJDA().getToken
+Token());%0A%0A        WebUtils.ins.prepareRaw(WebUtils.defaultRequest()%0A                .url(builder.build
 ())%0A

Fix the yoda command