Пример #1
0
        /// <summary>
        /// Fills in the data fields from some backup. Previously we did that on Bot() initialization,
        /// we do that in a separate function now.
        /// </summary>
        /// <returns></returns>
        public async Task DelayedConstruction()
        {
            if (_primary == null)
            {
                throw new PrimaryGuildException("DelayedConstruction() called too early, the Discord API is not ready yet.");
            }

            if (Settings.BotFirstRun)
            {
                FirstRunDelayedConstruction();
                return;
            }

            if (constructionComplete)
            {
                throw new PrimaryGuildException("Construction called twice, that is not allowed.");
            }

            Console.WriteLine("Restoring guild list configuration from message backup.");
            BackupGuildConfiguration bgc = await RestoreGuildConfiguration();

            guilds = new DiscordGuilds(bgc, client);

            // We check for role creation here, instead of inside the constructor of DiscordGuild.
            // We do this not to make the constructor async itself. It might be better to check there.
            foreach (DiscordGuild g in guilds.byID.Values)
            {
                await g.RolePresenceCheckAsync();
            }

            Console.WriteLine("Populating data from the message backup.");


            BackupData recoverData = await RestoreDataStructures();

            _data = new BotDataStructure(recoverData);

            if (Settings.UsingExtensionBanTracking)
            {
                // Temporary: if the bds structure was not parsed from the backup, because it didn't exist, just create a new empty one.
                if (recoverData.bds == null)
                {
                    Console.WriteLine("Unable to restore the old ban data structure, creating an empty one.");
                    recoverData.bds = new Extensions.BanDataStructure();
                }

                bt = new Extensions.BanTracking(guilds, recoverData.bds);
            }

            if (Settings.UsingExtensionRoleHighlights)
            {
                _highlighter = new Extensions.MainHighlighter(guilds);
            }

            Console.WriteLine("Loaded " + _data.DiscordUplay.Count + " discord -- uplay connections.");
            Console.WriteLine("Loaded " + _data.QuietPlayers.Count + " players who wish not to be pinged.");
            Console.WriteLine("Loaded " + _data.DiscordRanks.Count + " current player ranks.");

            constructionComplete = true;
        }
Пример #2
0
        /// <summary>
        /// An initial construction, if the bot is run for the first time.
        /// </summary>
        /// <returns></returns>
        public void FirstRunDelayedConstruction()
        {
            if (File.Exists(Settings.backupFile))
            {
                Console.WriteLine("Warning: There already exists a backup file, but your first run variable is set to true. Please keep it in mind");
            }

            _data = new BotDataStructure();

            if (Settings.UsingExtensionBanTracking)
            {
                bt = new Extensions.BanTracking(guilds);
            }

            if (Settings.UsingExtensionRoleHighlights)
            {
                _highlighter = new Extensions.MainHighlighter(guilds);
            }
        }