Exemplo n.º 1
0
        //   string dots = ".";
        void IrcClient_RawMessageReceived(object sender, IrcRawMessageEventArgs e)
        {
            string prefix, command;
            Dictionary <string, string> ptags = new Dictionary <string, string>();

            string[] parameters;

            //Console.WriteLine( e.RawContent );


            try {
                if (e.RawContent.StartsWith("@"))
                {
                    // TAGged command
                    int n = e.RawContent.IndexOf(' ');
                    if (n > 0)
                    {
                        string[] tags = e.RawContent.Substring(1, n - 1).Split(';');
                        foreach (var tag in tags)
                        {
                            string[] data = tag.Split('=');
                            ptags[data[0]] = data[1];
                        }

                        string txt = e.RawContent.Substring(n + 1);
                        ParseIrcMessageWithRegex(txt, out prefix, out command, out parameters);

                        //@color=#00B4CC;display-name=ilittle17;emotes=501:9-10;subscriber=1;turbo=1;user-type=mod
                        //@color=#0000FF;display-name=WinBotCity;emotes=;subscriber=1;turbo=0;user-type=
                        //@color=#C2CC00;display-name=Event0011;emotes=;subscriber=1;turbo=1;user-type=
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    // typical IRCv2 command
                    ParseIrcMessageWithRegex(e.RawContent, out prefix, out command, out parameters);
                }



                List <ChatMessage> msgs = new List <ChatMessage>();
                //List<ChatCommand> cmds = new List<ChatCommand>();
                string username = getUserName(prefix);
                switch (command)
                {
                /* case "001":
                 *   this.Status = true;
                 *   this.Tooltip = string.Format( "twitch channel {0} not found!", StreamerNick );
                 *   Destroy();
                 *   break;*/

                case "PART":
                case "JOIN":
                    //Header = "http://twitch.tv, " + StreamerNick + dots;
                    this.Status  = true;
                    this.Tooltip = string.Format("twitch: {0}", _streamerNick);
                    this.Header  = "Joined";
                    break;

                case "MODE":
                    //if (parameters[1] == "+o") {
                    //    addBage( parameters[2].ToLower(), "moderator" );
                    //}
                    break;

                case "CLEARCHAT":
                    fireOnRemoveUserMessages(parameters[1]);
                    break;

                case "PRIVMSG":
                    //Header = "http://twitch.tv, " + StreamerNick;
                    if (username != "Jtv")
                    {
                        string text = parameters[1];

                        string emotes = ptags.SafeGet("emotes", "");
                        if (!string.IsNullOrEmpty(emotes))
                        {
                            // F**K emotes
                            text = doAttachEmotes(text, emotes);
                        }
                        else
                        {
                            text = Regex.Replace(text,
                                                 @"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)",
                                                 "[url]$1[/url]");
                        }
                        // actualize badges!
                        //addBage
                        //@color=#00B4CC;display-name=ilittle17;emotes=501:9-10;subscriber=1;turbo=1;user-type=mod
                        if (Properties.Settings.Default.twitch_ShowSubsIcon)
                        {
                            if (ptags.SafeGet("subscriber", "0") == "1")
                            {
                                addBage(username.ToLower(), "subscriber");
                            }
                        }

                        if (ptags.SafeGet("turbo", "0") == "1")
                        {
                            addBage(username.ToLower(), "turbo");
                        }

                        if (ptags.SafeGet("user-type", "0") == "mod")
                        {
                            addBage(username.ToLower(), "moderator");
                        }

                        //parameters[1] = "Скажите позязя название сией композицииKappa";
                        if (string.Compare(username, _streamerNick, true) == 0)
                        {
                            addBage(username.ToLower(), "broadcaster");
                        }

                        string nick = ptags.SafeGet("display-name", username);

                        if (string.IsNullOrEmpty(nick))
                        {
                            nick = username;
                        }

                        var msg = new ChatMessage()
                        {
                            Date   = DateTime.Now,
                            Name   = nick,
                            Text   = Clean(text),   //ReplaceSmiles( username.ToLower(), parameters[1] ),
                            Source = this,
                            //Form = 0,
                            ToMe = this.ContainKeywords(parameters[1]),
                            Id   = _id
                        };

                        if (Properties.Settings.Default.twitch_AllowUseColors)
                        {
                            msg.Color = ptags.SafeGet("color", "");
                        }
                        else
                        {
                            msg.Color = "";
                        }

                        msg.AddBadges(getBages(username.ToLower()).ToArray());

                        msgs.Add(msg);
                    }
                    else
                    {
                    }
                    break;

                default:
                    break;
                }

                if (msgs.Count > 0)
                {
                    newMessagesArrived(msgs);
                }
                //if ( cmds.Count > 0 )
                //    newCommandsArrived( cmds );
            } catch (Exception ee) {
                App.Log('!', "Twitch error: {0}", ee);
                this.Header = "XError";
                MessageError("Oxlamon error: " + ee.Message);
                StartReconnect();
            }
        }