feat: rework of argument read. Added possibility to analyze only one user.
This commit is contained in:
parent
df34347920
commit
1e40bbd735
38
ArgumentReader.cs
Normal file
38
ArgumentReader.cs
Normal file
@ -0,0 +1,38 @@
|
||||
namespace TelegramMessageCounter;
|
||||
|
||||
public static class ArgumentReader
|
||||
{
|
||||
public static DataRequest ReadArguments(string[] args)
|
||||
{
|
||||
string? login = null;
|
||||
string? username = null;
|
||||
if (args.Length > 0 && args.Any(x => x == "--help"))
|
||||
{
|
||||
Console.WriteLine("Usage: TelegramMessageCounter --login (phone number) --user (username) <path>" +
|
||||
"\n login - Phone number of telegram. If argument is empty, waiting for Keyboard interrupt" +
|
||||
"\nuser - Username of telegram for individual stats. If argument is empty, analyzing all user history" +
|
||||
"\n path - Path to save results file. If argument is empty, path will be \"results.txt\"\n");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
if (args.Any(x => x == "--user"))
|
||||
{
|
||||
var userNameArgIndex = args.ToList().IndexOf("--user");
|
||||
username = args[userNameArgIndex+1];
|
||||
}
|
||||
|
||||
if (args.Any(x => x == "--login" || x == "-L"))
|
||||
{
|
||||
var userNameArgIndex = args.ToList().IndexOf("--login");
|
||||
if (userNameArgIndex == -1)
|
||||
{
|
||||
userNameArgIndex = args.ToList().IndexOf("-L");
|
||||
}
|
||||
login = args[userNameArgIndex+1];
|
||||
}
|
||||
string? path = args.Length > 1 ? args.Last() : null;
|
||||
|
||||
return new(login, username, (path ?? default)!);
|
||||
|
||||
}
|
||||
}
|
3
DataRequest.cs
Normal file
3
DataRequest.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace TelegramMessageCounter;
|
||||
|
||||
public record DataRequest(string? Login, string? Username, string Path = "results.txt");
|
28
Program.cs
28
Program.cs
@ -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)
|
||||
|
11
README.md
11
README.md
@ -6,9 +6,10 @@ Program for calculate statistics of messages sended in telegram with your friend
|
||||
|
||||
## Usage
|
||||
|
||||
.\TelegramMessageCounter.exe <login (phone number)> <path>
|
||||
.\TelegramMessageCounter.exe --login (phone number) --user (username) <path>
|
||||
where
|
||||
- `login` - Phone number of telegram. If argument is empty, waiting for Keyboard interrupt
|
||||
- `--login (-L)` - Phone number of telegram. If argument is empty, waiting for Keyboard interrupt
|
||||
- `--user` - Username of telegram for individual stats. If argument is empty, analyzing all user history
|
||||
- `path` - Path to save results file. If argument is empty, path will be `results.txt`
|
||||
|
||||
To invoke this text use
|
||||
@ -16,9 +17,9 @@ To invoke this text use
|
||||
.\TelegramMessageCounter.exe --help
|
||||
|
||||
### Example
|
||||
.\TelegramMessageCounter.exe +14928587194
|
||||
.\TelegramMessageCounter.exe +14928587194 D:\Results\results.txt
|
||||
.\TelegramMessageCounter.exe
|
||||
.\TelegramMessageCounter.exe --login +14928587194
|
||||
.\TelegramMessageCounter.exe -L +14928587194 D:\Results\results.txt
|
||||
.\TelegramMessageCounter.exe -L +14928587194 --user lisoveliy
|
||||
|
||||
### Results
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user