Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to ban the specified <see cref="IrcUser"/> from the <see cref="IrcChannel"/>.
        /// </summary>
        /// <param name="user">The <see cref="IrcUser"/>.</param>
        /// <param name="alsoKick">Optional. Whether the <see cref="IrcUser"/> should also be kicked out of the channel. True by default.</param>
        /// <param name="kickReason">Optional. If the <paramref name="alsoKick"/> parameter is set to true, the reason for the kick, if any.</param>
        /// <remarks>This method will only work if the current user is an operator on the <see cref="IrcChannel"/>.</remarks>
        public void BanUser(IrcUser user, bool alsoKick = true, string kickReason = "")
        {
            Validate.IsNotNull(user, "user");
            Validate.IsNotNull(kickReason, "kickReason");

            // MODE <channel name> +b <user name>
            this.Send("MODE", this.FullName, "+b", user.Nickname);

            if (alsoKick)
            {
                this.KickUser(user, kickReason);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds or removes a mode from the specified <see cref="IrcUser"/>'s mode on the <see cref="IrcChannel"/>.
        /// This method should be used for actual mode changes made using the MODE command.
        /// </summary>
        internal void AddOrRemoveUserMode(IrcUser user, bool add, char modeChar)
        {
            IrcChannelUserModes mode;

            if (!this.Network.Parameters.ChannelModes.UserModes.TryGetValue(modeChar, out mode))
            {
                return;
            }

            if (add)
            {
                this.UserModes[user] |= mode;
            }
            else
            {
                this.UserModes[user] &= ~mode;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a known <see cref="IrcUser"/> from their name.
        /// </summary>
        /// <param name="nickname">The user name.</param>
        /// <returns>The <see cref="IrcUser"/>.</returns>
        public IrcUser GetUser(string nickname)
        {
            Validate.IsNotDisposed(this._disposed);
            Validate.HasText(nickname, "nickname");
            IrcValidate.IsConnected(this.IsConnected);

            var user = this.KnownUsers.FirstOrDefault(u => this.Parameters.CaseMapping.AreEqual(u.Nickname, nickname));

            if (user == null)
            {
                user = new IrcUser(this.Client, this)
                {
                    Nickname = nickname
                };
                this.KnownUsersInternal.Add(user);
            }

            return(user);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to remove the specified flag from the specified <see cref="IrcUser"/>'s mode on the <see cref="IrcChannel"/>.
        /// </summary>
        /// <param name="user">The <see cref="IrcUser"/>.</param>
        /// <param name="mode">The mode.</param>
        /// <remarks>This method will only work if the current <see cref="IrcUser"/> is an operator on the <see cref="IrcChannel"/>.</remarks>
        public void RemoveUserMode(IrcUser user, IrcChannelUserModes mode)
        {
            Validate.IsNotNull(user, "user");
            Validate.IsEnumValue(mode, "mode");

            if (mode == IrcChannelUserModes.Normal)
            {
                return;
            }

            if (!this.Network.Parameters.ChannelModes.UserModes.Any(p => p.Value == mode))
            {
                throw new ArgumentException("The specified mode is not available on the network.");
            }

            string modeString = "-" + this.Network.Parameters.ChannelModes.UserModes.First(p => p.Value == mode).Key.ToString();

            // MODE <channel name> -<mode char> <user name>
            this.Send("MODE", this.FullName, modeString, user.Nickname);
        }
Ejemplo n.º 5
0
 internal InviteReceivedEventArgs(IrcUser sender)
 {
     this.Sender = sender;
 }
Ejemplo n.º 6
0
 internal MessageReceivedEventArgs(IrcUser sender, string message)
 {
     this.Sender  = sender;
     this.Message = message;
 }
Ejemplo n.º 7
0
 internal void OnUserKicked(IrcUser kickedUser, IrcUser kicker, string reason)
 {
     this.Raise(ref this.UserKicked, new UserKickedEventArgs(kickedUser, kicker, reason));
 }
Ejemplo n.º 8
0
 internal void OnModeChanged(string mode, IrcUser setter)
 {
     this.Raise(ref this.ModeChanged, new ModeChangedEventArgs(mode, setter));
 }
Ejemplo n.º 9
0
 internal void OnUserJoined(IrcUser user)
 {
     this.Raise(ref this.UserJoined, new UserEventArgs(user));
 }
Ejemplo n.º 10
0
 internal void OnUserLeft(IrcUser user, string reason)
 {
     this.Raise(ref this.UserLeft, new UserLeftEventArgs(user, reason));
 }
Ejemplo n.º 11
0
 internal void OnUserDiscovered(IrcUser user)
 {
     this.Raise(this.UserDiscovered, new UserEventArgs(user));
 }
Ejemplo n.º 12
0
 internal void OnInviteReceived(IrcUser sender)
 {
     this.Raise(ref this.InviteReceived, new InviteReceivedEventArgs(sender));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Removes the specified <see cref="IrcUser"/> from the <see cref="IrcChannel"/>.
 /// </summary>
 internal void RemoveUser(IrcUser user)
 {
     this.UserModes.RemoveUser(user);
     user.ChannelsInternal.Remove(this);
 }
Ejemplo n.º 14
0
 internal UserEventArgs(IrcUser user)
 {
     this.User = user;
 }
Ejemplo n.º 15
0
 internal UserLeftEventArgs(IrcUser user, string reason)
 {
     this.User   = user;
     this.Reason = reason;
 }
Ejemplo n.º 16
0
 internal UserKickedEventArgs(IrcUser kickedUser, IrcUser kicker, string reason)
 {
     this.KickedUser = kickedUser;
     this.Kicker     = kicker;
     this.Reason     = reason;
 }
Ejemplo n.º 17
0
 internal ModeChangedEventArgs(string mode, IrcUser setter)
 {
     this.Mode   = mode;
     this.Setter = setter;
 }
Ejemplo n.º 18
0
 internal void OnMessageReceived(IrcUser sender, string message)
 {
     this.Raise(ref this.MessageReceived, new MessageReceivedEventArgs(sender, message));
 }
 internal IrcUserChannelModePair(IrcUser user, IrcChannelUserModes mode)
 {
     this.User = user;
     this.Mode = mode;
 }