feat: rework of argument read. Added possibility to analyze only one user.

This commit is contained in:
Savely Savianok
2025-02-11 20:51:33 +03:00
parent df34347920
commit 1e40bbd735
4 changed files with 58 additions and 22 deletions

View File

@@ -8,25 +8,19 @@ namespace TelegramMessageCounter
private static readonly Client Client = new(23711185, "9e23f24bbb2f3dc3e561c0a5c9d3e622"); //Please, create your client, but don't shy use it if you are lazy :)
static void Main(string[] args)
{
if (args.Length > 0 && args[0] == "--help")
{
Console.WriteLine("Usage: TelegramMessageCounter <login (phone number)> <path>" +
"\n login - Phone number of telegram. If argument is empty, waiting for Keyboard interrupt" +
"\n path - Path to save results file. If argument is empty, path will be \"results.txt\"\n");
}
string? login = args.Length > 0 ? args[0] : null;
string? path = args.Length > 1 ? args[1] : null;
var dataRequest = ArgumentReader.ReadArguments(args);
var username = dataRequest.Login;
Splash.MakeSplash();
loginStage:
if (login is null)
if (username is null)
{
Console.WriteLine("Enter your phone number: ");
login = Console.ReadLine();
username = Console.ReadLine();
}
if (login is null)
if (username is null)
{
Console.WriteLine("Login is invalid!");
goto loginStage;
@@ -37,7 +31,7 @@ namespace TelegramMessageCounter
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Waiting to login...");
DoLogin(login).Wait();
DoLogin(username).Wait();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[DONE]"); //Check logged
@@ -46,6 +40,9 @@ namespace TelegramMessageCounter
List<CounterInfo> infos = [];
foreach(var user in Client.Messages_GetAllDialogs().Result.users.Values)
{
if(dataRequest.Username is not null && user.username != dataRequest.Username)
continue;
var res = GetInfo(user.id);
if (res == null)
{
@@ -56,10 +53,7 @@ namespace TelegramMessageCounter
Console.WriteLine($"Multiplier {Client.User}/{res.TargetUsername} is: {res.Multiplier} of {res.MyMsg}/{res.TargetMsg} and total {res.FullMsg} messages");
infos.Add(res);
}
if(path is not null)
SaveAndAddStats(infos, path);
else
SaveAndAddStats(infos);
SaveAndAddStats(infos, dataRequest.Path);
}
static CounterInfo? GetInfo(long targetId)