public bool connect()//This is where the bot connects to the server and logs in { ChangeLabel("Connecting..."); user_message = "USER " + NICK + " " + NICK + "_h" + " " + NICK + "_s" + " :/r/naruto \n"; nick_message = "NICK " + NICK + "\r\n"; join_message = "JOIN " + HOME_CHANNEL + "\r\n"; quit_message = "QUIT " + HOME_CHANNEL + "\n"; userList.Clear(); irc = new TcpClient(HOST, PORT); stream = irc.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream) { AutoFlush = true }; reddit = new Reddit(); if (Settings.Default.redditUserEnabled) user = reddit.LogIn(Settings.Default.redditUser, Settings.Default.redditPass); try { messageSender(writer, user_message); messageSender(writer, nick_message); return true;//Weee, we connected! } catch (SocketException se) { Console.Out.Write(se); return false;//Boo, we didnt connect } }
public void animeSeach(StreamWriter s, string CHANNEL, string nick, string line) { string message; if (isMuted(nick)) return; GoogleSeach g = new GoogleSeach(); string json; bool user = false; if (line == "" || line == " ") return; if (line.Contains("-u") == true) user = true; string getString = "https://www.googleapis.com/customsearch/v1?key=" + Settings.Default.apikey + "&cx=" + Settings.Default.cxKey + "&q=" + line.Replace(" ", "%20").Replace(" -u", "%20"); var webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; if (Settings.Default.silence == false && Settings.Default.aniSearchEnabled == true) { try { json = webClient.DownloadString(getString); JsonConvert.PopulateObject(json, g); } catch { } if (g.items == null) message = privmsg(CHANNEL, "Could not find anything, try http://myanimelist.net/anime.php?q=" + line.Replace(" ", "%20")); else { int i_max = 0; int i = 0; bool found = false; if (g.items.Length < 4) i_max = g.items.Length-1; else i_max = 4; while (i<=i_max && found == false) { if (!user) { if (g.items[i].link.Contains("http://myanimelist.net/anime/")) { found = true; } else i++; } else { if (g.items[i].link.Contains("http://myanimelist.net/profile/")) { found = true; } else i++; } } if (!found) message = privmsg(CHANNEL, g.items[0].link); else if (!user) { string readHtml = webClient.DownloadString(g.items[i].link); string score = getBetween(readHtml, "Score:</span> ", "<sup><small>"); string rank = getBetween(readHtml, ">Ranked #", "</div>"); string title = getBetween(readHtml, ">Ranked #" + rank + "</div>", "</h1>"); message = privmsg(CHANNEL, "[#" + rank + "] " + "[" + score + " / 10] : " + "\x02" + title + "\x02" + " -> " + g.items[i].link); } else { string readHtml = webClient.DownloadString(g.items[i].link); string profile = getBetween(readHtml, "<title>", "'s Profile - MyAnimeList.net</title>"); string completed = getBetween(readHtml, ">Completed</span></td>", "<td><div style="); completed = getBetween(completed, "<td align=\"center\">", "</td>"); message = privmsg(CHANNEL, "[" + profile + "] " + "Completed " + completed + " animes" +" -> " + g.items[i].link); } } messageSender(s, message); } }