Exemple #1
0
        public bool RegisterAlias(string alias, string command)
        {
            if (this.Exists(alias) || !this.Exists(command))
            {
                return(false);
            }
            if (alias == null || alias == string.Empty)
            {
                return(false);
            }

            alias   = alias.ToLower();
            command = command.ToLower();

            lock (this.CommandsList)
                if (this.CommandsList[command].IsAlias)
                {
                    return(false);
                }

            CommandRights rights = new CommandRights();

            rights.IsAlias     = true;
            rights.MainCommand = command;
            rights.Plugin      = string.Empty;
            lock (this.CommandsList)
                this.CommandsList.Add(alias, rights);
            return(true);
        }
Exemple #2
0
        public bool SetRights(string command, CommandRights rights)
        {
            if (!this.Exists(command))
            {
                return(false);
            }
            if (rights == null)
            {
                return(false);
            }
            command = this.GetMainCommand(command);
            string plugin;

            lock (this.CommandsList)
                plugin = this.CommandsList[command].Plugin.ToLower();
            CommandRights defaultRights = this.GetRights(command);

            if (defaultRights == null)
            {
                return(false);
            }
            this.ResetRights(command);
            if (defaultRights != rights)
            {
                this.Config.ExecuteNonQuery("INSERT INTO CORE_Rights VALUES('" + plugin + "', '" + command + "', '" + rights.Organization.ToString() + "', '" + rights.PrivateChannel.ToString() + "', '" + rights.PrivateMessage.ToString() + "')");
            }
            return(true);
        }
Exemple #3
0
        public bool SetRight(string command, CommandType type, UserLevel right)
        {
            if (!this.Exists(command))
            {
                return(false);
            }
            CommandRights rights = this.GetRights(command);

            if (rights == null)
            {
                return(false);
            }
            switch (type)
            {
            case CommandType.Organization:
                rights.Organization = right;
                break;

            case CommandType.PrivateChannel:
                rights.PrivateChannel = right;
                break;

            case CommandType.Tell:
                rights.PrivateMessage = right;
                break;
            }
            return(this.SetRights(command, rights));
        }
Exemple #4
0
        public CommandRights GetRights(string command)
        {
            if (!this.Exists(command))
            {
                return(null);
            }

            CommandRights rights = this.GetDefaultRights(command);

            try
            {
                lock (this.CommandsList)
                {
                    command = this.GetMainCommand(command);
                    string internalName = this.CommandsList[command].Plugin.ToLower();
                    using (IDbCommand cmd = this.Config.Connection.CreateCommand())
                    {
                        cmd.CommandText = "SELECT GC_Right, PG_Right, TELL_Right FROM CORE_Rights WHERE InternalName = '" + internalName + "' AND Command = '" + command + "'";
                        IDataReader reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            rights.Organization   = (UserLevel)Enum.Parse(typeof(UserLevel), reader.GetString(0));
                            rights.PrivateChannel = (UserLevel)Enum.Parse(typeof(UserLevel), reader.GetString(1));
                            rights.PrivateMessage = (UserLevel)Enum.Parse(typeof(UserLevel), reader.GetString(2));
                        }
                        reader.Close();
                    }
                }
            }
            catch { }
            return(rights);
        }
Exemple #5
0
        public bool Register(string plugin, Command command)
        {
            if (this.Exists(command.CommandName))
            {
                return(false);
            }
            if (plugin == null || plugin == string.Empty)
            {
                return(false);
            }
            if (command.IsAlias)
            {
                return(false);
            }

            CommandRights tmp = new CommandRights();

            tmp.Plugin         = plugin.ToLower();
            tmp.Organization   = command.Organization;
            tmp.PrivateChannel = command.PrivateChannel;
            tmp.PrivateMessage = command.PrivateMessage;
            tmp.Help           = command.Help;

            lock (this.CommandsList)
                this.CommandsList.Add(command.CommandName, tmp);
            return(true);
        }
Exemple #6
0
        private void OnHelpCommand(BotShell bot, CommandArgs e)
        {
            RichTextWindow window = new RichTextWindow(bot);

            window.AppendTitle("VhaBot Help");
            bool found = false;

            foreach (string plugin in bot.Plugins.GetPlugins())
            {
                if (bot.Plugins.IsLoaded(plugin))
                {
                    string[]      commands     = bot.Commands.GetCommands(plugin);
                    List <string> helpCommands = new List <string>();
                    foreach (string command in commands)
                    {
                        CommandRights rights = bot.Commands.GetRights(command);
                        if (rights.Help && !rights.IsAlias)
                        {
                            helpCommands.Add(command);
                        }
                    }
                    helpCommands.Sort();
                    if (helpCommands.Count > 0)
                    {
                        PluginLoader loader = bot.Plugins.GetLoader(plugin);
                        window.AppendHighlight(loader.Name);
                        window.AppendLineBreak();
                        window.AppendNormalStart();
                        int i = 0;
                        foreach (string command in helpCommands)
                        {
                            window.AppendBotCommand(Format.UppercaseFirst(command), "help " + command);
                            i++;
                            if (i < helpCommands.Count)
                            {
                                window.AppendString(", ");
                            }
                        }
                        window.AppendColorEnd();
                        window.AppendLineBreak(2);
                        found = true;
                    }
                }
            }
            if (found)
            {
                bot.SendReply(e, "VhaBot Help »» ", window);
            }
            else
            {
                bot.SendReply(e, "No help available");
            }
        }
Exemple #7
0
 public CommandRights GetDefaultRights(string command)
 {
     if (!this.Exists(command))
     {
         return(null);
     }
     command = this.GetMainCommand(command);
     lock (this.CommandsList)
     {
         CommandRights rights = new CommandRights();
         rights.Plugin         = this.CommandsList[command].Plugin;
         rights.Organization   = this.CommandsList[command].Organization;
         rights.PrivateChannel = this.CommandsList[command].PrivateChannel;
         rights.PrivateMessage = this.CommandsList[command].PrivateMessage;
         rights.Help           = this.CommandsList[command].Help;
         return(rights);
     }
 }
Exemple #8
0
        private void CreateSelectLine(BotShell bot, ref RichTextWindow window, string command)
        {
            CommandRights rights = bot.Commands.GetRights(command);

            command = command.Replace(" ", "_");
            this.CreateSelectPanel(ref window, rights.PrivateMessage, "commands set " + command + " tell");
            window.AppendString(" ");
            this.CreateSelectPanel(ref window, rights.PrivateChannel, "commands set " + command + " pg");
            window.AppendString(" ");
            this.CreateSelectPanel(ref window, rights.Organization, "commands set " + command + " org");
            window.AppendHighlight(" " + Format.UppercaseFirst(command.Replace("_", " ")));

            window.AppendNormalStart();
            window.AppendString(" [");
            window.AppendBotCommand("Reset", "commands reset " + command);
            window.AppendString("]");
            window.AppendColorEnd();
        }
Exemple #9
0
        public UserLevel GetRight(string command, CommandType type)
        {
            CommandRights rights = this.GetRights(command);

            if (rights == null)
            {
                return(UserLevel.Disabled);
            }
            switch (type)
            {
            case CommandType.Organization:
                return(rights.Organization);

            case CommandType.PrivateChannel:
                return(rights.PrivateChannel);

            case CommandType.Tell:
                return(rights.PrivateMessage);

            default:
                return(UserLevel.Disabled);
            }
        }
Exemple #10
0
        private void OnCommandsResetCommand(BotShell bot, CommandArgs e)
        {
            if (e.Args.Length < 1)
            {
                bot.SendReply(e, "Usage: commands reset [command]");
                return;
            }
            string command = e.Args[0].ToLower().Replace("_", " ");

            if (!bot.Commands.Exists(command))
            {
                bot.SendReply(e, "No such command!");
                return;
            }
            if (bot.Plugins.GetState(bot.Commands.GetInternalName(command)) == PluginState.Core)
            {
                bot.SendReply(e, "You can't reset the command rights on Core plugins!");
                return;
            }
            bot.Commands.ResetRights(command);
            CommandRights rights = bot.Commands.GetRights(command);

            bot.SendReply(e, "The required userlevel for the command " + HTML.CreateColorString(bot.ColorHeaderHex, command) + " has been reset. Tell: " + HTML.CreateColorString(bot.ColorHeaderHex, rights.PrivateMessage.ToString()) + ", Private Channel: " + HTML.CreateColorString(bot.ColorHeaderHex, rights.PrivateChannel.ToString()) + ", Organization: " + HTML.CreateColorString(bot.ColorHeaderHex, rights.Organization.ToString()));
        }
Exemple #11
0
        private void OnHelpDisplayCommand(BotShell bot, CommandArgs e)
        {
            string command = e.Words[0];

            command = bot.Commands.GetMainCommand(command);
            if (!bot.Commands.Exists(command) || !bot.Commands.GetRights(command).Help)
            {
                bot.SendReply(e, "No such help topic");
                return;
            }

            PluginLoader  loader = bot.Plugins.GetLoader(bot.Commands.GetInternalName(command));
            CommandRights rights = bot.Commands.GetRights(command);
            UserLevel     level  = bot.Users.GetUser(e.Sender);

            RichTextWindow window = new RichTextWindow(bot);

            window.AppendTitle("Information");
            window.AppendHighlight("Command: ");
            window.AppendNormal(Format.UppercaseFirst(command));
            window.AppendLineBreak();
            window.AppendHighlight("Plugin: ");
            window.AppendNormal(loader.ToString());
            window.AppendLineBreak();
            window.AppendHighlight("Private Message Access: ");
            if (level >= rights.PrivateMessage)
            {
                window.AppendColorString(RichTextWindow.ColorGreen, rights.PrivateMessage.ToString());
            }
            else
            {
                window.AppendColorString(RichTextWindow.ColorRed, rights.PrivateMessage.ToString());
            }
            window.AppendLineBreak();
            window.AppendHighlight("Private Channel Access: ");
            if (level >= rights.PrivateChannel)
            {
                window.AppendColorString(RichTextWindow.ColorGreen, rights.PrivateChannel.ToString());
            }
            else
            {
                window.AppendColorString(RichTextWindow.ColorRed, rights.PrivateChannel.ToString());
            }
            window.AppendLineBreak();
            window.AppendHighlight("Organization Access: ");
            if (level >= rights.Organization)
            {
                window.AppendColorString(RichTextWindow.ColorGreen, rights.Organization.ToString());
            }
            else
            {
                window.AppendColorString(RichTextWindow.ColorRed, rights.Organization.ToString());
            }
            window.AppendLineBreak(2);

            window.AppendHeader("Help");
            window.AppendHighlightStart();
            string help = bot.Commands.GetHelp(command);

            if (help == null || help.Trim() == string.Empty)
            {
                window.AppendString("No additional help available for this command");
            }
            else
            {
                window.AppendRawString(help);
            }
            window.AppendColorEnd();

            bot.SendReply(e, "VhaBot Help »» " + Format.UppercaseFirst(command) + " »» ", window);
        }
 public CommandAttribute(CommandRights requiredRights, string commandNameSpace)
     : this(requiredRights, commandNameSpace, null)
 {
 }
 public CommandAttribute(CommandRights requiredRights, string commandNameSpace, string help)
 {
     CommandNameSpace = commandNameSpace;
     CommandHelp      = help;
     RequiredRights   = requiredRights;
 }
 public CommandAttribute(CommandRights requiredRights, string commandNameSpace, string help)
 {
     CommandNameSpace = commandNameSpace;
     CommandHelp = help;
     RequiredRights = requiredRights;
 }
 public CommandAttribute(CommandRights requiredRights, string commandNameSpace)
     : this(requiredRights, commandNameSpace, null)
 {
 }
Exemple #16
0
        private void OnCommandsMapCommand(BotShell bot, CommandArgs e)
        {
            RichTextWindow window = new RichTextWindow(bot);

            window.AppendTitle("Commands Map");
            window.AppendNormal("This is a map of all commands currently available on this bot.");
            window.AppendLineBreak();
            window.AppendNormal("The commands are listed in the following format: [command] ([tell] [pg] [org] / [default tell] [default pg] [default org])");
            window.AppendLineBreak();
            window.AppendNormal("The letters represent the required userlevel you need for the command.");
            window.AppendLineBreak();
            window.AppendNormal("The color of the command represents whether the command has help or not. Red means there is no help available. Orange means there should be help available but this command was unable to retrieve it. Green means there is help available.");
            window.AppendLineBreak(2);

            foreach (string plugin in bot.Plugins.GetLoadedPlugins())
            {
                string[]     commands = bot.Commands.GetCommands(plugin);
                PluginLoader loader   = bot.Plugins.GetLoader(plugin);
                window.AppendHeader(loader.ToString());
                if (commands.Length > 0)
                {
                    foreach (string command in commands)
                    {
                        CommandRights rights = bot.Commands.GetRights(command);
                        if (rights.Help)
                        {
                            if (bot.Commands.GetHelp(command) != string.Empty)
                            {
                                window.AppendColorStart(RichTextWindow.ColorGreen);
                            }
                            else
                            {
                                window.AppendColorStart(RichTextWindow.ColorOrange);
                            }
                        }
                        else
                        {
                            window.AppendColorStart(RichTextWindow.ColorRed);
                        }
                        window.AppendString(Format.UppercaseFirst(command));
                        window.AppendColorEnd();

                        string tell = rights.PrivateMessage.ToString().Substring(0, 1).ToUpper();
                        string pg   = rights.PrivateChannel.ToString().Substring(0, 1).ToUpper();
                        string org  = rights.Organization.ToString().Substring(0, 1).ToUpper();
                        rights = bot.Commands.GetDefaultRights(command);
                        string d_tell = rights.PrivateMessage.ToString().Substring(0, 1).ToUpper();
                        string d_pg   = rights.PrivateChannel.ToString().Substring(0, 1).ToUpper();
                        string d_org  = rights.Organization.ToString().Substring(0, 1).ToUpper();

                        window.AppendNormal(" (" + tell + pg + org + "/" + d_tell + d_pg + d_org + ")");
                        window.AppendLineBreak();
                    }
                }
                else
                {
                    window.AppendNormal("No commands available");
                    window.AppendLineBreak();
                }
                window.AppendLineBreak();
            }
            bot.SendReply(e, "Commands Map »» ", window);
        }