Пример #1
0
        private void OnConfigurationDisplayCommand(BotShell bot, CommandArgs e)
        {
            string internalName = e.Args[0].ToLower();

            if (!bot.Plugins.Exists(internalName))
            {
                bot.SendReply(e, "No such plugin!");
                return;
            }
            ConfigurationEntry[] entires = bot.Configuration.List(internalName);
            if (entires.Length < 1)
            {
                bot.SendReply(e, "This plugin has no settings to configure");
                return;
            }
            RichTextWindow window = new RichTextWindow(bot);
            PluginLoader   loader = bot.Plugins.GetLoader(internalName);

            window.AppendTitle("Configuration");
            foreach (ConfigurationEntry entry in entires)
            {
                window.AppendHighlight(entry.Name + ": ");
                window.AppendNormalStart();
                string command = "configuration set " + internalName + " " + entry.Key.ToLower();
                switch (entry.Type)
                {
                case ConfigType.String:
                    string value1 = bot.Configuration.GetString(entry.Section, entry.Key, (string)entry.DefaultValue);
                    if (entry.Values != null && entry.Values.Length > 0)
                    {
                        window.AppendMultiBox(command, value1, entry.StringValues);
                    }
                    else
                    {
                        window.AppendString(value1 + " [");
                        window.AppendCommand("Edit", "/text /tell " + bot.Character + " " + command + " [text]");
                        window.AppendString("]");
                    }
                    break;

                case ConfigType.Integer:
                    string value2 = bot.Configuration.GetInteger(entry.Section, entry.Key, (int)entry.DefaultValue).ToString();
                    if (entry.Values != null && entry.Values.Length > 0)
                    {
                        window.AppendMultiBox(command, value2, entry.StringValues);
                    }
                    else
                    {
                        window.AppendString(value2 + " [");
                        window.AppendCommand("Edit", "/text /tell " + bot.Character + " " + command + " [number]");
                        window.AppendString("]");
                    }
                    break;

                case ConfigType.Boolean:
                    string value3 = "Off";
                    if (bot.Configuration.GetBoolean(entry.Section, entry.Key, (bool)entry.DefaultValue))
                    {
                        value3 = "On";
                    }
                    window.AppendMultiBox(command, value3, "On", "Off");
                    break;

                case ConfigType.Username:
                    string value4 = bot.Configuration.GetUsername(entry.Section, entry.Key, (string)entry.DefaultValue);
                    window.AppendString(value4 + " [");
                    window.AppendCommand("Edit", "/text /tell " + bot.Character + " " + command + " [username]");
                    window.AppendString("]");
                    break;

                case ConfigType.Date:
                    DateTime value5 = bot.Configuration.GetDate(entry.Section, entry.Key, (DateTime)entry.DefaultValue);
                    window.AppendString(value5.ToString("dd/MM/yyyy") + " [");
                    window.AppendCommand("Edit", "/text /tell " + bot.Character + " " + command + " [dd]/[mm]/[yyyy]");
                    window.AppendString("]");
                    break;

                case ConfigType.Time:
                    TimeSpan value6 = bot.Configuration.GetTime(entry.Section, entry.Key, (TimeSpan)entry.DefaultValue);
                    window.AppendString(string.Format("{0:00}:{1:00}:{2:00}", Math.Floor(value6.TotalHours), value6.Minutes, value6.Seconds) + " [");
                    window.AppendCommand("Edit", "/text /tell " + bot.Character + " " + command + " [hh]:[mm]:[ss]");
                    window.AppendString("]");
                    break;

                case ConfigType.Dimension:
                    string value7 = bot.Configuration.GetDimension(entry.Section, entry.Key, (Server)entry.DefaultValue).ToString();
                    window.AppendMultiBox(command, value7, Server.RubiKa.ToString(), Server.Test.ToString());
                    break;

                case ConfigType.Color:
                    string value8 = bot.Configuration.GetColor(entry.Section, entry.Key, (string)entry.DefaultValue);
                    window.AppendColorString(value8, value8);
                    window.AppendString(" [");
                    window.AppendBotCommand("Edit", "configuration color " + internalName + " " + entry.Key.ToLower());
                    window.AppendString("]");
                    break;

                case ConfigType.Password:
                    string value9 = bot.Configuration.GetPassword(entry.Section, entry.Key, (string)entry.DefaultValue);
                    for (int i = 0; i < value9.Length; i++)
                    {
                        window.AppendString("*");
                    }
                    window.AppendString(" [");
                    window.AppendCommand("Edit", "/text /tell " + bot.Character + " " + command + " [password]");
                    window.AppendString("]");
                    break;

                case ConfigType.Custom:
                    string value10 = bot.Configuration.GetCustom(entry.Section, entry.Key);
                    if (value10 != null)
                    {
                        window.AppendRawString(value10);
                    }
                    break;
                }
                window.AppendString(" [");
                window.AppendBotCommand("Default", "configuration reset " + internalName + " " + entry.Key.ToLower());
                window.AppendString("]");
                window.AppendColorEnd();
                window.AppendLineBreak();
            }
            bot.SendReply(e, "Configuration »» " + loader.Name + " »» ", window);
        }