private void lookupWord(String word, String channel, String nick) { try { WebRequest request = new GetMethodWebRequest("http://en.wikipedia.org/wiki/Special:Search?search=" + word + "&go=Go"); WebResponse resultPage; synchronized(this.wc) { resultPage = this.wc.getResponse(request); } String url = resultPage.getURL().toString(); TextBlock[] blocks = resultPage.getTextBlocks(); for (TextBlock textBlock : blocks) { Pattern p = Pattern.compile("^(.{100,}?)\\.($| [A-Z])"); Matcher m = p.matcher(textBlock.getText()); if (m.find()) { if(m.group(1).contains("No page with that title exists")) { break; } if(m.group(1).contains("You can create this article or request it")) { break; } if(m.group(1).contains("Please wikify (format) this article")) { break; } String desc=m.group(1); desc=desc.replaceAll("\\s*\\(.+?\\)",""); sendMessage(channel, nick + ", " + trimText(desc,450-6-url.length()-nick.length()-2) + ". [ " + url + " ]"); return; } } } catch (Exception e) { sendNotice(nick, "Problem while filling request: " + e.getMessage()); } sendMessage(channel, nick + ", I couldn't find a wikipedia entry. Try being more specific."); }