public String toString() { if (needsShorten) { needsShorten = false; title = Utils.shortenAllUrls(StringTools.unescapeHTML(title)); url = Utils.shortenUrl(url); } return channel + ' ' + Utils.timeAgo(date) + " | " + title + " | " + url; }
public void doCommand( PircBotX bot, EType type, CommandCallback callback, Channel channel, User sender, String message) { String[] args = message.split(" "); if (args.length == 1) { callback.type = EType.Notice; callback.append(help(bot, type, channel, sender)); return; } StringBuilder sb = new StringBuilder(); for (int i = 1; i < args.length; i++) { if (i != 1) sb.append(" "); sb.append(args[i]); } HTTPQuery q; StringBuilder result = new StringBuilder(); try { q = new HTTPQuery( "http://www.urbandictionary.com/iphone/search/define?term=" + URLEncoder.encode(sb.toString(), "UTF8"), "GET"); } catch (Exception e) { e.printStackTrace(); return; } q.connect(true, false); String line = q.readWhole(); try { JSONObject json = new JSONObject(line); String resulttype = json.getString("result_type"); if (resulttype.contentEquals("no_results")) { callback.append("No results."); return; } JSONObject entry = json.getJSONArray("list").getJSONObject(0); String word = entry.getString("word"); String definition = entry.getString("definition"); String example = entry.getString("example"); String permalink = entry.getString("permalink"); result.append(Utils.shortenUrl(permalink)); result.append(" \u0002"); result.append(word); result.append("\u0002: "); result.append(definition); if (example != null && example.length() > 0) { result.append(" Example: "); result.append(example); } String output = StringTools.ircFormatted(result, true); callback.append(output); } catch (Exception e) { e.printStackTrace(); } }