/// <summary>
        /// The setup.
        /// </summary>
        public override void LocalSetup()
        {
            this.welcomeUser = new WelcomeUser { Host = "ab/.*", User = "******", Nick = ".*" };
            this.ignoreUser = new WelcomeUser { Host = ".*", User = "******", Nick = ".*", Exception = true };

            this.session = new Mock<ISession>();
        }
        public void Setup()
        {
            var welcomeUser = new WelcomeUser { Host = "ab/.*", User = "******", Nick = ".*" };
            var ignoreUser = new WelcomeUser { Host = ".*", User = "******", Nick = ".*" };

            this.userRepo.Setup(x => x.GetWelcomeForChannel("ab"))
                .Returns(new List<WelcomeUser> { welcomeUser });

            this.userRepo.Setup(x => x.GetExceptionsForChannel("ab"))
                .Returns(new List<WelcomeUser> { ignoreUser });
        }
Esempio n. 3
0
        /// <summary>
        /// The add mode.
        /// </summary>
        /// <param name="argumentsList">
        /// The arguments list.
        /// </param>
        /// <param name="response">
        /// The response.
        /// </param>
        private void AddMode(List<string> argumentsList, CommandResponseHandler response)
        {
            try
            {
                var exception = false;

                if (argumentsList[0] == "@ignore")
                {
                    exception = true;
                    argumentsList.RemoveAt(0);
                }

                var welcomeUser = new WelcomeUser
                                      {
                                          Nick = ".*",
                                          User = "******",
                                          Host = argumentsList.Implode(),
                                          Channel = this.Channel,
                                          Exception = exception
                                      };

                this.databaseSession.Save(welcomeUser);

                response.Respond(this.CommandServiceHelper.MessageService.Done(this.Channel));

                this.databaseSession.Transaction.Commit();
            }
            catch (Exception e)
            {
                this.Log.Error("Error occurred during addition of welcome mask.", e);
                response.Respond(e.Message);

                this.databaseSession.Transaction.Rollback();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var response = new CommandResponseHandler();

            var messageService = this.CommandServiceHelper.MessageService;
            if (this.Arguments.Length == 0)
            {
                response.Respond(messageService.NotEnoughParameters(this.Channel, "Welcomer", 1, 0));
                return response;
            }

            // FIXME: ServiceLocator - welcomeuserrepo
            var repository = ServiceLocator.Current.GetInstance<IWelcomeUserRepository>();

            List<string> argumentsList = this.Arguments.ToList();
            var mode = argumentsList.PopFromFront();

            switch (mode.ToLower())
            {
                case "enable":
                case "disable":
                    response.Respond(
                        messageService.RetrieveMessage("Welcomer-ObsoleteOption", this.Channel, new[] { mode }),
                        CommandResponseDestination.PrivateMessage);
                    break;
                case "add":
                    var welcomeUser = new WelcomeUser
                                          {
                                              Nick = ".*",
                                              User = "******",
                                              Host = string.Join(" ", argumentsList.ToArray()),
                                              Channel = this.Channel,
                                              Exception = false
                                          };
                    repository.Save(welcomeUser);

                    response.Respond(messageService.Done(this.Channel));
                    break;
                case "del":
                case "Delete":
                case "remove":

                    this.Log.Debug("Getting list of welcomeusers ready for deletion!");

                    // TODO: move to repository.
                    var criteria = Restrictions.And(
                        Restrictions.Eq("Host", string.Join(" ", argumentsList.ToArray())),
                        Restrictions.Eq("Channel", this.Channel));

                    var welcomeUsers = repository.Get(criteria);

                    this.Log.Debug("Got list of WelcomeUsers, proceeding to Delete...");

                    repository.Delete(welcomeUsers);

                    this.Log.Debug("All done, cleaning up and sending message to IRC");

                    response.Respond(messageService.Done(this.Channel));
                    break;
                case "list":
                    var welcomeForChannel = repository.GetWelcomeForChannel(this.Channel);
                    welcomeForChannel.ForEach(x => response.Respond(x.Host));
                    break;
            }

            return response;
        }