Ejemplo n.º 1
0
 public ChannelModerationLog GetOrCreateChannelModerationLog(ulong channelId)
 {
     if (!channelLogs.TryGetValue(channelId, out ChannelModerationLog channelModerationLog))
     {
         channelModerationLog = new ChannelModerationLog(this, channelId);
         channelLogs.Add(channelId, channelModerationLog);
     }
     return(channelModerationLog);
 }
Ejemplo n.º 2
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);
        }