Ejemplo n.º 1
0
 public IrcScriptWhoIs(EcmaState state, WhoIsData data)
 {
     this.data = data;
     this.Put("nick", EcmaValue.String(data.Nick));
     this.Put("channels", EcmaValue.Object(EcmaUntil.ToArray(state, new List <object>(data.Channels))));
     this.Put("isAway", EcmaValue.Boolean(data.Away));
     this.Put("awayMessage", EcmaValue.String(data.AwayMessage));
 }
Ejemplo n.º 2
0
        private void HandleMessage(IrcMessage message)
        {
            //if message is null we do not handle the request
            if (message == null)
            {
                return;
            }

            //let us se if this is a type as int
            double d;

            if (double.TryParse(message.Type, out d))
            {
                switch (message.Type)
                {
                case "001":
                    foreach (string channel in this.Channels)
                    {
                        this.SendLine("JOIN " + channel);
                    }
                    this.Flush();
                    break;

                case "301":
                    nick = message.ParamsMidle.Split(' ')[1];
                    if (this.whois.ContainsKey(nick))
                    {
                        whois[nick].Away        = true;
                        whois[nick].AwayMessage = message.ParamsTrailing;
                    }
                    break;

                case "311":
                    string[]  wn = message.ParamsMidle.Split(' ');
                    WhoIsData wd = new WhoIsData();
                    wd.Nick = wn[1];
                    if (this.whois.ContainsKey(wn[1]))
                    {
                        this.whois[wn[1]] = wd;
                    }
                    else
                    {
                        this.whois.Add(wn[1], wd);
                    }
                    break;

                case "317":
                    nick = message.ParamsMidle.Split(' ')[1];
                    if (this.whois.ContainsKey(nick))
                    {
                    }
                    break;

                case "318":
                    nick = message.ParamsMidle.Split(' ')[1];
                    if (this.whois.ContainsKey(nick))
                    {
                        if (this.scriptAction.ContainsKey("server.whois"))
                        {
                            this.DoAction("server.whois", new ScriptWhoIsData(this.script.State, this.whois[nick]));
                        }
                    }
                    break;

                case "319":
                    nick = message.ParamsMidle.Split(' ')[1];
                    if (this.whois.ContainsKey(nick))
                    {
                        this.whois[nick].Channels = message.ParamsTrailing.Split(' ');
                    }
                    break;

                case "332":
                    this.Main.SetTopic(this.identify, message.ParamsMidle.Substring(message.ParamsMidle.LastIndexOf(' ') + 1), message.ParamsTrailing);
                    break;

                case "353":
                    string[] users = message.ParamsTrailing.Split(' ');
                    for (int i = 0; i < users.Length; i++)
                    {
                        char     prefix = users[i].ToCharArray()[0];
                        UserInfo info   = new UserInfo();
                        if (prefix == '+' || prefix == '@')
                        {
                            info.Nick  = users[i].Substring(1);
                            info.Op    = prefix == '@';
                            info.Voice = prefix == '+';
                        }
                        else
                        {
                            info.Nick = users[i];
                        }
                        this.Main.AppendUser(this.identify, message.ParamsMidle.Substring(message.ParamsMidle.LastIndexOf(' ') + 1), info);

                        if (this.scriptEvenets.ContainsKey("353"))
                        {
                            this.DoPlugin("353", new ScriptUserInfo(info));
                        }
                    }
                    break;
                }

                if (this.events != null)
                {
                    this.events(this, message);
                }
            }
            else
            {
                this.events?.Invoke(this, message);

                if (this.scriptEvenets.ContainsKey(message.Type))
                {
                    this.DoPlugin(message.Type, new IrcScriptMessage(message));
                }
            }
        }