The IRC user.
Inheritance: IUser
コード例 #1
0
ファイル: IrcUserTests.cs プロジェクト: tom29739/helpmebot
        public void ShouldCreateFromPrefix2()
        {
            // arrange
            const string Prefix = "*****@*****.**";
            var expected = new IrcUser
            {
                Hostname = "foo.com",
                Nickname = "stwalkerster"
            };

            // act
            var actual = IrcUser.FromPrefix(Prefix);

            // assert
            Assert.That(actual, Is.EqualTo(expected));
        }
コード例 #2
0
ファイル: IrcUserTests.cs プロジェクト: tom29739/helpmebot
        public void ShouldCreateFromPrefix()
        {
            // arrange
            const string Prefix = "Yetanotherx|[email protected]";
            var expected = new IrcUser
                               {
                                   Hostname = "mcbouncer.com",
                                   Username = "******",
                                   Nickname = "Yetanotherx|afk"
                               };

            // act
            var actual = IrcUser.FromPrefix(Prefix);

            // assert
            Assert.That(actual, Is.EqualTo(expected));
        }
コード例 #3
0
ファイル: IrcUser.cs プロジェクト: tom29739/helpmebot
 /// <summary>
 /// The equals.
 /// </summary>
 /// <param name="other">
 /// The other.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 protected bool Equals(IrcUser other)
 {
     return string.Equals(this.Nickname, other.Nickname);
 }
コード例 #4
0
ファイル: IrcClient.cs プロジェクト: tom29739/helpmebot
        /// <summary>
        /// The on name reply received.
        /// </summary>
        /// <param name="e">
        /// The e.
        /// </param>
        private void OnNameReplyReceived(MessageReceivedEventArgs e)
        {
            List<string> parameters = e.Message.Parameters.ToList();

            string channel = parameters[2];
            string names = parameters[3];

            this.logger.DebugFormat("Names on {0}: {1}", channel, names);

            foreach (string name in names.Split(' '))
            {
                string parsedName = name;
                bool voice = false;
                bool op = false;

                if (parsedName.StartsWith("+"))
                {
                    parsedName = parsedName.Substring(1);
                    voice = true;
                }

                if (parsedName.StartsWith("@"))
                {
                    parsedName = parsedName.Substring(1);
                    op = true;
                }

                lock (this.userOperationLock)
                {
                    if (this.channels[channel].Users.ContainsKey(parsedName))
                    {
                        IrcChannelUser channelUser = this.channels[channel].Users[parsedName];
                        channelUser.Operator = op;
                        channelUser.Voice = voice;
                    }
                    else
                    {
                        var ircUser = new IrcUser { Nickname = parsedName };
                        if (this.UserCache.ContainsKey(parsedName))
                        {
                            ircUser = this.UserCache[parsedName];
                        }
                        else
                        {
                            this.UserCache.Add(parsedName, ircUser);
                        }

                        var channelUser = new IrcChannelUser(ircUser, channel) { Voice = voice, Operator = op };

                        this.channels[channel].Users.Add(parsedName, channelUser);
                    }
                }
            }
        }
コード例 #5
0
ファイル: IrcClient.cs プロジェクト: tom29739/helpmebot
        /// <summary>
        /// The handle who x reply.
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        private void HandleWhoXReply(IMessage message)
        {
            try
            {
                if (message.Command != Numerics.WhoXReply)
                {
                    throw new ArgumentException("Expected WHOX reply message", "message");
                }

                List<string> parameters = message.Parameters.ToList();
                if (parameters.Count() != 8)
                {
                    throw new ArgumentException("Expected 8 WHOX parameters.", "message");
                }

                /* >> :holmes.freenode.net 354 stwalkerster 001 #wikipedia-en-accounts ChanServ services.           ChanServ       H@  0
                 * >> :holmes.freenode.net 354 stwalkerster 001 #wikipedia-en-accounts ~jamesur wikimedia/Jamesofur Jamesofur|away G  jamesofur
                 *                             .            t   c                      u        h                   n              f  a
                 *     prefix              cmd    0         1   2                      3        4                   5              6  7
                 */
                string channel = parameters[2];
                string user = parameters[3];
                string host = parameters[4];
                string nick = parameters[5];
                string flags = parameters[6];
                bool away = flags[0] == 'G'; // H (here) / G (gone)
                string modes = flags.Substring(1);
                string account = parameters[7];

                lock (this.userOperationLock)
                {
                    var ircUser = new IrcUser();
                    if (this.UserCache.ContainsKey(nick))
                    {
                        ircUser = this.UserCache[nick];
                    }
                    else
                    {
                        ircUser.Nickname = nick;
                        this.UserCache.Add(nick, ircUser);
                    }

                    ircUser.Account = account;
                    ircUser.Username = user;
                    ircUser.Hostname = host;
                    ircUser.Away = away;

                    if (this.channels[channel].Users.ContainsKey(ircUser.Nickname))
                    {
                        IrcChannelUser channelUser = this.channels[channel].Users[ircUser.Nickname];
                        channelUser.Operator = modes.Contains("@");
                        channelUser.Voice = modes.Contains("+");
                    }
                    else
                    {
                        var channelUser = new IrcChannelUser(ircUser, channel)
                                              {
                                                  Operator = modes.Contains("@"), 
                                                  Voice = modes.Contains("+")
                                              };

                        this.channels[channel].Users.Add(ircUser.Nickname, channelUser);
                    }
                }
            }
            catch (Exception ex)
            {
                this.nickTrackingValid = false;
                this.logger.Error("Nick tracking for authentication is no longer valid.", ex);
                throw;
            }
        }
コード例 #6
0
ファイル: IrcUserTests.cs プロジェクト: tom29739/helpmebot
        public void ShouldCreateFromPrefix4()
        {
            // arrange
            const string Prefix = "nick!user@host";
            var expected = new IrcUser
            {
                Hostname = "host",
                Username = "******",
                Nickname = "nick"
            };

            // act
            var actual = IrcUser.FromPrefix(Prefix);

            // assert
            Assert.That(actual, Is.EqualTo(expected));
        }