示例#1
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            string revision;

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

            string apiDeployPassword = Configuration.singleton()["accDeployPassword"];

            string key = md5(md5(revision) + apiDeployPassword);

            revision = HttpUtility.UrlEncode(revision);

            var r = new StreamReader(
                HttpRequest.get("http://toolserver.org/~acc/deploy/deploy.php?r=" + revision + "&k=" + key,
                                1000 * 30 // 30 sec timeout
                                ));



            var crh = new CommandResponseHandler();

            foreach (var x in r.ReadToEnd().Split('\n', '\r'))
            {
                crh.respond(x);
            }
            return(crh);
        }
示例#2
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            CommandResponseHandler crh = new CommandResponseHandler();

            string userName;

            if (args.Length > 0 && args[0] != "")
            {
                userName = string.Join(" ", args);
            }
            else
            {
                userName = source.nickname;
            }
            string rights = getRights(userName, channel);

            string message;

            if (rights != "")
            {
                string[] messageParameters = { userName, rights };
                message = new Message().get("cmdRightsList", messageParameters);
            }
            else
            {
                string[] messageParameters = { userName };
                message = new Message().get("cmdRightsNone", messageParameters);
            }

            crh.respond(message);
            return(crh);
        }
示例#3
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            CommandResponseHandler crh = new CommandResponseHandler();

            Dictionary <string, Monitoring.CategoryWatcher> .KeyCollection kc = WatcherController.instance().getKeywords();
            if (GlobalFunctions.isInArray("@cats", args) != -1)
            {
                GlobalFunctions.removeItemFromArray("@cats", ref args);
                string listSep = new Message().get("listSeparator");
                string list    = new Message().get("allCategoryCodes");
                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, channel));
                }
            }
            return(crh);
        }
示例#4
0
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            CommandResponseHandler crh = new CommandResponseHandler();

            if (args.Length > 0)
            {
                string   userName         = string.Join(" ", args);
                DateTime registrationDate = getRegistrationDate(userName, channel);
                if (registrationDate == new DateTime(0))
                {
                    string[] messageParams = { userName };
                    string   message       = new Message().get("noSuchUser", messageParams);
                    crh.respond(message);
                }
                else
                {
                    string[] messageParameters =
                    {
                        userName, registrationDate.ToString("hh:mm:ss t"),
                        registrationDate.ToString("d MMMM yyyy")
                    };
                    string message = new Message().get("registrationDate", messageParameters);
                    crh.respond(message);
                }
            }
            else
            {
                string[] messageParameters = { "registration", "1", args.Length.ToString() };
                Helpmebot6.irc.ircNotice(source.nickname,
                                         new Message().get("notEnoughParameters", messageParameters));
            }
            return(crh);
        }
示例#5
0
 /// <summary>
 /// Actual command logic
 /// </summary>
 /// <param name="source">The user who triggered the command.</param>
 /// <param name="channel">The channel the command was triggered in.</param>
 /// <param name="args">The arguments to the command.</param>
 /// <returns></returns>
 protected override CommandResponseHandler execute(User source, string channel, string[] args)
 {
     CommandResponseHandler crh = new CommandResponseHandler();
     string[] cmdArgs = {source.ToString(), source.accessLevel.ToString()};
     crh.respond(new Message().get("cmdAccess", cmdArgs));
     return crh;
 }
示例#6
0
        protected override CommandResponseHandler reallyRun(User source, string channel, string[] args)
        {
            if (!AccessLog.instance().save(new AccessLog.AccessLogEntry(source, GetType(), true, channel, args)))
            {
                CommandResponseHandler errorResponse = new CommandResponseHandler();
                errorResponse.respond("Error adding to access log - command aborted.", CommandResponseDestination.ChannelDebug);
                errorResponse.respond(new Message().get("AccessDeniedAccessListFailure"), CommandResponseDestination.Default);
                return(errorResponse);
            }

            this.log("Starting command execution...");
            CommandResponseHandler crh;

            try
            {
                crh = GlobalFunctions.isInArray("@confirm", args) != -1 ? execute(source, channel, args) : notConfirmed(source, channel, args);
            }
            catch (Exception ex)
            {
                Logger.instance().addToLog(ex.ToString(), Logger.LogTypes.Error);
                crh = new CommandResponseHandler(ex.Message);
            }
            this.log("Command execution complete.");
            return(crh);
        }
示例#7
0
 /// <summary>
 /// Actual command logic
 /// </summary>
 /// <param name="source">The user who triggered the command.</param>
 /// <param name="channel">The channel the command was triggered in.</param>
 /// <param name="args">The arguments to the command.</param>
 /// <returns></returns>
 protected override CommandResponseHandler execute(User source, string channel, string[] args)
 {
     string[] statuses = ThreadList.instance().getAllThreadStatus();
     CommandResponseHandler crh = new CommandResponseHandler();
     foreach (string item in statuses)
     {
         crh.respond(item);
     }
     return crh;
 }
示例#8
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            string[] statuses          = ThreadList.instance().getAllThreadStatus();
            CommandResponseHandler crh = new CommandResponseHandler();

            foreach (string item in statuses)
            {
                crh.respond(item);
            }
            return(crh);
        }
示例#9
0
        /// <summary>
        /// Access denied to command, decide what to do
        /// </summary>
        /// <param name="source">The source of the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns>A response to the command if access to the command was denied</returns>
        protected virtual CommandResponseHandler accessDenied(User source, string channel, string[] args)
        {
            CommandResponseHandler response = new CommandResponseHandler();

            response.respond(new Message().get("accessDenied", ""),
                             CommandResponseDestination.PrivateMessage);
            this.log("Access denied to command.");
            if (!AccessLog.instance().save(new AccessLog.AccessLogEntry(source, GetType(), false, channel, args)))
            {
                response.respond("Error adding denied entry to access log.", CommandResponseDestination.ChannelDebug);
            }
            return(response);
        }
示例#10
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            var crh = new CommandResponseHandler();

            if (args.Length > 0 && args[0] != string.Empty)
            {
                foreach (string s in args)
                {
                    string[] cmdArgs = { s, User.newFromString(s).accessLevel.ToString() };
                    crh.respond(new Message().get("cmdAccess", cmdArgs));
                }
            }

            else
            {
                string[] cmdArgs = { source.ToString(), source.accessLevel.ToString() };
                crh.respond(new Message().get("cmdAccess", cmdArgs));
            }
            return(crh);
        }
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            CommandResponseHandler crh = new CommandResponseHandler();

            if (args.Length == 1)
            {
                // just do category check
                crh.respond(WatcherController.instance().forceUpdate(args[0], channel));
            }
            else
            {
                // do something else too.
                Type subCmdType =
                    Type.GetType("helpmebot6.Commands.CategoryWatcherCommand." + args[1].Substring(0, 1).ToUpper() +
                                 args[1].Substring(1).ToLower());
                if (subCmdType != null)
                {
                    return ((GenericCommand) Activator.CreateInstance(subCmdType)).run(source, channel, args);
                }
            }
            return crh;
        }
示例#12
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            CommandResponseHandler crh = new CommandResponseHandler();

            if (args.Length == 1)
            {
                // just do category check
                crh.respond(WatcherController.instance().forceUpdate(args[0], channel));
            }
            else
            {
                // do something else too.
                Type subCmdType =
                    Type.GetType("helpmebot6.Commands.CategoryWatcherCommand." + args[1].Substring(0, 1).ToUpper() +
                                 args[1].Substring(1).ToLower());
                if (subCmdType != null)
                {
                    return(((GenericCommand)Activator.CreateInstance(subCmdType)).run(source, channel, args));
                }
            }
            return(crh);
        }
示例#13
0
文件: Faq.cs 项目: awnowlin/helpmebot
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            string command = GlobalFunctions.popFromFront(ref args).ToLower();
            CommandResponseHandler crh = new CommandResponseHandler();

            NubioApi faqRepo = new NubioApi(new Uri(Configuration.singleton()["faqApiUri"]));
            string result;
            switch (command)
            {
                case "search":
                    result = faqRepo.searchFaq(string.Join(" ", args));
                    if (result != null)
                    {
                        crh.respond(result);
                    }
                    break;
                case "fetch":
                    result = faqRepo.fetchFaqText(int.Parse(args[0]));
                    if (result != null)
                    {
                        crh.respond(result);
                    }
                    break;
                case "link":
                    result = faqRepo.viewLink(int.Parse(args[0]));
                    if (result != null)
                    {
                        crh.respond(result);
                    }
                    break;
                default:
                    break;
            }

            return crh;
        }
示例#14
0
        /// <summary>
        /// Handles the command response handler.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="directedTo">
        /// The directed to.
        /// </param>
        /// <param name="response">
        /// The response.
        /// </param>
        private void HandleCommandResponseHandler(
            LegacyUser source, 
            string destination, 
            string directedTo, 
            CommandResponseHandler response)
        {
            if (response != null)
            {
                foreach (CommandResponse item in response.GetResponses())
                {
                    string message = item.Message;

                    if (directedTo != string.Empty)
                    {
                        message = directedTo + ": " + message;
                    }

                    var irc1 = this.commandServiceHelper.Client;
                    switch (item.Destination)
                    {
                        case CommandResponseDestination.Default:
                            if (this.OverrideBotSilence || LegacyConfig.Singleton()["silence", destination] != "true")
                            {
                                irc1.SendMessage(destination, message);
                            }

                            break;
                        case CommandResponseDestination.ChannelDebug:
                            irc1.SendMessage(this.commandServiceHelper.ConfigurationHelper.CoreConfiguration.DebugChannel, message);
                            break;
                        case CommandResponseDestination.PrivateMessage:
                            irc1.SendMessage(source.Nickname, message);
                            break;
                    }
                }
            }
        }
示例#15
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="command">The command.</param>
        /// <param name="args">The args.</param>
        public void handleCommand(User source, string destination, string command, string[] args)
        {
            Logger.instance().addToLog("Handling recieved message...", Logger.LogTypes.General);

            // if on ignore list, ignore!
            if (source.accessLevel == User.UserRights.Ignored)
                return;

            // flip destination over if required
            if (destination == Helpmebot6.irc.ircNickname)
                destination = source.nickname;

            /*
             * check category codes
             */
            if (WatcherController.instance().isValidKeyword(command))
            {
                int argsLength = GlobalFunctions.realArrayLength(args);

                string[] newArgs = new string[argsLength + 1];
                int newArrayPos = 1;
                for (int i = 0; i < args.Length; i++)
                {
                    if (!String.IsNullOrEmpty(args[i]))
                        newArgs[newArrayPos] = args[i];
                    newArrayPos++;
                }
                newArgs[0] = command;
                string directedTo = findRedirection(destination, ref newArgs);
                CommandResponseHandler crh = new CategoryWatcher().run(source, destination, newArgs);
                this.handleCommandResponseHandler(source, destination, directedTo, crh);
                return;
            }

            /*
             * Check for a valid command
             * search for a class that can handle this command.
             */

            // Create a new object which holds the type of the command handler, if it exists.
            // if the command handler doesn't exist, then this won't be set to a value
            Type commandHandler =
                Type.GetType("helpmebot6.Commands." + command.Substring(0, 1).ToUpper() + command.Substring(1).ToLower());
            // check the type exists
            if (commandHandler != null)
            {
                string directedTo = findRedirection(destination, ref args);

                // create a new instance of the commandhandler.
                // cast to genericcommand (which holds all the required methods to run the command)
                // run the command.
                CommandResponseHandler response = ((GenericCommand) Activator.CreateInstance(commandHandler)).run(
                    source, destination, args);
                this.handleCommandResponseHandler(source, destination, directedTo, response);
                return;
            }

            /*
             * Check for a learned word
             */
            {
                WordLearner.RemeberedWord rW = WordLearner.remember(command);
                CommandResponseHandler crh = new CommandResponseHandler();
                string wordResponse = rW.phrase;
                string directedTo = "";
                if (wordResponse != String.Empty)
                {
                    if (source.accessLevel < User.UserRights.Normal)
                    {
                        crh.respond(new Message().get("accessDenied"),
                                    CommandResponseDestination.PrivateMessage);
                        string[] aDArgs = {source.ToString(), MethodBase.GetCurrentMethod().Name};
                        crh.respond(new Message().get("accessDeniedDebug", aDArgs),
                                    CommandResponseDestination.ChannelDebug);
                    }
                    else
                    {
                        wordResponse = String.Format(wordResponse, args);
                        if (rW.action)
                        {
                            crh.respond(IAL.wrapCTCP("ACTION", wordResponse));
                        }
                        else
                        {
                            directedTo = findRedirection(destination, ref args);
                            crh.respond(wordResponse);
                        }
                        this.handleCommandResponseHandler(source, destination, directedTo, crh);
                    }
                    return;
                }
            }
        }
示例#16
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            var ignore = false;

            switch (args[0].ToLower())
            {
            case "enable":
                if (Configuration.singleton()["welcomeNewbie", channel] == "true")
                {
                    return(new CommandResponseHandler(new Message().get("no-change")));
                }
                Configuration.singleton()["welcomeNewbie", channel] = "true";
                return(new CommandResponseHandler(new Message().get("done")));

            case "disable":
                if (Configuration.singleton()["welcomeNewbie", channel] == "false")
                {
                    return(new CommandResponseHandler(new Message().get("no-change")));
                }
                Configuration.singleton()["welcomeNewbie", channel] = "false";
                return(new CommandResponseHandler(new Message().get("done")));

            case "global":
                Configuration.singleton( )["welcomeNewbie", channel] = null;
                return(new CommandResponseHandler(new Message().get("defaultSetting")));

            case "add":
                if (args[1] == "@ignore")
                {
                    ignore = true;
                    GlobalFunctions.popFromFront(ref args);
                }

                NewbieWelcomer.instance().addHost(args[1], ignore);
                return(new CommandResponseHandler(new Message().get("done")));

            case "del":
                if (args[1] == "@ignore")
                {
                    ignore = true;
                    GlobalFunctions.popFromFront(ref args);
                }

                NewbieWelcomer.instance().delHost(args[1], ignore);
                return(new CommandResponseHandler(new Message().get("done")));

            case "list":
                if (args[1] == "@ignore")
                {
                    ignore = true;
                    GlobalFunctions.popFromFront(ref args);
                }

                var      crh  = new CommandResponseHandler();
                string[] list = NewbieWelcomer.instance().getHosts(ignore);
                foreach (string item in list)
                {
                    crh.respond(item);
                }
                return(crh);
            }
            return(new CommandResponseHandler());
        }
示例#17
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="command">
        /// The command.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        public void HandleCommand(LegacyUser source, string destination, string command, string[] args)
        {
            this.Log.Debug("Handling recieved message...");

            // user is null (!)
            if (source == null)
            {
                this.Log.Debug("Ignoring message from null user.");
                return;
            }

            // if on ignore list, ignore!
            if (source.AccessLevel == LegacyUser.UserRights.Ignored)
            {
                this.Log.Debug("Ignoring message from ignored user.");
                return;
            }

            // flip destination over if required
            if (destination == this.commandServiceHelper.Client.Nickname)
            {
                destination = source.Nickname;
            }

            /*
             * check category codes
             */
            if (WatcherController.Instance().IsValidKeyword(command))
            {
                int argsLength = args.SmartLength();

                var newArgs = new string[argsLength + 1];
                int newArrayPos = 1;
                foreach (string t in args)
                {
                    if (!string.IsNullOrEmpty(t))
                    {
                        newArgs[newArrayPos] = t;
                    }

                    newArrayPos++;
                }

                newArgs[0] = command;
                string directedTo = FindRedirection(ref newArgs);
                CommandResponseHandler crh =
                    new CategoryWatcher(source, destination, newArgs, this.commandServiceHelper).RunCommand();
                this.HandleCommandResponseHandler(source, destination, directedTo, crh);
                return;
            }

            /* 
             * Check for a valid command
             * search for a class that can handle this command.
             */

            // Create a new object which holds the type of the command handler, if it exists.
            // if the command handler doesn't exist, then this won't be set to a value
            Type commandHandler =
                Type.GetType(
                    "helpmebot6.Commands." + command.Substring(0, 1).ToUpper() + command.Substring(1).ToLower());

            // check the type exists
            if (commandHandler != null)
            {
                string directedTo = FindRedirection(ref args);

                // create a new instance of the commandhandler.
                // cast to genericcommand (which holds all the required methods to run the command)
                // run the command.
                CommandResponseHandler response =
                    ((GenericCommand)
                     Activator.CreateInstance(commandHandler, source, destination, args, this.commandServiceHelper))
                        .RunCommand();
                this.HandleCommandResponseHandler(source, destination, directedTo, response);
                return;
            }

            /*
             * Check for a learned word
             */
            {
                // FIXME: ServiceLocator - keywordservice
                var keywordService = ServiceLocator.Current.GetInstance<IKeywordService>();

                Keyword keyword = keywordService.Get(command);

                var crh = new CommandResponseHandler();
                string directedTo = string.Empty;
                if (keyword != null)
                {
                    if (source.AccessLevel < LegacyUser.UserRights.Normal)
                    {
                        this.Log.InfoFormat("Access denied for keyword retrieval for {0}", source);

                        var messageService1 = this.commandServiceHelper.MessageService;
                        crh.Respond(
                            messageService1.RetrieveMessage(Messages.OnAccessDenied, destination, null), 
                            CommandResponseDestination.PrivateMessage);

                        string[] accessDeniedArguments = { source.ToString(), MethodBase.GetCurrentMethod().Name };
                        crh.Respond(
                            messageService1.RetrieveMessage("accessDeniedDebug", destination, accessDeniedArguments), 
                            CommandResponseDestination.ChannelDebug);
                    }
                    else
                    {
                        string wordResponse = keyword.Response;

                        IDictionary<string, object> dict = new Dictionary<string, object>();

                        dict.Add("username", source.Username);
                        dict.Add("nickname", source.Nickname);
                        dict.Add("hostname", source.Hostname);
                        dict.Add("AccessLevel", source.AccessLevel);
                        dict.Add("channel", destination);

                        for (int i = 0; i < args.Length; i++)
                        {
                            dict.Add(i.ToString(CultureInfo.InvariantCulture), args[i]);
                            dict.Add(i + "*", string.Join(" ", args, i, args.Length - i));
                        }

                        wordResponse = wordResponse.FormatWith(dict);

                        if (keyword.Action)
                        {
                            crh.Respond(wordResponse.SetupForCtcp("ACTION"));
                        }
                        else
                        {
                            directedTo = FindRedirection(ref args);
                            crh.Respond(wordResponse);
                        }

                        this.HandleCommandResponseHandler(source, destination, directedTo, crh);
                    }
                }
            }
        }
示例#18
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            var crh = new CommandResponseHandler();

            if (args.Length > 1)
            {
                switch (args[0].ToLower())
                {
                case "add":
                    if (args.Length > 2)
                    {
                        var aL = User.UserRights.Normal;

                        switch (args[2].ToLower())
                        {
                        case "developer":
                            aL = source.accessLevel == User.UserRights.Developer
                                             ? User.UserRights.Developer
                                             : User.UserRights.Superuser;
                            break;

                        case "superuser":
                            aL = User.UserRights.Superuser;
                            break;

                        case "advanced":
                            aL = User.UserRights.Advanced;
                            break;

                        case "semi-ignored":
                            aL = User.UserRights.Semiignored;
                            break;

                        case "semiignored":
                            aL = User.UserRights.Semiignored;
                            break;

                        case "ignored":
                            aL = User.UserRights.Ignored;
                            break;

                        case "normal":
                            aL = User.UserRights.Normal;
                            break;

                        default:
                            break;
                        }

                        crh = addAccessEntry(User.newFromString(args[1]), aL);
                    }
                    else
                    {
                        string[] messageParameters = { "access add", "3", args.Length.ToString() };
                        return(new CommandResponseHandler(new Message().get("notEnoughParameters", messageParameters)));
                    }
                    break;

                case "del":
                    crh = delAccessEntry(int.Parse(args[1]));
                    break;
                }
                // add <source> <level>

                // del <id>
            }
            else
            {
                string[] messageParameters = { "access", "2", args.Length.ToString() };
                return(new CommandResponseHandler(new Message().get("notEnoughParameters", messageParameters)));
            }
            return(crh);
        }
示例#19
0
        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            // TODO: link to basewiki
            Stream rawDataStream =
                HttpRequest.get(
                    "http://en.wikipedia.org/w/api.php?action=query&prop=revisions|info&rvprop=user|comment&redirects&inprop=protection&format=xml&titles=" +
                    string.Join(" ", args));

            XmlTextReader xtr = new XmlTextReader(rawDataStream);

            CommandResponseHandler crh = new CommandResponseHandler();

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


            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)
                        {
                            return(new CommandResponseHandler(new Message().get("pageMissing")));
                        }
                        // title, touched
                        // <page pageid="78056" ns="0" title="Sausage" touched="2010-05-23T17:46:16Z" lastrevid="363765722" counter="252" length="43232">
                        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;

                    default:
                        break;
                    }
                }
            }


            if (redirects != null)
            {
                string[] redirArgs = { redirects, title };
                crh.respond(new Message().get("pageRedirect", redirArgs));
            }

            string[] margs = { title, user, touched.ToString(), comment, size };
            crh.respond(new Message().get("pageMainResponse", margs));

            foreach (PageProtection p in protection)
            {
                string[] pargs =
                {
                    title, p.type, p.level,
                    p.expiry == DateTime.MaxValue ? "infinity" : p.expiry.ToString()
                };
                crh.respond(new Message().get("pageProtected", pargs));
            }

            return(crh);
        }
示例#20
0
        /// <summary>
        /// Handles the command response handler.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="directedTo">The directed to.</param>
        /// <param name="response">The response.</param>
        private void handleCommandResponseHandler(User source, string destination, string directedTo,
                                                  CommandResponseHandler response)
        {
            if (response != null)
            {
                foreach (CommandResponse item in response.getResponses())
                {
                    string message = item.message;

                    if (directedTo != String.Empty)
                    {
                        message = directedTo + ": " + message;
                    }

                    switch (item.destination)
                    {
                        case CommandResponseDestination.Default:
                            if (overrideBotSilence ||
                                Configuration.singleton()["silence",destination] != "true")
                            {
                                Helpmebot6.irc.ircPrivmsg(destination, message);
                            }
                            break;
                        case CommandResponseDestination.ChannelDebug:
                            Helpmebot6.irc.ircPrivmsg(Helpmebot6.debugChannel, message);
                            break;
                        case CommandResponseDestination.PrivateMessage:
                            Helpmebot6.irc.ircPrivmsg(source.nickname, message);
                            break;
                    }
                }
            }
        }
示例#21
0
 /// <summary>
 /// Access granted to command, decide what to do
 /// </summary>
 /// <param name="source">The source of the command.</param>
 /// <param name="channel">The channel the command was triggered in.</param>
 /// <param name="args">Arguments to the command</param>
 /// <returns>The response to the comand</returns>
 protected virtual CommandResponseHandler reallyRun(User source, string channel, string[] args)
 {
     if(!AccessLog.instance().save(new AccessLog.AccessLogEntry(source, GetType(), true,channel, args)))
     {
         CommandResponseHandler errorResponse = new CommandResponseHandler();
         errorResponse.respond("Error adding to access log - command aborted.", CommandResponseDestination.ChannelDebug);
         errorResponse.respond(new Message().get("AccessDeniedAccessListFailure"), CommandResponseDestination.Default);
         return errorResponse;
     }
     this.log("Starting command execution...");
     CommandResponseHandler crh;
     try
     {
         crh = execute(source, channel, args);
     }
     catch (Exception ex)
     {
         Logger.instance().addToLog(ex.ToString(), Logger.LogTypes.Error);
         crh = new CommandResponseHandler(ex.Message);
     }
     this.log("Command execution complete.");
     return crh;
 }
示例#22
0
        /// <summary>
        /// Access denied to command, decide what to do
        /// </summary>
        /// <param name="source">The source of the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns>A response to the command if access to the command was denied</returns>
        protected virtual CommandResponseHandler accessDenied(User source, string channel, string[] args)
        {
            CommandResponseHandler response = new CommandResponseHandler();

            response.respond(new Message().get("accessDenied", ""),
                             CommandResponseDestination.PrivateMessage);
            this.log("Access denied to command.");
            if (!AccessLog.instance().save(new AccessLog.AccessLogEntry(source, GetType(), false, channel, args)))
            {
                response.respond("Error adding denied entry to access log.", CommandResponseDestination.ChannelDebug);
            }
            return response;
        }