Skip to content

Instantly share code, notes, and snippets.

@azenla
Created March 30, 2013 03:24
Show Gist options
  • Save azenla/5275180 to your computer and use it in GitHub Desktop.
Save azenla/5275180 to your computer and use it in GitHub Desktop.
ShortURLResolver
@EventListener(name = "ShortURLResolver", event = "MessageEvent")
public static void shortUrlResolver(MessageEvent event) throws IOException {
if (event.getMessage().contains("http://goo.gl")) {
String googleurllink = "";
for (String url : pullLinks(event.getMessage())) {
if (url.startsWith("http://goo.gl/")) {
googleurllink = url;
}
}
HttpURLConnection connection = (HttpURLConnection) new URL(googleurllink).openConnection();
connection.setInstanceFollowRedirects(false);
connection.connect();
String redirected = connection.getHeaderField("Location");
if (redirected.equals(googleurllink)) {
event.getBot().sendNotice(event.getUser(), "Goo.Gl Failed!");
}
event.getChannel().sendMessage("$> " + googleurllink + " > " + redirected);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment