Skip to content

Commit bf832cc

Browse files
Use URLEncoder for /google command to avoid bugs
1 parent 6b22076 commit bf832cc

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/main/java/technobot/commands/fun/GoogleCommand.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import technobot.commands.Command;
99
import technobot.util.embeds.EmbedUtils;
1010

11+
import java.net.URLEncoder;
12+
import java.nio.charset.StandardCharsets;
13+
1114
/**
1215
* Command that googles something for the user.
1316
*
@@ -30,13 +33,7 @@ public void execute(SlashCommandInteractionEvent event) {
3033
event.replyEmbeds(EmbedUtils.createError("google doesn't like questions longer than 250 characters!")).queue();
3134
return;
3235
}
33-
34-
StringBuilder query = new StringBuilder("?q=");
35-
String[] words = question.strip().split(" ");
36-
for (int i = 0; i < words.length; i++) {
37-
query.append(words[i]);
38-
if (i+1 != words.length) query.append("+");
39-
}
40-
event.reply("http://lmgtfy.com/"+query).queue();
36+
String query = URLEncoder.encode(question, StandardCharsets.UTF_8);
37+
event.reply("http://lmgtfy.com/?q="+query).queue();
4138
}
4239
}

0 commit comments

Comments
 (0)