コード例 #1
0
 public void CustomUpdate()
 {
     coroutineManager.Interval();
     if (!initialized)
     {
         return;
     }
     if (!twitchClient.Connected)
     {
         Connect();
     }
     else if (twitchClient.Available > 0)
     {
         string rawLine = reader.ReadLine();
         if (rawLine == "PING :tmi.twitch.tv")
         {
             SendRawMessage("PONG :tmi.twitch.tv");
         }
         else if (rawLine.Contains("PRIVMSG"))
         {
             TwitchMessage user             = TwitchMessage.GetTwitchMessage(rawLine);
             string        username         = user.display_name; //GetUsername(rawLine);
             string        extractedMessage = user.message;      //GetExtractedMessage(rawLine);
             bool          isAction         = false;
             if (extractedMessage.StartsWith("\u0001"))
             {
                 extractedMessage = extractedMessage.Replace("\u0001", "");
                 extractedMessage = extractedMessage.ReplaceFirst("ACTION ", "");
                 isAction         = true;
             }
             user.message = extractedMessage;
             messagesToBeAdded.Enqueue(user);
         }
         else if (rawLine.Contains("CLEARCHAT"))
         {
             int    start = rawLine.IndexOf(":", rawLine.IndexOf("CLEARCHAT")) + 1;
             int    stop  = rawLine.IndexOf(" ", start);
             string user  = rawLine.Substring(start, rawLine.Length - start);
             Font   f     = font;
             f = new Font(f, FontStyle.Strikeout);
             foreach (TwitchUserMessage m in currentChatMessages)
             {
                 if (m.twitchMessage.display_name.ToLower() == user.ToLower())
                 {
                     m.Font = f;
                 }
             }
         }
     }
     if (messagesToBeAdded.Count > 0)
     {
         ProcessMessage(messagesToBeAdded.Dequeue());
     }
 }
コード例 #2
0
        private void sendCurrentMessageToChat()
        {
            string textToSend = richTextBox1.Text;

            richTextBox1.Clear();
            writer.WriteLine("PRIVMSG #" + channelToJoin + " :" + textToSend);
            TwitchMessage m = new TwitchMessage();

            m.username = botUsername;
            m.message  = textToSend;
            m.color    = "#FFFFFF";
            SentUserMessage m2 = new SentUserMessage(m, panelBorder, border, Width);

            Controls.Add(m2);
            currentChatMessages.Add(m2);
            Application.DoEvents();
            m2.Location = new Point(-m2.Width, Height - m2.Size.Height - 50 - (richTextBox1.Visible ? richTextBox1.Size.Height : 0));
            coroutineManager.StartCoroutine(moveLabels(m2));
        }
コード例 #3
0
        private void ProcessMessage(TwitchMessage twitchMessage)
        {
            // http://static-cdn.jtvnw.net/emoticons/v1/:<emote ID>/1.0
            //<emote ID>:<first index>-<last index>,<another first index>-<another last index>/<another emote ID>:<first index>-<last index>...

            SortedList <int, ImageAndInts> emoteBoxes = new SortedList <int, ImageAndInts>();
            var badges = new List <Image>();

            string[] array   = twitchMessage.message.Split(' ');
            int      lastLoc = 0;

            if (useFFZ || useBTTV || useEmoji)
            {
                foreach (string a in array)
                {
                    if (cachedBTTVEmotes.ContainsKey(a))
                    {
                        int start             = twitchMessage.message.IndexOf(a, lastLoc);
                        int stop              = start + a.Length - 1;
                        Tuple <int, int> ints = new Tuple <int, int>(start, stop);
                        lastLoc = stop;

                        ImageAndInts iss = new ImageAndInts
                        {
                            img  = cachedBTTVEmotes[a],
                            ints = ints
                        };
                        emoteBoxes.Add(start, iss);
                    }
                    else if (cachedFFZEmotes.ContainsKey(a))
                    {
                        int start             = twitchMessage.message.IndexOf(a, lastLoc);
                        int stop              = start + a.Length - 1;
                        Tuple <int, int> ints = new Tuple <int, int>(start, stop);
                        lastLoc = stop;

                        ImageAndInts iss = new ImageAndInts
                        {
                            img  = cachedFFZEmotes[a],
                            ints = ints
                        };
                        emoteBoxes.Add(start, iss);
                    }
                    else if (useEmoji)
                    {
                        List <string> emojis  = new List <string>();
                        string        current = "";
                        for (int i = 0; i < a.Length; i++)
                        {
                            char c = a[i];
                            if (!Emojis.codeToEmoji.ContainsKey(current))
                            {
                                if (c > 255)
                                {
                                    current += c;
                                    continue;
                                }
                            }
                            if (current.Length > 0)
                            {
                                i--;
                                emojis.Add(current);
                            }
                            current = "";
                        }
                        if (current.Length > 0)
                        {
                            emojis.Add(current);
                        }
                        foreach (string s in emojis)
                        {
                            if (Emojis.codeToEmoji.ContainsKey(s))
                            {
                                int start             = twitchMessage.message.IndexOf(s, lastLoc);
                                int stop              = start + s.Length - 1;
                                Tuple <int, int> ints = new Tuple <int, int>(start, stop);
                                lastLoc = stop;
                                ImageAndInts iss = new ImageAndInts
                                {
                                    img           = Emojis.codeToEmoji[s],
                                    ints          = ints,
                                    preferredSize = new Size(18, 18)
                                };
                                try
                                {
                                    emoteBoxes.Add(start, iss);
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
            string[] tBadges = twitchMessage.badges.Split(',');
            if (tBadges[0] != null)
            {
                foreach (string s in tBadges)
                {
                    string[] parts = s.Split('/');
                    if (cachedBadges.ContainsKey(parts[0]))
                    {
                        badges.Add(cachedBadges[parts[0]].versions[parts[1]].image);
                    }
                }
            }
            string[] emotes = twitchMessage.emotes.Split('/');
            if (emotes[0] != "")
            {
                foreach (string s in emotes)
                {
                    int    start   = s.IndexOf(":");
                    string onePart = s.Substring(start + 1);
                    List <Tuple <int, int> > ints = new List <Tuple <int, int> >();
                    string[] indexes = onePart.Split(',');
                    foreach (string a in indexes)
                    {
                        string[]         e = a.Split('-');
                        Tuple <int, int> t = new Tuple <int, int>(int.Parse(e[0]), int.Parse(e[1]));
                        ints.Add(t);
                    }

                    for (int i = 0; i < ints.Count; i++)
                    {
                        int    firstIndex  = ints[i].Item1;
                        int    secondIndex = ints[i].Item2;
                        int    length      = secondIndex - firstIndex + 1;
                        string code        = twitchMessage.message.Substring(firstIndex, firstIndex + length > twitchMessage.message.Length - 1 ? twitchMessage.message.Length - firstIndex : length);
                        string theId       = s.Substring(0, start);
                        string theUrl      = "http://static-cdn.jtvnw.net/emoticons/v1/" + theId + "/1.0";
                        string path        = "./emotes/Twitch/Twitch" + theId + ".png";
                        if (!File.Exists(path))
                        {
                            client.DownloadFile(theUrl, path);
                        }
                        Image image = default(Image);
                        try
                        {
                            image = Image.FromFile(path);
                        }
                        catch { }
                        ImageAndInts iss = new ImageAndInts
                        {
                            img  = image,
                            ints = ints[i],
                            //tooltip = new Controls.ToolTip("Twitch Emote: " + code, image)
                        };
                        try
                        {
                            emoteBoxes.Add(firstIndex, iss);
                        }
                        catch { }
                    }
                }
            }
            TwitchUserMessage m = new TwitchUserMessage(twitchMessage, badges, emoteBoxes, font, doSplitter, textColor, backColor, Width - 2 * border - (vScrollBar1.Visible ? vScrollBar1.Width : 0), panelBorder / 2, emoteSpacing);

            Controls.Add(m);
            currentChatMessages.Add(m);
            Application.DoEvents();
            m.Location = new Point(-m.Width, Height - m.Size.Height - 50 - (richTextBox1.Visible ? richTextBox1.Size.Height : 0));
            coroutineManager.StartCoroutine(moveLabels(m));
        }
コード例 #4
0
 public void CustomUpdate()
 {
     coroutineManager.Interval();
     if (!initialized)
     {
         return;
     }
     if (!twitchClient.Connected)
     {
         Connect();
     }
     else if (twitchClient.Available > 0)
     {
         string rawLine = reader.ReadLine();
         if (rawLine == "PING :tmi.twitch.tv")
         {
             SendRawMessage("PONG :tmi.twitch.tv");
         }
         else if (rawLine.Contains("PRIVMSG"))
         {
             TwitchMessage user             = TwitchMessage.GetTwitchMessage(rawLine);
             string        username         = user.display_name; //GetUsername(rawLine);
             string        extractedMessage = user.message;      //GetExtractedMessage(rawLine);
             bool          isAction         = false;
             if (extractedMessage.StartsWith("\u0001"))
             {
                 extractedMessage = extractedMessage.Replace("\u0001", "");
                 extractedMessage = extractedMessage.ReplaceFirst("ACTION ", "");
                 isAction         = true;
             }
             user.message  = extractedMessage;
             user.isAction = isAction;
             messagesToBeAdded.Enqueue(user);
         }
         else if (rawLine.Contains("CLEARCHAT"))
         {
             int    start = rawLine.IndexOf(":", rawLine.IndexOf("CLEARCHAT")) + 1;
             int    stop  = rawLine.IndexOf(" ", start);
             string user  = rawLine.Substring(start, rawLine.Length - start);
             Font   f     = font;
             f = new Font(f, FontStyle.Strikeout);
             foreach (MessageControl m in currentChatMessages)
             {
                 if (m is TwitchUserMessage u)
                 {
                     if (u.twitchMessage.display_name.ToLower() == user.ToLower())
                     {
                         u.Font      = f;
                         u.ForeColor = Color.Gray;
                         u.DrawContent(u.CreateGraphics());
                     }
                 }
             }
         }
         else if (rawLine.Contains("USERNOTICE"))
         {
             //To be added: notifications
             int    start     = rawLine.IndexOf("system-msg=") + "system-msg=".Length;
             int    stop      = rawLine.IndexOf(";tmi") - 1;
             string theString = rawLine.Substring(start, stop - start);
             theString.Replace("\\s", " ");
             MessageControl m = new HighlightedNotification(theString, panelBorder, border, Width - 2 * border);
             currentChatMessages.Add(m);
             m.Font      = font;
             m.ForeColor = textColor;
             m.BackColor = backColor;
             Controls.Add(m);
             Application.DoEvents();
             m.Location = new Point(-m.Width, Height - m.Size.Height - 50 - (richTextBox1.Visible ? richTextBox1.Size.Height : 0));
             coroutineManager.StartLateCoroutine(moveLabels(m));
         }
     }
     if (messagesToBeAdded.Count > 0)
     {
         ProcessMessage(messagesToBeAdded.Dequeue());
     }
 }