Пример #1
0
        internal async Task <bool> InitialLoad()
        {
            LoadFileOperation storageSettings = await ResourcesModel.LoadToJSONObject(StorageDirectory + ID_SAFEFILE);

            if (storageSettings.Success)
            {
                if (storageSettings.Result.TryGetField(JSON_ID, out nextId))
                {
                    string[] files = Directory.GetFiles(StorageDirectory);
                    foreach (string filename in files)
                    {
                        if (filename.EndsWith("json") && filename.Contains("page-"))
                        {
                            LoadFileOperation PageFile = await ResourcesModel.LoadToJSONObject(filename);

                            if (PageFile.Success)
                            {
                                handlePageJSON(PageFile.Result);
                            }
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        internal static async Task <bool> LoadQuotes()
        {
            LoadFileOperation quoteSettings = await ResourcesModel.LoadToJSONObject(ResourcesModel.QuoteSettingsFilePath);

            if (quoteSettings.Success)
            {
                if (quoteSettings.Result.GetField(ref nextQuoteId, JSON_QUOTEID))
                {
                    string[] files = Directory.GetFiles(ResourcesModel.QuotesDirectory);
                    foreach (string filename in files)
                    {
                        if (filename.EndsWith("json") && filename.Contains("quotes-"))
                        {
                            LoadFileOperation QuoteFile = await ResourcesModel.LoadToJSONObject(filename);

                            if (QuoteFile.Success)
                            {
                                handleQuoteJSON(QuoteFile.Result);
                            }
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        private static async Task LoadGuildModerationLog(ulong guildId)
        {
            GuildModerationLog guildModerationLog = new GuildModerationLog(guildId);

            if (Directory.Exists(guildModerationLog.UserDirectory))
            {
                foreach (string filepath in Directory.EnumerateFiles(guildModerationLog.UserDirectory, "*.json"))
                {
                    LoadFileOperation load = await ResourcesModel.LoadToJSONObject(filepath);

                    if (load.Success)
                    {
                        UserModerationLog userModerationLog = new UserModerationLog(guildModerationLog);
                        if (userModerationLog.FromJSON(load.Result))
                        {
                            guildModerationLog.userLogs.Add(userModerationLog.UserId, userModerationLog);
                            if (userModerationLog.IsBanned)
                            {
                                if (userModerationLog.BannedUntil.Value < DateTimeOffset.MaxValue)
                                {
                                    AddTimeLimitedInfractionReference(userModerationLog);
                                }
                            }
                            else if (userModerationLog.IsMuted)
                            {
                                if (userModerationLog.MutedUntil.Value < DateTimeOffset.MaxValue)
                                {
                                    AddTimeLimitedInfractionReference(userModerationLog);
                                }
                            }
                        }
                    }
                }
            }
            if (Directory.Exists(guildModerationLog.ChannelDirectory))
            {
                foreach (string filepath in Directory.EnumerateFiles(guildModerationLog.ChannelDirectory, "*.json"))
                {
                    LoadFileOperation load = await ResourcesModel.LoadToJSONObject(filepath);

                    if (load.Success)
                    {
                        ChannelModerationLog channelModerationLog = new ChannelModerationLog(guildModerationLog);
                        if (channelModerationLog.FromJSON(load.Result))
                        {
                            guildModerationLog.channelLogs.Add(channelModerationLog.ChannelId, channelModerationLog);
                        }
                    }
                }
            }
            GuildLogs.Add(guildModerationLog.GuildId, guildModerationLog);
        }
Пример #4
0
        public static async Task Load()
        {
            var fileOperation = await ResourcesModel.LoadToJSONObject(ResourcesModel.GuildsFilePath);

            if (fileOperation.Success)
            {
                if (fileOperation.Result.IsArray)
                {
                    foreach (JSONField guild_json in fileOperation.Result.Array)
                    {
                        if (guild_json.IsObject)
                        {
                            MinecraftGuild guild = new MinecraftGuild();
                            if (guild.FromJSON(guild_json.Container))
                            {
                                guilds.Add(guild);
                            }
                        }
                    }
                }
            }
        }