コード例 #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)
        {
            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);
        }
コード例 #2
0
ファイル: Enable.cs プロジェクト: Manishearth/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)
 {
     if (WatcherController.instance().addWatcherToChannel(args[0], channel))
     {
         return(new CommandResponseHandler(new Message().get("done")));
     }
     return(new CommandResponseHandler(new Message().get("no-change")));
 }
コード例 #3
0
ファイル: Status.cs プロジェクト: Manishearth/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[] messageParams =
            {
                args[0],
                WatcherController.instance().isWatcherInChannel(channel, args[0])
                                             ? new Message().get("enabled")
                                             : new Message().get("disabled"),
                WatcherController.instance().getDelay(args[0]).ToString()
            };

            return(new CommandResponseHandler(new Message().get("keywordStatus", messageParams)));
        }
コード例 #4
0
ファイル: Delay.cs プロジェクト: Manishearth/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)
 {
     if (args.Length > 2)
     {
         // 2 or more args
         return(WatcherController.instance().setDelay(args[0], int.Parse(args[2])));
     }
     if (args.Length == 2)
     {
         int      delay         = WatcherController.instance().getDelay(args[0]);
         string[] messageParams = { args[0], delay.ToString() };
         string   message       = new Message().get("catWatcherCurrentDelay", messageParams);
         return(new CommandResponseHandler(message));
     }
     // TODO: fix
     return(null);
 }
コード例 #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();

            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);
        }
コード例 #6
0
ファイル: Disable.cs プロジェクト: Manishearth/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)
 {
     WatcherController.instance().removeWatcherFromChannel(args[0], channel);
     return(new CommandResponseHandler(new Message().get("done")));
 }
コード例 #7
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;
                }
            }
        }