Пример #1
0
        public Quote getQuote(string sender)
        {
            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 (quotes.Count == 0)
            {
                string reply = Properties.Settings.Default.emptyQuotesMessage;
                reply = reply.Replace("$SENDER", sender);
                reply = reply.Replace("$BROADCASTER", ChatHandler.getChannel());
                return(new Quote(reply, 0));
            }
            int q;

            do
            {
                q = ChatHandler.rnd.Next(quotes.Count);
            } while (q == lastQuote && quotes.Count > 1);
            lastQuote = q;
            return(new Quote(quotes[q], q + 1));
        }
Пример #2
0
 public override void handleMessage()
 {
     if (tags["msg-id"] == "sub" || tags["msg-id"] == "resub")
     {
         string reply = Properties.Settings.Default.subResponse;
         reply = reply.Replace("$SENDER", tags["display-name"]);
         reply = reply.Replace("$BROADCASTER", ChatHandler.getChannel());
         reply = reply.Replace("$MONTHS", tags["msg-param-cumulative-months"]);
         ChatHandler.sendMessage(reply);
     }
     else if (tags["msg-id"] == "subgift" || tags["msg-id"] == "anonsubgift")
     {
         string reply = Properties.Settings.Default.giftSubResponse;
         reply = reply.Replace("$SENDER", tags["display-name"]);
         reply = reply.Replace("$BROADCASTER", ChatHandler.getChannel());
         reply = reply.Replace("$MONTHS", tags["msg-param-months"]);
         reply = reply.Replace("$RECIPIENT", tags["msg-param-recipient-display-name"]);
         ChatHandler.sendMessage(reply);
     }
     else if (tags["msg-id"] == "raid")
     {
         string reply = Properties.Settings.Default.raidResponse;
         reply = reply.Replace("$SENDER", tags["msg-param-displayName"]);
         reply = reply.Replace("$BROADCASTER", ChatHandler.getChannel());
         reply = reply.Replace("$COUNT", tags["msg-param-viewerCount"]);
         ChatHandler.sendMessage(reply);
     }
 }
Пример #3
0
        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();
        }
Пример #4
0
        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());
        }
Пример #5
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);
        }