void Bot_OnMessage(Network n, Irc.IrcEventArgs e) { if (IsMatch("^googlesearch \\?$", e.Data.Message)) { AnswerWithNotice(n, e, FormatBold("Use of GoogleSearch plugin:")); AnswerWithNotice(n, e, FormatItalic("google <search term>") + " - Searches google for <search term> and lists the first two results."); AnswerWithNotice(n, e, FormatItalic("google <number of results> <search term>") + " - Searches google for <search term> and lists the first <number of results> (maximum is 10) results."); } else if (IsMatch("^google ((?<count>\\d{1,2}) )?(?<term>.*)$", e.Data.Message)) { int count = 2; if (Matches["count"].Length > 0) { count = int.Parse(Matches["count"].ToString()); } if (count > 10) { count = 10; } try { Google.Google.GoogleSearchService s = new Google.Google.GoogleSearchService(); Google.Google.GoogleSearchResult results = s.doGoogleSearch(Bot.Configuration["Plugins"]["GoogleSearch"].Attributes["Key"].Value, Matches["term"].ToString(), 0, count, false, "", false, "", "", ""); if (count > results.resultElements.Length) { count = results.resultElements.Length; } if (count > 0) { Answer(n, e, FormatBold(count.ToString() + " results for " + FormatItalic(Matches["term"].ToString()) + ".")); for (int i = 0; i < count; i++) { string result = results.resultElements[i].URL + " (" + FormatBold(results.resultElements[i].title) + " - " + results.resultElements[i].snippet + ")"; result = result.Replace("<b>", "").Replace("</b>", "").Replace("<br>", "").Replace("'", "'").Replace("&", "&"); Answer(n, e, result); } } else { Answer(n, e, "No results found for " + FormatItalic(Matches["term"].ToString()) + "."); } } catch (Exception ex) { Answer(n, e, "Error in GoogleSearch plugin: " + FormatItalic(ex.Message)); } } }
void Bot_OnMessage(Network n, Irc.IrcEventArgs e) { if (IsMatch("^googlesearch \\?$", e.Data.Message)) { AnswerWithNotice(n, e, FormatBold("Use of GoogleSearch plugin:")); AnswerWithNotice(n, e, FormatItalic("google <search term>") + " - Searches google for <search term> and lists the first two results."); AnswerWithNotice(n, e, FormatItalic("google <number of results> <search term>") + " - Searches google for <search term> and lists the first <number of results> (maximum is 10) results."); } else if (IsMatch("^google ((?<count>\\d{1,2}) )?(?<term>.*)$", e.Data.Message)) { int count = 2; if (Matches["count"].Length > 0) count = int.Parse(Matches["count"].ToString()); if (count > 10) count = 10; try { Google.Google.GoogleSearchService s = new Google.Google.GoogleSearchService(); Google.Google.GoogleSearchResult results = s.doGoogleSearch(Bot.Configuration["Plugins"]["GoogleSearch"].Attributes["Key"].Value, Matches["term"].ToString(), 0, count, false, "", false, "", "", ""); if (count > results.resultElements.Length) count = results.resultElements.Length; if (count > 0) { Answer(n, e, FormatBold(count.ToString() + " results for " + FormatItalic(Matches["term"].ToString()) + ".")); for (int i = 0; i < count; i++) { string result = results.resultElements[i].URL + " (" + FormatBold(results.resultElements[i].title) + " - " + results.resultElements[i].snippet + ")"; result = result.Replace("<b>", "").Replace("</b>", "").Replace("<br>", "").Replace("'", "'").Replace("&", "&"); Answer(n, e, result); } } else Answer(n, e, "No results found for " + FormatItalic(Matches["term"].ToString()) + "."); } catch (Exception ex) { Answer(n, e, "Error in GoogleSearch plugin: " + FormatItalic(ex.Message)); } } }