示例#1
0
        public static bool ParseAdminCommand(string Admin, string Command, IRCBotClient Bot)
        {
            string[] splitCommand = Command.Split(' ');

            IRCAdminBotCommand botCommand = null;

            switch (splitCommand[0])
            {
            case IRCAdminBotCommandHelp.COMMAND:
                botCommand = new IRCAdminBotCommandHelp();
                break;

            case IRCAdminBotCommandCheckReg.COMMAND:
                botCommand = new IRCAdminBotCommandCheckReg();
                break;

            case IRCAdminBotCommandRegister.COMMAND:
                botCommand = new IRCAdminBotCommandRegister();
                break;

            case IRCAdminBotCommandList.COMMAND:
                botCommand = new IRCAdminBotCommandList();
                break;

            case IRCAdminBotCommandAdd.COMMAND:
                botCommand = new IRCAdminBotCommandAdd();
                break;

            case IRCAdminBotCommandRemove.COMMAND:
                botCommand = new IRCAdminBotCommandRemove();
                break;

            case IRCAdminBotCommandEcho.COMMAND:
                botCommand = new IRCAdminBotCommandEcho();
                break;
            }

            if (botCommand == null)
            {
                return(false);
            }

            return(botCommand.PerformCommand(Admin, Command.Substring(splitCommand[0].Length).TrimStart(' '), Bot));
        }
示例#2
0
        /// <summary>
        /// Invoked when a private message was received.
        /// Private messages = admin console
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnLocalUserMessageReceived(object sender, IrcMessageEventArgs e)
        {
            // try get channeluser by name
            IrcChannelUser usr = GetChannelUser(e.Source.Name);

            if (usr == null)
            {
                return;
            }

            // only allow ADMINS from config
            if (!Config.Admins.Contains(e.Source.Name))
            {
                // respond user he can't use this feature
                IrcClient.LocalUser.SendMessage(
                    e.Source.Name,
                    e.Source.Name + " you can't use the admin console - Only admins allowed.");
                return;
            }

            // Must be registered.
            if (!IsUserRegistered(e.Source.Name))
            {
                // respond user he can't use this feature
                IrcClient.LocalUser.SendMessage(
                    e.Source.Name,
                    e.Source.Name + " you can't use the admin console - nickname must be registered.");
                return;
            }

            // invalid
            if (e.Text == null || e.Text == String.Empty)
            {
                return;
            }

            Log("ADM", e.Source.Name + " used the command " + e.Text);

            // Bot admin command?
            if (e.Text.StartsWith("@"))
            {
                // Returns false if nothing handled the admin command.
                if (!IRCAdminBotCommand.ParseAdminCommand(e.Source.Name, e.Text, this))
                {
                    IrcClient.LocalUser.SendMessage(e.Source.Name,
                                                    "Couldn't find a handler for admin command " + e.Text);
                }

                return;
            }

            // get first space in text
            int firstspace = e.Text.IndexOf(' ');

            // either use first part up to first space or full text if no space
            string comtype =
                (firstspace > 0) ? e.Text.Substring(0, firstspace) : comtype = e.Text;

            // check if commandtype is allowed
            if (Config.AdminCommands.Contains(comtype))
            {
                // Record this admin as recent.
                if (!RecentAdmins.Contains(e.Source.Name))
                {
                    RecentAdmins.Add(e.Source.Name);
                }
                // enqueue it for execution
                AdminCommandQueue.Enqueue(e.Text);
            }
            else
            {
                // respond admin he can't use this admincommand
                IrcClient.LocalUser.SendMessage(
                    e.Source.Name,
                    e.Source.Name + " you can't use the admin command '" + comtype + "'");
            }
        }