Created
March 30, 2013 03:24
-
-
Save azenla/5275180 to your computer and use it in GitHub Desktop.
ShortURLResolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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