public static int runBot() { TcpClient client; try { int port = 6667; client = new TcpClient("irc.chat.twitch.tv", port); // Enter in channel (the username of the stream chat you wish to connect to) without the # // Get a client stream for reading and writing. // Stream stream = client.GetStream(); stream = client.GetStream(); } catch (Exception e) { MessageBox.Show(e.Message + e.StackTrace, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } streamReader = new StreamReader(stream, Encoding.UTF8); // Send the message to the connected TcpServer. // string oauth = "5bdocznijbholgvt3o9u6t5ui6okjs"; string loginstring = "PASS oauth:" + botOauth + "\r\nNICK " + botNick + "\r\n"; string toShow = "PASS oauth:" + "*****" + "\r\nNICK " + botNick + "\r\n"; sendToServer(loginstring); Console.WriteLine(toShow); mainForm.writeToServerOutputTextBox(toShow + "\r\n"); // Receive the TcpServer.response. mainForm.writeToServerOutputTextBox(readFromServer() + "\r\n"); // String to store the response ASCII representation. // Requesting tags capability for more info string tagReqString = "CAP REQ :twitch.tv/tags twitch.tv/commands\r\n"; sendToServer(tagReqString); // Read the request response readFromServer(); // send message to join channel string joinstring = "JOIN " + "#" + channel + "\r\n"; sendToServer(joinstring); readFromServer(); mainForm.writeToServerOutputTextBox("Joined channel #" + channel + ".\r\n"); willDisconnect = false; while (!willDisconnect) { ChatMessage msg = receiveMessage(); msg.handleMessage(); } QuoteHandler.getInstance().deconstruct(); stream.Close(); client.Close(); return(0); }
public string replaceVariables(string commandText, string commandArgs) { JObject broadcastData = null; TimeSpan uptime = new TimeSpan(0); Quote q = null; foreach (String cmd in ChatHandler.getMessageVars()) { if (commandText.Contains("$" + cmd)) { switch (cmd) { case "QUOTE": if (q == null) { q = QuoteHandler.getInstance().getQuote(sender); } commandText = commandText.Replace("$QUOTE", q.getQuoteText()); break; case "QNUM": if (q == null) { q = QuoteHandler.getInstance().getQuote(sender); } commandText = commandText.Replace("$QNUM", q.getQuoteNumber().ToString()); break; case "ADDQUOTE": QuoteHandler.getInstance().addQuote(commandArgs, sender, senderIsMod); return(null); case "VOTEYES": QuoteHandler.getInstance().voteYes(sender); return(null); case "BROADCASTER": commandText = commandText.Replace("$BROADCASTER", ChatHandler.getChannel()); break; case "SENDER": commandText = commandText.Replace("$SENDER", sender); break; case "GAME": if (broadcastData == null) { broadcastData = ChatHandler.getBroadcastDataFromAPI(); } commandText = commandText.Replace("$GAME", broadcastData.Property("game").Value.ToString()); break; case "TITLE": if (broadcastData == null) { broadcastData = ChatHandler.getBroadcastDataFromAPI(); } commandText = commandText.Replace("$TITLE", broadcastData.Property("status").Value.ToString()); break; case "UPHOURS": if (uptime.Ticks == 0) { uptime = ChatHandler.getUptime(); } commandText = commandText.Replace("$UPHOURS", uptime.Hours.ToString()); break; case "UPMINUTES": if (uptime.Ticks == 0) { uptime = ChatHandler.getUptime(); } commandText = commandText.Replace("$UPMINUTES", uptime.Minutes.ToString()); break; case "8BALL": commandText = commandText.Replace("$8BALL", ChatHandler.get8BallResponse()); break; case "CALCULATOR": Expression e = new Expression(commandArgs); string x = e.calculate().ToString(); commandText = commandText.Replace("$CALCULATOR", x); break; case "COMMANDS": commandText = commandText.Replace("$COMMANDS", ChatHandler.commandsForHelp); break; case "SONGREQ": string id = ""; string res = "Queued."; try { Uri ytlink = new Uri(commandArgs); id = getIdFromYoutubeLink(ytlink); } catch { var searchListRequest = SongRequest.youtubeService.Search.List("snippet"); searchListRequest.Q = commandArgs; searchListRequest.MaxResults = 5; searchListRequest.Type = "video"; var searchListResponse = searchListRequest.Execute(); if (searchListResponse.Items.Count == 0) { return("No results found."); } foreach (var item in searchListResponse.Items) { if (item.Snippet.Title.ToLower().Contains("lyrics")) { id = item.Id.VideoId; res = "Queued \"" + item.Snippet.Title + "\"."; break; } } if (id == "") { id = searchListResponse.Items[0].Id.VideoId; res = "Queued \"" + searchListResponse.Items[0].Snippet.Title + "\"."; } } if (MainForm.songRequestForm == null) { string reply = Properties.Settings.Default.closedSrWindowResponse; reply = reply.Replace("$SENDER", sender); reply = reply.Replace("$BROADCASTER", ChatHandler.getChannel()); commandText = reply; } else if (id != null) { SongRequest sr = new SongRequest(id, sender); if (sr.embeddable == false) { string reply = Properties.Settings.Default.nonEmbeddableSrResponse; reply = reply.Replace("$SENDER", sender); reply = reply.Replace("$BROADCASTER", ChatHandler.getChannel()); return(reply); } MainForm.songRequestForm.queueSong(sr); return(res); } else { commandText = "Unable to parse link."; } break; case "QUEUETIME": commandText = commandText.Replace("$QUEUETIME", MainForm.songRequestForm.getQueueLength().ToString()); break; } } } return(commandText); }