private void QuoteTimer_Elapsed(object sender, ElapsedEventArgs e) { string reply = Properties.Settings.Default.nonEmbeddableSrResponse; reply = reply.Replace("$SENDER", quoteAdders[0]); reply = reply.Replace("$BROADCASTER", ChatHandler.getChannel()); ChatHandler.sendMessage(reply); quoteAdders.Clear(); addingQuote = false; quoteTimer.Stop(); }
public ChatMessagePrivmsg(string rawMessage) : base(rawMessage) { Regex r = new Regex(":(?<sender>[A-Za-z0-9_]*)!(.*)@(.*).tmi.twitch.tv PRIVMSG #(.*?) :(?<message>.*)"); Match match = r.Match(rawMessage); parseTags(rawMessage); try { bits = int.Parse(tags["bits"]); } catch (Exception e) { } sender = match.Groups["sender"].Value; sentMessage = match.Groups["message"].Value; senderIsMod = tags["mod"].Equals("1"); senderIsBroadcaster = sender.Equals(ChatHandler.getChannel()); }
public void addQuote(string quote, string sender, bool senderIsMod) { if (quote.Trim() == "") { return; } if (Properties.Settings.Default.quotes == null) { Properties.Settings.Default.quotes = new System.Collections.Specialized.StringCollection(); Properties.Settings.Default.Save(); } if (quotes == null) { string[] arrQuotes = new string[Properties.Settings.Default.quotes.Count]; Properties.Settings.Default.quotes.CopyTo(arrQuotes, 0); quotes = new List <string>(arrQuotes); quoteTimer.Elapsed += QuoteTimer_Elapsed; } if (addingQuote) { ChatHandler.sendMessage("Finish adding the current quote first."); return; } quoteToAdd = quote; if (Properties.Settings.Default.quoteVotersNumber == 0) { Properties.Settings.Default.quotes.Add(quoteToAdd); Properties.Settings.Default.Save(); quotes.Add(quoteToAdd); ChatHandler.sendMessage("Quote added."); return; } else { addingQuote = true; quoteTimer.Start(); ChatHandler.sendMessage((Properties.Settings.Default.quoteVotersNumber - 1).ToString() + " other " + (Properties.Settings.Default.quoteVotersNumber > 2 ? "people need" : "person needs") + " to agree by typing " + Properties.Settings.Default.prefix + ChatHandler.getVoteYesCommand() + " to add the quote! Ends in one minute."); quoteAdders.Add(sender); } }
public virtual void handleMessage() { #if DEBUG ChatHandler.writeLineToFormBox(rawMessage); #endif }
public override void handleMessage() { if (sender != ChatHandler.getBotNick()) { ChatHandler.messagesBetweenPeriodics++; } if (sentMessage.StartsWith("\u0001ACTION")) { sentMessage = sentMessage.Replace("\u0001ACTION", ""); sentMessage = sentMessage.Replace("\u0001", ""); ChatHandler.writeLineToFormBox("* " + sender + " " + sentMessage); } else { ChatHandler.writeLineToFormBox("<" + (senderIsBroadcaster ? "~" : (senderIsMod ? "@" : "")) + sender + "> " + sentMessage); } if (sentMessage.StartsWith(Properties.Settings.Default.prefix)) { string command; if (sentMessage.Contains(" ")) { command = sentMessage.Substring(1, sentMessage.IndexOf(" ") - 1); } else { command = sentMessage.Substring(1, sentMessage.Length - 1); } command = command.ToLower(); try { string msg = ChatHandler.getMessageFromCommand(command); if (senderHasPermission(command)) { string args = getCommandArguments(sentMessage); msg = replaceVariables(msg, args); ChatHandler.sendMessage(msg); } else { ChatHandler.sendMessage(Properties.Settings.Default.noPermsMessage); } } catch (Exception e) { if (command == "wowie" && ChatHandler.getBotNick() == "wowiebot") { ChatHandler.sendMessage("wowie"); } } } else { ChatHandler.printLinkTitles(sentMessage); } if (bits > 0) // >= Properties.Settings.Default.bitsMessageThreshold) { string msg = Properties.Settings.Default.messageForBits; msg = msg.Replace("$COUNT", bits.ToString()); msg = msg.Replace("$SENDER", sender); ChatHandler.sendMessage(msg); } }
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); }