forked from sim0n00ps/OF-DL
Added step to insert non-nude list members in Db
This commit is contained in:
parent
d417741702
commit
7e0fdb3ebf
@ -21,6 +21,10 @@ public class CajetanDbService(IConfigService configService)
|
||||
await cmdInfo.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
using (SqliteCommand cmdNonNude = new("CREATE TABLE IF NOT EXISTS user_non_nude (user_id INTEGER NOT NULL, name VARCHAR NOT NULL, PRIMARY KEY(user_id)", connection))
|
||||
{
|
||||
await cmdNonNude.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, long>> GetUsersAsync()
|
||||
@ -91,7 +95,7 @@ public class CajetanDbService(IConfigService configService)
|
||||
|
||||
cmdInfo.Parameters.AddWithValue("@userId", userInfo.Id);
|
||||
cmdInfo.Parameters.AddWithValue("@name", userInfo.Name ?? userInfo.Username);
|
||||
cmdInfo.Parameters.AddWithValue("@blob", Newtonsoft.Json.JsonConvert.SerializeObject(userInfo));
|
||||
cmdInfo.Parameters.AddWithValue("@blob", JsonConvert.SerializeObject(userInfo));
|
||||
|
||||
try
|
||||
{
|
||||
@ -104,4 +108,36 @@ public class CajetanDbService(IConfigService configService)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateNonNudeCollectionAsync(Dictionary<string, long> usersInNonNudeLists)
|
||||
{
|
||||
if (usersInNonNudeLists.Count == 0)
|
||||
return;
|
||||
|
||||
await using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db");
|
||||
|
||||
Log.Debug("Database data source: " + connection.DataSource);
|
||||
|
||||
foreach ((string username, long userId) in usersInNonNudeLists)
|
||||
{
|
||||
using SqliteCommand cmdInfo = new(
|
||||
"INSERT OR REPLACE INTO user_non_nude (user_id, name) " +
|
||||
"VALUES (@userId, @name);",
|
||||
connection
|
||||
);
|
||||
|
||||
cmdInfo.Parameters.AddWithValue("@userId", userId);
|
||||
cmdInfo.Parameters.AddWithValue("@name", username);
|
||||
|
||||
try
|
||||
{
|
||||
await cmdInfo.ExecuteNonQueryAsync();
|
||||
Log.Debug("Updating Non-Nude collection with: {Username:l}", username);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Failed to update Non-Nude collection with: {Username:l}", username);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,4 +6,5 @@ public interface ICajetanDbService : IDbService
|
||||
|
||||
Task<Dictionary<string, long>> GetUsersAsync();
|
||||
Task UpdateUserInfoAsync(UserEntities.UserInfo? userInfo);
|
||||
Task UpdateNonNudeCollectionAsync(Dictionary<string, long> usersInNonNudeLists);
|
||||
}
|
||||
|
||||
@ -364,6 +364,8 @@ internal class Worker(IServiceProvider serviceProvider)
|
||||
await _dbService.CreateUsersDb(result.Users);
|
||||
await _dbService.InitializeUserInfoTablesAsync();
|
||||
|
||||
await UpdateNonNudeListAsync();
|
||||
|
||||
return result;
|
||||
|
||||
async Task FetchUsersAsync()
|
||||
@ -390,6 +392,28 @@ internal class Worker(IServiceProvider serviceProvider)
|
||||
result.Lists = await _apiService.GetLists("/lists") ?? [];
|
||||
}
|
||||
|
||||
async Task UpdateNonNudeListAsync()
|
||||
{
|
||||
const string LIST_NAME = "NonNude";
|
||||
const long LIST_ID = 1220021758;
|
||||
|
||||
HashSet<string> listNames = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (result.Lists.ContainsKey(LIST_NAME))
|
||||
listNames.Add(LIST_NAME);
|
||||
|
||||
string? nameById = result.Lists.FirstOrDefault(l => l.Value == LIST_ID).Key;
|
||||
if (!string.IsNullOrWhiteSpace(nameById))
|
||||
listNames.Add(nameById);
|
||||
|
||||
Dictionary<string, long> usersInNonNudeLists = await GetUsersFromSpecificListsAsync(result, [.. listNames]);
|
||||
|
||||
AnsiConsole.Markup($"[green]Updating Non-Nude collection with {usersInNonNudeLists.Count} Users[/]");
|
||||
await _dbService.UpdateNonNudeCollectionAsync(usersInNonNudeLists);
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
}
|
||||
|
||||
void AddToResult(Dictionary<string, long>? subscriptions)
|
||||
{
|
||||
foreach ((string username, long userId) in subscriptions ?? [])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user