private async Task HandleGuildRegister(GuildConfig guildConfig, bool importExistingBans) { using var scope = _serviceProvider.CreateScope(); var discordAPI = scope.ServiceProvider.GetRequiredService <DiscordAPIInterface>(); var scheduler = scope.ServiceProvider.GetRequiredService <Scheduler>(); var translator = scope.ServiceProvider.GetRequiredService <Translator>(); await scheduler.CacheAllKnownGuilds(); await scheduler.CacheAllGuildMembers(new List <ulong>()); await scheduler.CacheAllGuildBans(new List <ulong>()); if (importExistingBans) { translator.SetContext(guildConfig); ModCaseRepository modCaseRepository = ModCaseRepository.CreateWithBotIdentity(scope.ServiceProvider); foreach (IBan ban in await discordAPI.GetGuildBans(guildConfig.GuildId, CacheBehavior.OnlyCache)) { ModCase modCase = new() { Title = string.IsNullOrEmpty(ban.Reason) ? translator.T().ImportedFromExistingBans() : ban.Reason, Description = string.IsNullOrEmpty(ban.Reason) ? translator.T().ImportedFromExistingBans() : ban.Reason, GuildId = guildConfig.GuildId, UserId = ban.User.Id, Username = ban.User.Username, Labels = new[] { translator.T().Imported() }, Discriminator = ban.User.Discriminator, CreationType = CaseCreationType.Imported, PunishmentType = PunishmentType.Ban, PunishedUntil = null }; await modCaseRepository.ImportModCase(modCase); } } }