Пример #1
0
        public void Initialize()
        {
            var dbName = DbConfig.DatabaseName;

            if (Process.GetProcesses().FirstOrDefault(x => x.ProcessName == "Raven.Server") == null)
            {
                PrettyConsole.Log(LogSeverity.Error, "Database", "Please make sure RavenDB is running.");
                Console.ReadLine();
                Environment.Exit(0);
            }


            _store = new Lazy <IDocumentStore>(
                () => new DocumentStore {
                Database = DbConfig.DatabaseName, Urls = new[] { DbConfig.DatabaseUrl }
            }
                .Initialize(),
                true).Value;
            if (_store == null)
            {
                PrettyConsole.Log(LogSeverity.Error, "Database", "Failed to build document store.");
            }


            if (_store.Maintenance.Server.Send(new GetDatabaseNamesOperation(0, 5)).All(x => x != dbName))
            {
                _store.Maintenance.Server.Send(new CreateDatabaseOperation(new DatabaseRecord(dbName)));
            }

            _store.AggressivelyCacheFor(TimeSpan.FromMinutes(30));


            using (var session = _store.OpenSession())
            {
                if (session.Advanced.Exists("Config"))
                {
                    return;
                }
                PrettyConsole.Log(LogSeverity.Info, "Arcade's Bot", "Enter Bot's Token:");
                var token = Console.ReadLine();
                PrettyConsole.Log(LogSeverity.Info, "Arcade's Bot", "Enter Bot's Prefix:");
                var prefix = Console.ReadLine();
                var model  = new ConfigModel
                {
                    Prefix     = prefix.Trim(),
                    Blacklist  = new List <ulong>(),
                    Namespaces = new List <string>(),
                    ApiKeys    = new Dictionary <string, string>
                    {
                        { "Giphy", "dc6zaTOxFJmzC" },
                        { "Google", "" },
                        { "Discord", token.Trim() },
                        { "Imgur", "" },
                        { "Cleverbot", "" }
                    }
                };
                var id = "Config";
                Create <ConfigModel>(ref id, model);
            }
        }