예제 #1
0
        public void ShowTab()
        {
            List <IrcChannelViewModel> icvm = new List <IrcChannelViewModel>();
            List <IrcNetworkViewModel> invm = new List <IrcNetworkViewModel>();
            IrcMainView         imv         = (IrcMainView)this.SV.ActiveItem.Content;
            IrcMainViewModel    imvm        = (IrcMainViewModel)imv.DataContext;
            IrcNetworkViewModel y           = null;

            for (int i = 0; i < imv.Items.Items.Count; i++)
            {
                invm.Add((IrcNetworkViewModel)imv.Items.Items[i]);
            }
            foreach (IrcNetworkViewModel inv in invm)
            {
                if (inv.DisplayName == this.Network)
                {
                    imvm.ActivateItem(inv);
                    y = inv;
                }
            }
            IrcNetworkView z = y.GetView() as IrcNetworkView;

            for (int i = 1; i < z.Items.Items.Count; i++)
            {
                icvm.Add((IrcChannelViewModel)z.Items.Items[i]);
            }
            foreach (IrcChannelViewModel ic in icvm)
            {
                if (ic.Channel.Name == this.Channel)
                {
                    y.ActivateItem(ic);
                }
            }
            this.TryClose();
        }
예제 #2
0
        public void Send()
        {
            // TODO Ignore adjacent duplicates
            this.personalHistory.Add(this.Message);
            this.historyIndex = -1;

            if (this.Message[0] != '/')
            {
                // Regular message
                this.Channel.Client.LocalUser.SendMessage(this.Channel, this.Message);
                Message m = new Message(this.Message.Trim(),
                                        DateTime.Now.ToString(this.Settings.TimestampFormat),
                                        this.Channel.Client.LocalUser.NickName,
                                        MessageLevels.Public);
                this.Messages.Add(m);
                if (this.Settings.CanLog && this.logger != null)
                {
                    logger.Append(string.Format("{0} {1}: {2}", m.Received, m.Sender, m.Text));
                }
                this.Message = string.Empty;
                return;
            }

            string command;

            string[] args;

            this.Message = this.Message.TrimEnd(' ');
            if (this.Message.Contains(" "))
            {
                command = this.Message.Substring(1, this.Message.IndexOf(' ') - 1).ToLower();
                args    = this.Message.Substring(this.Message.IndexOf(' '), this.Message.Length - command.Length - 1)
                          .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                command = this.Message.Substring(1, this.Message.Length - 1);
                args    = new string[] { };
            }

            IrcNetworkViewModel invm = (IrcNetworkViewModel)this.Parent;
            IrcMainViewModel    imvm = (IrcMainViewModel)invm.Parent;

            switch (command)
            {
            // TODO No such nick
            case "help":
                // TODO "/help command"
                this.Messages.Add(new Message("Helptext.",
                                              DateTime.Now.ToString(this.Settings.TimestampFormat), "=!=",
                                              MessageLevels.Clientside));
                break;

            case "join":
            case "j":
                if (args.Length == 1)
                {
                    this.Channel.Client.Channels.Join(args[0]);
                }
                else if (args.Length == 2)
                {
                    this.Channel.Client.Channels.Join(args[0], args[1]);
                }
                else
                {
                    this.Messages.Add(new Message(string.Format("Invalid number of arguments for the command \"{0}\"!", command),
                                                  DateTime.Now.ToString(this.Settings.TimestampFormat), "=!=",
                                                  MessageLevels.Clientside));
                }
                break;

            case "whois":
                this.WhoIs(args[0]);
                break;

            case "clear":
                this.ClearMessages();
                break;

            case "complete":
                if (args[0] == "-d" || args[0] == "--delete")
                {
                    this.Settings.Completions.Remove(args[1]);
                }
                else
                {
                    this.Settings.Completions[args[0]] = string.Join(" ", args.Range(1, -1));
                }
                this.Settings.Save();
                break;

            case "disconnect":
                imvm.CloseItem(invm);
                break;

            case "part":
                if (args.Length < 2)
                {
                    invm.CloseItem(this);
                }
                else
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        for (int y = 1; y < invm.Items.Count; y++)
                        {
                            IrcChannelViewModel icvm = invm.Items[y];
                            if (icvm.DisplayName == args[i].ToString())
                            {
                                invm.CloseItem(icvm);
                            }
                        }
                    }
                }
                break;

            case "msg":
                IrcQueryViewModel ipcvm  = null;
                IrcUser           target = null;

                var message = string.Join(" ", args.Range(1, -1));

                foreach (var u in this.Channel.Users)
                {
                    if (u.User.NickName == args[0])
                    {
                        target = u.User;
                        break;
                    }
                }

                if (target == null)
                {
                    this.Messages.Add(new Message("User does not exist!",
                                                  DateTime.Now.ToString(this.Settings.TimestampFormat),
                                                  "=!=",
                                                  MessageLevels.Clientside, MessageLevels.Error));
                    return;
                }

                foreach (var item in (this.Parent as IrcNetworkViewModel).Items)
                {
                    if (item.DisplayName == args[0])
                    {
                        ipcvm = item;
                    }
                }

                if (ipcvm == null)
                {
                    ipcvm = new IrcQueryViewModel(target, this.Channel.Client, this.Settings);
                    (this.Parent as IrcNetworkViewModel).Items.Add(ipcvm);
                }

                (this.Parent as IrcNetworkViewModel).ActivateItem(ipcvm);

                this.Channel.Client.LocalUser.SendMessage(args[0], message);

                ipcvm.Messages.Add(new Message(message,
                                               DateTime.Now.ToString(this.Settings.TimestampFormat),
                                               target.NickName, MessageLevels.Private));

                break;

            case "nick":
                switch (args.Length)
                {
                case 0:
                    this.Messages.Add(new Message("You are " + this.Channel.Client.LocalUser.NickName + ".",
                                                  DateTime.Now.ToString(this.Settings.TimestampFormat),
                                                  "=!=", MessageLevels.Clientside));
                    break;

                case 1:
                    this.Channel.Client.LocalUser.SetNickName(args[0]);
                    this.Messages.Add(new Message("Changed nick to " + args[0] + ".",
                                                  DateTime.Now.ToString(this.Settings.TimestampFormat),
                                                  "=!=", MessageLevels.Clientside));
                    break;

                default:
                    this.Messages.Add(new Message("Invalid number of arguments for command '/nick'.",
                                                  DateTime.Now.ToString(this.Settings.TimestampFormat),
                                                  "=!=", MessageLevels.Clientside, MessageLevels.Error));
                    break;
                }
                break;

            case "quit":
                for (int i = 0; i < invm.Items.Count; i++)
                {
                    IrcNetworkViewModel net = invm.Items[i];
                    imvm.CloseItem(net);
                }
                break;

            case "motd":
                this.Messages.Add(new Message(this.Channel.Client.MessageOfTheDay,
                                              DateTime.Now.ToString(this.Settings.TimestampFormat), "=!=",
                                              MessageLevels.Clientside));
                break;

            case "names":
                //TODO Nachrichten haben keinen Zeilenumbruch, wenn zu lange
                string users = "";
                foreach (IrcChannelUser iu in this.Users)
                {
                    users += iu.User.NickName + ",";
                }
                this.Messages.Add(new Message(users,
                                              DateTime.Now.ToString(this.Settings.TimestampFormat), "=!=",
                                              MessageLevels.Clientside));
                break;

            default:
                this.Messages.Add(new Message(string.Format("Unknown command \"{0}\".", command),
                                              DateTime.Now.ToString(this.Settings.TimestampFormat),
                                              "=!=",
                                              MessageLevels.Clientside, MessageLevels.Error));
                break;
            }
            this.Message = string.Empty;
        }