public void parseRoleta(TwitchUserMessage userMessage)
 {
     sendChatMessage(string.Format("{0} pointed the gun to his head!", userMessage.Username));
     System.Threading.Thread.Sleep(r.Next(1000, 5000));
     if (r.Next() % 2 == 0)
     {
         sendChatMessage(string.Format("The gun failed! You're safe... for now :) "));
     }
     else
     {
         int timeoutTime = r.Next(1, 180);
         sendChatMessage(string.Format("You're dead! Timeout for {0} seconds!", timeoutTime.ToString()));
     }
 }
 IEnumerator enterChatLine(TwitchUserMessage greetings)
 {
     if (doAnimations)
     {
         for (int i = 0; i < enterChatAnimation.StepCount - 1; i++)
         {
             greetings.Location = new Point(enterChatAnimation.GetNext(i), greetings.Location.Y);
             yield return(new WaitForMilliseconds(5));
         }
     }
     else
     {
         greetings.Location = new Point(0, greetings.Location.Y);
     }
     yield break;
 }
 public void parseHello(TwitchUserMessage userMessage)
 {
     sendChatMessage(userMessage.Username + ", Hello mate!");
 }
 public void parseCoins(TwitchUserMessage userMessage)
 {
     sendChatMessage(userMessage.Username + " have " + r.Next().ToString() + " coins");
 }
 public void parseBankheist(TwitchUserMessage userMessage)
 {
     sendChatMessage(string.Format("Sorry {0}, the bank is closed now!", userMessage.Username));
 }
示例#6
0
        public void parseCommand(TwitchUserMessage userMessage)
        {
            IList<string> commands = commandList.Keys.ToList();
            string innerCommand = string.Empty;
            foreach (string command in commands)
            {
                innerCommand = commandPrefix + command;
                Regex regex = new Regex(innerCommand + ".*");
                if (regex.IsMatch(userMessage.Message))
                {
                    System.Threading.ParameterizedThreadStart pts = new System.Threading.ParameterizedThreadStart(RunCommand);
                    System.Threading.Thread t = new System.Threading.Thread(pts);
                    CommandParameter cp = new CommandParameter();
                    cp.ircClient = this;
                    cp.userMessage = userMessage;
                    cp.ircCommand = commandList[command];

                    //Run on a thread to avoid huge queues
                    t.Start(cp);

                    //commandList[command](userMessage);
                }
            }
        }
示例#7
0
        public TwitchUserMessage parseMessage(string message)
        {
            Regex regex = new Regex(":(\\w+)\\!\\1@\\1\\.tmi\\.twitch\\.tv\\sPRIVMSG\\s#" + channel + " :(.*)");
            if (regex.IsMatch(message))
            {
                MatchCollection mc = regex.Matches(message);
                TwitchUserMessage t = new TwitchUserMessage();
                t.Username = mc[0].Groups[1].Value;
                t.Message = mc[0].Groups[2].Value;

                return t;
            }
            return null;
        }
        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));
        }