forked from sim0n00ps/OF-DL
Added update all UserInfo mode
This commit is contained in:
parent
811cafe5ca
commit
b5f41f530f
@ -112,6 +112,7 @@ namespace OF_DL.Entities
|
|||||||
public string[] NonInteractiveSpecificLists { get; set; } = [];
|
public string[] NonInteractiveSpecificLists { get; set; } = [];
|
||||||
|
|
||||||
public bool OutputBlockedUsers { get; set; }
|
public bool OutputBlockedUsers { get; set; }
|
||||||
|
public bool UpdateAllUserInfo { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CreatorConfig : IFileNameFormatConfig
|
public class CreatorConfig : IFileNameFormatConfig
|
||||||
|
|||||||
@ -235,6 +235,25 @@ namespace OF_DL.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Dictionary<string, long>> GetUsers()
|
||||||
|
{
|
||||||
|
SqliteConnection connection = await GetAndOpenConnectionAsync($"Data Source={Directory.GetCurrentDirectory()}/users.db");
|
||||||
|
using SqliteCommand cmd = new("SELECT user_id, username FROM users", connection);
|
||||||
|
using SqliteDataReader reader = cmd.ExecuteReader();
|
||||||
|
|
||||||
|
Dictionary<string, long> result = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
long userId = reader.GetInt64(0);
|
||||||
|
string username = reader.GetString(1);
|
||||||
|
|
||||||
|
result[username] = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateUserInfo(User? user)
|
public async Task UpdateUserInfo(User? user)
|
||||||
{
|
{
|
||||||
if (user is null)
|
if (user is null)
|
||||||
|
|||||||
@ -12,6 +12,7 @@ using OF_DL.Enumerations;
|
|||||||
using OF_DL.Enumurations;
|
using OF_DL.Enumurations;
|
||||||
using OF_DL.Helpers;
|
using OF_DL.Helpers;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using Serilog.Context;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
@ -531,6 +532,14 @@ public class Program
|
|||||||
config.OutputBlockedUsers = true;
|
config.OutputBlockedUsers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const string UPDATE_ALL_USER_INFO_ARG = "--update-userinfo";
|
||||||
|
|
||||||
|
if (args.Any(a => UPDATE_ALL_USER_INFO_ARG.Equals(a, StringComparison.OrdinalIgnoreCase)))
|
||||||
|
{
|
||||||
|
config.NonInteractiveMode = true;
|
||||||
|
config.UpdateAllUserInfo = true;
|
||||||
|
}
|
||||||
|
|
||||||
Log.Debug("Additional arguments:");
|
Log.Debug("Additional arguments:");
|
||||||
foreach (string argument in args)
|
foreach (string argument in args)
|
||||||
{
|
{
|
||||||
@ -872,6 +881,11 @@ public class Program
|
|||||||
await DownloadBlockedOrExpiredUsers(apiHelper, config);
|
await DownloadBlockedOrExpiredUsers(apiHelper, config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (config.UpdateAllUserInfo)
|
||||||
|
{
|
||||||
|
await UpdateAlluserInfo(apiHelper, config);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await DownloadAllData(apiHelper, auth, config);
|
await DownloadAllData(apiHelper, auth, config);
|
||||||
}
|
}
|
||||||
@ -938,6 +952,34 @@ public class Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task UpdateAlluserInfo(APIHelper m_ApiHelper, Entities.Config Config)
|
||||||
|
{
|
||||||
|
DBHelper dbHelper = new(Config);
|
||||||
|
|
||||||
|
await dbHelper.CreateUsersDB([]);
|
||||||
|
|
||||||
|
Dictionary<string, long> users = await dbHelper.GetUsers();
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
foreach ((string username, long userId) in users)
|
||||||
|
{
|
||||||
|
using (LogContext.PushProperty("Username", username))
|
||||||
|
using (LogContext.PushProperty("UserId", userId))
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log.Information("Updating User Info for for: {Username:l}");
|
||||||
|
AnsiConsole.Markup($"[green]Updating User Info for for: {username}\n[/]");
|
||||||
|
|
||||||
|
User ? user_info = await m_ApiHelper.GetUserInfo($"/users/{username}");
|
||||||
|
await dbHelper.UpdateUserInfo(user_info);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "Failed to update User Info for: {Username:l}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config)
|
private static async Task DownloadAllData(APIHelper m_ApiHelper, Auth Auth, Entities.Config Config)
|
||||||
{
|
{
|
||||||
DBHelper dBHelper = new DBHelper(Config);
|
DBHelper dBHelper = new DBHelper(Config);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user