Пример #1
0
        public void SaveChanges()
        {
            lock (Settings)
            {
                BotDao.SaveSettings(Settings);
            }

            return;
        }
Пример #2
0
        public async Task <bool> Initialize()
        {
            Console.WriteLine("Welcome to LanDiscordBot!\nBeginning initialization process...");

            // Load settings
            Console.WriteLine("Loading bot settings...");

            try
            {
                Settings = BotDao.LoadSettings();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (Settings == null)
            {
                Console.WriteLine("Invalid settings file.  Creating new settings file.");

                Settings = new BotSettings();

                BotDao.SaveSettings(Settings);
            }

            if (Settings.AuthToken.Length < 1)
            {
                Console.WriteLine("Invalid auth token!  Please set your bot's auth token in config/bot.json.");

                return(false);
            }

            Console.WriteLine("Bot settings loaded.");

            // Login to Discord
            Console.WriteLine("Logging into Discord...");
            try
            {
                await Client.LoginAsync(TokenType.Bot, Settings.AuthToken);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            if (Client.LoginState != LoginState.LoggedIn)
            {
                Console.WriteLine("Login failure!  Please verify your auth token in config/bot.json.");

                return(false);
            }

            Console.WriteLine("Login successful!");

            // Accounts init
            Console.WriteLine("Loading accounting...");

            try
            {
                Accounts = AccountDao.LoadAccounts();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (Accounts == null)
            {
                Console.WriteLine("Invalid accounting file.  Creating new accounting file.");

                if (Accounts == null)
                {
                    Accounts = new AccountService();
                }

                AccountDao.SaveAccounts(Accounts);
            }

            Accounts.Initialize(this);

            Console.WriteLine("Accounting loaded.");

            Scp.Initialize();
            Dad.Initialize();
            Chat.Initialize();
            Highlights.Initialize();

            Console.WriteLine("Starting Discord client...");
            await Client.StartAsync();

            Console.WriteLine("Finishing up initialization...");
            await Client.SetGameAsync(Settings.PlayStatus);

            Console.WriteLine("Initialization complete!");

            return(true);
        }
Пример #3
0
 public BotManager()
 {
     _dao       = new BotDao();
     _responses = new List <BotResponse>();
 }