package com.blamejared.mcbot.commands;

import com.blamejared.mcbot.commands.api.Command;
import com.blamejared.mcbot.commands.api.CommandBase;
import com.blamejared.mcbot.commands.api.CommandContext;
import com.blamejared.mcbot.commands.api.CommandException;
import com.blamejared.mcbot.commands.api.Flag;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

@Command
public class CommandLMGTFY extends CommandBase {
    
    private static final Flag FLAG_IE = new SimpleFlag("ie", false);

    public CommandLMGTFY() {
        super("lmgtfy", false, Lists.newArrayList(FLAG_IE));
    }
    
    @Override
    public void process(CommandContext ctx) throws CommandException {
        if (ctx.getArgs().size() < 1) {
            throw new CommandException("Not enough arguments.");
        }
        int iie = ctx.getFlags().containsKey(FLAG_IE) ? 1 : 0;
        StringBuilder arg = new StringBuilder("http://lmgtfy.com/?iie=").append(iie).append("&q=");
        arg.append(Joiner.on('+').join(ctx.getArgs()));
        ctx.reply(arg.toString());
    }
    
    public String getUsage() {
        return "<question>";
    }
}

@@ -33,16 +33,90 @@
 mands;%0A%0A
+import java.io.UnsupportedEncodingException;%0Aimport java.net.URLEncoder;%0A%0A
 import c
@@ -157,16 +157,16 @@
 ommand;%0A
-
 import c
@@ -374,16 +374,56 @@
 i.Flag;%0A
+import com.google.common.base.Charsets;%0A
 import c
@@ -1011,19 +1011,19 @@
 Builder 
-arg
+url
  = new S
@@ -1036,16 +1036,17 @@
 uilder(%22
+%3C
 http://l
@@ -1102,19 +1102,21 @@
     
-arg.append(
+String arg = 
 Join
@@ -1126,9 +1126,9 @@
 on('
-+
+ 
 ').j
@@ -1145,17 +1145,16 @@
 tArgs())
-)
 ;%0A      
@@ -1159,34 +1159,236 @@
     
-ctx.reply(arg.toString());
+try %7B%0A            ctx.reply(url.append(URLEncoder.encode(ctx.sanitize(arg), Charsets.UTF_8.name())).append(%22%3E%22).toString());%0A        %7D catch (UnsupportedEncodingException e) %7B%0A            throw new CommandException(e);%0A        %7D
 %0A   

Fix URL encoding of lmgtfy output