示例#1
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var crh = new CommandResponseHandler();
            Dictionary<string, Helpmebot.Monitoring.CategoryWatcher>.KeyCollection kc = WatcherController.Instance().GetKeywords();

            List<string> args = this.Arguments.ToList();

            if (args.Contains("@cats"))
            {
                args.Remove("@cats");

                var messageService = this.CommandServiceHelper.MessageService;
                string listSep = messageService.RetrieveMessage("listSeparator", this.Channel, null);
                string list = messageService.RetrieveMessage("allCategoryCodes", this.Channel, null);

                foreach (string item in kc)
                {
                    list += item;
                    list += listSep;
                }

                crh.Respond(list.TrimEnd(listSep.ToCharArray()));
            }
            else
            {
                foreach (string key in kc)
                {
                    crh.Respond(WatcherController.Instance().ForceUpdate(key, this.Channel), CommandResponseDestination.PrivateMessage);
                }
            }
            
            return crh;
        }
示例#2
0
        /// <summary>
        ///     Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var crh = new CommandResponseHandler();

            IMessageService messageService = this.CommandServiceHelper.MessageService;
            if (this.Arguments.Length > 0 && this.Arguments[0] != string.Empty)
            {
                foreach (string s in this.Arguments)
                {
                    var legacyUser = LegacyUser.NewFromString(s);

                    if (legacyUser == null)
                    {
                        string[] errArgs = { s };
                        crh.Respond(messageService.RetrieveMessage("cmdAccessInvalidUser", this.Channel, errArgs));
                        continue;
                    }

                    string[] cmdArgs = { s, legacyUser.AccessLevel.ToString() };
                    crh.Respond(messageService.RetrieveMessage("cmdAccess", this.Channel, cmdArgs));
                }
            }
            else
            {
                string[] cmdArgs = { this.Source.ToString(), this.Source.AccessLevel.ToString() };
                crh.Respond(messageService.RetrieveMessage("cmdAccess", this.Channel, cmdArgs));
            }

            return crh;
        }
示例#3
0
        /// <summary>
        ///     Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            string[] statuses = ThreadList.GetInstance().GetAllThreadStatus();
            var crh = new CommandResponseHandler();
            foreach (string item in statuses)
            {
                crh.Respond(item);
            }

            return crh;
        }
示例#4
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            CommandResponseHandler crh = new CommandResponseHandler();
            if (this.Arguments.Length == 1)
            {
                // just do category check
                crh.Respond(WatcherController.Instance().ForceUpdate(this.Arguments[0], this.Channel));
            }
            else
            {
                // do something else too.
                Type subCmdType =
                    Type.GetType("helpmebot6.Commands.CategoryWatcherCommand." + this.Arguments[1].Substring(0, 1).ToUpper() +
                                 this.Arguments[1].Substring(1).ToLower());
                if (subCmdType != null)
                {
                    return ((GenericCommand)Activator.CreateInstance(subCmdType, this.Source, this.Channel, this.Arguments, this.CommandServiceHelper)).RunCommand();
                }
            }

            return crh;
        }
示例#5
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var response = new CommandResponseHandler();

            if (this.Arguments.Length == 0)
            {
                response.Respond(this.CommandServiceHelper.MessageService.NotEnoughParameters(this.Channel, "Welcomer", 1, 0));
                return response;
            }
            
            List<string> argumentsList = this.Arguments.ToList();
            var mode = argumentsList.PopFromFront();

            this.databaseSession.BeginTransaction(IsolationLevel.RepeatableRead);

            switch (mode.ToLower())
            {
                case "enable":
                case "disable":
                    response.Respond(
                        this.CommandServiceHelper.MessageService.RetrieveMessage("Welcomer-ObsoleteOption", this.Channel, new[] { mode }),
                        CommandResponseDestination.PrivateMessage);
                    break;
                case "add":
                    this.AddMode(argumentsList, response);
                    break;
                case "del":
                case "delete":
                case "remove":
                    this.DeleteMode(argumentsList, response);
                    break;
                case "list":
                    this.ListMode(response);
                    break;
            }
            
            return response;
        }
示例#6
0
        /// <summary>
        ///     Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var crh = new CommandResponseHandler();
            IMessageService messageService = this.CommandServiceHelper.MessageService;
            if (this.Arguments.Length > 1)
            {
                switch (this.Arguments[0].ToLower())
                {
                    case "add":
                        if (this.Arguments.Length > 2)
                        {
                            var aL = LegacyUser.UserRights.Normal;

                            switch (this.Arguments[2].ToLower())
                            {
                                case "superuser":
                                    aL = LegacyUser.UserRights.Superuser;
                                    break;
                                case "advanced":
                                    aL = LegacyUser.UserRights.Advanced;
                                    break;
                                case "semi-ignored":
                                    aL = LegacyUser.UserRights.Semiignored;
                                    break;
                                case "semiignored":
                                    aL = LegacyUser.UserRights.Semiignored;
                                    break;
                                case "ignored":
                                    aL = LegacyUser.UserRights.Ignored;
                                    break;
                                case "normal":
                                    aL = LegacyUser.UserRights.Normal;
                                    break;
                            }

                            var legacyUser = LegacyUser.NewFromString(this.Arguments[1]);

                            if (legacyUser == null)
                            {
                                string[] errArgs = { this.Arguments[1] };
                                crh.Respond(messageService.RetrieveMessage("cmdAccessInvalidUser", this.Channel, errArgs));
                                return crh;
                            }

                            crh = this.AddAccessEntry(legacyUser, aL);
                        }
                        else
                        {
                            string[] messageParameters =
                                {
                                    "access add", "3", 
                                    this.Arguments.Length.ToString(CultureInfo.InvariantCulture)
                                };
                            return
                                new CommandResponseHandler(
                                    messageService.RetrieveMessage(
                                        "notEnoughParameters", 
                                        this.Channel, 
                                        messageParameters));
                        }

                        break;
                    case "del":
                        crh = this.DeleteAccessEntry(int.Parse(this.Arguments[1]));
                        break;
                }

                /*
                 * add <source> <level>
                 *
                 * del <id>
                 */
            }
            else
            {
                string[] messageParameters =
                    {
                        "access", "2", 
                        this.Arguments.Length.ToString(CultureInfo.InstalledUICulture)
                    };
                return
                    new CommandResponseHandler(
                        messageService.RetrieveMessage("notEnoughParameters", this.Channel, messageParameters));
            }

            return crh;
        }
示例#7
0
 /// <summary>
 /// The list mode.
 /// </summary>
 /// <param name="response">
 /// The response.
 /// </param>
 private void ListMode(CommandResponseHandler response)
 {
     var welcomeForChannel =
         this.databaseSession.QueryOver<WelcomeUser>().Where(x => x.Channel == this.Channel).List();
     welcomeForChannel.ForEach(x => response.Respond(x.ToString()));
 }
示例#8
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();
            }
        }
示例#9
0
        /// <summary>
        /// The delete mode.
        /// </summary>
        /// <param name="argumentsList">
        /// The arguments list.
        /// </param>
        /// <param name="response">
        /// The response.
        /// </param>
        private void DeleteMode(List<string> argumentsList, CommandResponseHandler response)
        {
            try
            {
                this.Log.Debug("Getting list of welcomeusers ready for deletion!");

                var exception = false;

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

                var implode = argumentsList.Implode();

                var welcomeUsers =
                    this.databaseSession.QueryOver<WelcomeUser>()
                        .Where(x => x.Exception == exception && x.Host == implode && x.Channel == this.Channel)
                        .List();

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

                welcomeUsers.ForEach(this.databaseSession.Delete);

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

                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();
            }
        }
示例#10
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var args = this.Arguments;
            
            var deployInProgressMessage = this.CommandServiceHelper.MessageService.RetrieveMessage("DeployInProgress", this.Channel, null); 
            this.CommandServiceHelper.Client.SendMessage(this.Channel, deployInProgressMessage);

            string revision;

            bool showUrl = false;

            if (args[0].ToLower() == "@url")
            {
                showUrl = true;
                GlobalFunctions.PopFromFront(ref args);
            }

            if (args.Length > 0 && args[0] != string.Empty)
            {
                revision = string.Join(" ", args);
            }
            else
            {
                throw new ArgumentException();
            }
            
            string apiDeployPassword = LegacyConfig.Singleton()["accDeployPassword"];

            string key = this.EncodeMD5(this.EncodeMD5(revision) + apiDeployPassword);

            revision = HttpUtility.UrlEncode(revision);

            string requestUri = "http://accounts-dev.wmflabs.org/deploy/deploy.php?r=" + revision + "&k=" + key;

            using (Stream data = HttpRequest.Get(requestUri, 1000 * 30 /* 30 sec timeout */).ToStream())
            {
                var r = new StreamReader(data);

                var crh = new CommandResponseHandler();
                if (showUrl)
                {
                    crh.Respond(requestUri, CommandResponseDestination.PrivateMessage);
                }

                foreach (var x in r.ReadToEnd().Split('\n', '\r'))
                {
                    crh.Respond(x);
                }

                return crh;
            }
        }
示例#11
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;
        }
示例#12
0
        /// <summary>
        ///     Access granted to command, decide what to do
        /// </summary>
        /// <returns>The response to the command</returns>
        protected virtual CommandResponseHandler ReallyRunCommand()
        {
            if (
                !AccessLog.Instance()
                     .Save(
                         new AccessLog.AccessLogEntry(
                     this.Source, 
                     this.GetType(), 
                     true, 
                     this.Channel, 
                     this.Arguments, 
                     this.AccessLevel)))
            {
                var errorResponse = new CommandResponseHandler();
                string message = this.CommandServiceHelper.MessageService.RetrieveMessage(
                    "AccessDeniedAccessListFailure", 
                    this.Channel, 
                    null);
                errorResponse.Respond(
                    "Error adding to access log - command aborted.", 
                    CommandResponseDestination.ChannelDebug);
                errorResponse.Respond(message, CommandResponseDestination.Default);
                return errorResponse;
            }

            this.Log.Info("Starting command execution...");
            CommandResponseHandler crh;
            try
            {
                crh = this.ExecuteCommand();
            }
            catch (Exception ex)
            {
                this.Log.Error(ex.Message, ex);
                crh = new CommandResponseHandler(ex.Message);
            }

            this.Log.Info("Command execution complete.");
            return crh;
        }
示例#13
0
        /// <summary>
        ///     Access denied to command, decide what to do
        /// </summary>
        /// <returns>A response to the command if access to the command was denied</returns>
        protected virtual CommandResponseHandler OnAccessDenied()
        {
            var response = new CommandResponseHandler();

            string message = this.CommandServiceHelper.MessageService.RetrieveMessage("AccessDenied", this.Channel, null);

            response.Respond(message, CommandResponseDestination.PrivateMessage);
            this.Log.Info("Access denied to command.");
            if (
                !AccessLog.Instance()
                     .Save(
                         new AccessLog.AccessLogEntry(
                     this.Source, 
                     this.GetType(), 
                     false, 
                     this.Channel, 
                     this.Arguments, 
                     this.AccessLevel)))
            {
                response.Respond("Error adding denied entry to access log.", CommandResponseDestination.ChannelDebug);
            }

            return response;
        }
示例#14
0
        /// <summary>
        ///     Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var crh = new CommandResponseHandler();

            string userName;
            if (this.Arguments.Length > 0 && this.Arguments[0] != string.Empty)
            {
                userName = string.Join(" ", this.Arguments);
            }
            else
            {
                userName = this.Source.Nickname;
            }

            string rights = GetRights(userName, this.Channel);

            string message;
            var messageService = this.CommandServiceHelper.MessageService;
            if (rights != string.Empty)
            {
                string[] messageParameters = { userName, rights };
                message = messageService.RetrieveMessage("cmdRightsList", this.Channel, messageParameters);
            }
            else
            {
                string[] messageParameters = { userName };
                message = messageService.RetrieveMessage("cmdRightsNone", this.Channel, messageParameters);
            }

            crh.Respond(message);
            return crh;
        }
示例#15
0
 /// <summary>
 /// Appends the specified more responses.
 /// </summary>
 /// <param name="moreResponses">
 /// The more responses.
 /// </param>
 public void Append(CommandResponseHandler moreResponses)
 {
     foreach (object item in moreResponses.GetResponses())
     {
         this.responses.Add(item);
     }
 }
示例#16
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <returns>the response</returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            // TODO: link to basewiki
            var uri = "https://en.wikipedia.org/w/api.php?action=query&prop=revisions|info&rvprop=user|comment&redirects&inprop=protection&format=xml&titles="
                      + string.Join(" ", this.Arguments);
            using (Stream rawDataStream = HttpRequest.Get(uri).ToStream())
            {
                var xtr = new XmlTextReader(rawDataStream);

                var crh = new CommandResponseHandler();

                string redirects = null;
                var protection = new ArrayList();
                string title;
                string size;
                string comment;
                DateTime touched = DateTime.MinValue;
                string user = title = comment = size = null;

                var messageService = this.CommandServiceHelper.MessageService;
                while (!xtr.EOF)
                {
                    xtr.Read();
                    if (xtr.IsStartElement())
                    {
                        switch (xtr.Name)
                        {
                            case "r":
                                // redirect!
                                // <r from="Sausages" to="Sausage" />
                                redirects = xtr.GetAttribute("from");
                                break;
                            case "page":
                                if (xtr.GetAttribute("missing") != null)
                                {
                                    var msg = messageService.RetrieveMessage("pageMissing", this.Channel, null);
                                    return new CommandResponseHandler(msg);
                                }

                                title = xtr.GetAttribute("title");
                                touched = DateTime.Parse(xtr.GetAttribute("touched"));

                                break;
                            case "rev":
                                // user, comment
                                // <rev user="******" comment="..." />
                                user = xtr.GetAttribute("user");
                                comment = xtr.GetAttribute("comment");
                                break;
                            case "pr":
                                // protections
                                // <pr type="edit" level="autoconfirmed" expiry="2010-06-30T18:36:52Z" />
                                string time = xtr.GetAttribute("expiry");
                                protection.Add(
                                    new PageProtection(
                                        xtr.GetAttribute("type"),
                                        xtr.GetAttribute("level"),
                                        time == "infinity" ? DateTime.MaxValue : DateTime.Parse(time)));
                                break;
                        }
                    }
                }

                if (redirects != null)
                {
                    string[] redirArgs = { redirects, title };
                    crh.Respond(messageService.RetrieveMessage("pageRedirect", this.Channel, redirArgs));
                }

                string[] margs = { title, user, touched.ToString(CultureInfo.InvariantCulture), comment, size };
                crh.Respond(messageService.RetrieveMessage("pageMainResponse", this.Channel, margs));

                foreach (PageProtection p in protection)
                {
                    string[] pargs =
                        {
                            title, p.Type, p.Level,
                            p.Expiry == DateTime.MaxValue ? "infinity" : p.Expiry.ToString()
                        };
                    crh.Respond(messageService.RetrieveMessage("pageProtected", this.Channel, pargs));
                }

                return crh;
            }
        }
示例#17
0
        /// <summary>
        ///     The execute command.
        /// </summary>
        /// <returns>
        ///     The <see cref="CommandResponseHandler" />.
        /// </returns>
        protected override CommandResponseHandler ExecuteCommand()
        {
            var crh = new CommandResponseHandler();
            var messageService = this.CommandServiceHelper.MessageService;
            if (this.Arguments.Length > 0)
            {
                string userName = string.Join(" ", this.Arguments);
                DateTime registrationDate = GetRegistrationDate(userName, this.Channel);
                if (registrationDate == new DateTime(0))
                {
                    string[] messageParams = { userName };
                    string message = messageService.RetrieveMessage("noSuchUser", this.Channel, messageParams);
                    crh.Respond(message);
                }
                else
                {
                    string[] messageParameters =
                        {
                            userName, registrationDate.ToString("hh:mm:ss t"), 
                            registrationDate.ToString("d MMMM yyyy")
                        };
                    string message = messageService.RetrieveMessage(
                        "registrationDate", 
                        this.Channel, 
                        messageParameters);
                    crh.Respond(message);
                }
            }
            else
            {
                string[] messageParameters =
                    {
                        "registration", "1", 
                        this.Arguments.Length.ToString(CultureInfo.InvariantCulture)
                    };

                string notEnoughParamsMessage = messageService.RetrieveMessage(Messages.NotEnoughParameters, this.Channel, messageParameters);
                this.CommandServiceHelper.Client.SendNotice(this.Source.Nickname, notEnoughParamsMessage);
            }

            return crh;
        }