예제 #1
0
        /// <summary>
        /// Kicks a user from a channel
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="user"></param>
        /// <param name="reason"></param>
        /// <returns>TRUE if the user is sucessfully kicked</returns>
        public bool KickUser(string channel, IUser user, string reason)
        {
            if (channel.Length < 2 || channel[0] != '#')
            {
                throw new InvalidChannelException();
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (user.IsService)
            {
                throw new CannotKickServiceException();
            }
            ChannelEntry currentEntry = User.GetChannelEntry(channel);
            if (currentEntry == null)
            {
                throw new NotOnChannelException();
            }
            if ((currentEntry.Op == false) && (currentEntry.HalfOp == false))
            {
                throw new NotAChannelOperatorException();
            }
            ChannelEntry userEntry = user.GetChannelEntry(channel);
            if (userEntry == null)
            {
                throw new NotOnChannelException();
            }
            if ((userEntry.HalfOp == true) && (currentEntry.HalfOp == true))
            {
                throw new NotAChannelOperatorException();
            }

            var command =
                Plugin.Service.CommandFactory.CreateKickUserCommand();
            command.From = User;
            command.User = user;
            command.Channel = channel;
            command.Reason = reason;
            Plugin.Service.SendCommand(command);
            return true;
        }