Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
d641857437 | |||
306bb27f03 | |||
d0ad97f08b | |||
e9db40dee9 | |||
1e40bbd735 |
44
ArgumentReader.cs
Normal file
44
ArgumentReader.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
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"))
|
||||||
|
{
|
||||||
|
var helpFile = Assembly.GetExecutingAssembly()
|
||||||
|
.GetManifestResourceStream("TelegramMessageCounter.help.txt");
|
||||||
|
Console.WriteLine(new StreamReader(helpFile ?? new MemoryStream()).ReadToEnd());
|
||||||
|
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?[] argValues = [login, username];
|
||||||
|
string? path = args.Length > 1 && argValues.All(x => x != args.Last()) ? args.Last() : null;
|
||||||
|
|
||||||
|
if (path == null)
|
||||||
|
return new(login, username);
|
||||||
|
|
||||||
|
return new(login, username, path);
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,23 @@
|
|||||||
using System;
|
using CsvHelper.Configuration.Attributes;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace TelegramMessageCounter
|
namespace TelegramMessageCounter;
|
||||||
{
|
|
||||||
internal record CounterInfo
|
public record CounterInfo(
|
||||||
(
|
[property: Name("Message multiplier")]
|
||||||
float Multiplier,
|
float MessageMultiplier,
|
||||||
int TargetMsg,
|
[property: Name("Symbols multiplier")]
|
||||||
int MyMsg,
|
float SymbolsMultiplier,
|
||||||
int FullMsg,
|
[property: Name("Your messages")]
|
||||||
string TargetUsername
|
int UserMessageCount,
|
||||||
);
|
[property: Name("Target messages")]
|
||||||
}
|
int TargetMessageCount,
|
||||||
|
[property: Name("Your symbols")]
|
||||||
|
int UserSymbolsCount,
|
||||||
|
[property: Name("Target symbols")]
|
||||||
|
int TargetSymbolsCount,
|
||||||
|
[property: Name("All messages")]
|
||||||
|
int FullMessageCount,
|
||||||
|
[Index(0)]
|
||||||
|
[property: Name("Target username")]
|
||||||
|
string TargetUsername
|
||||||
|
);
|
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");
|
120
Program.cs
120
Program.cs
@ -5,68 +5,71 @@ namespace TelegramMessageCounter
|
|||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
private static readonly Client Client = new(23711185, "9e23f24bbb2f3dc3e561c0a5c9d3e622"); //Please, create your client, but don't shy use it if you are lazy :)
|
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)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length > 0 && args[0] == "--help")
|
var dataRequest = ArgumentReader.ReadArguments(args);
|
||||||
{
|
var username = dataRequest.Login;
|
||||||
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;
|
|
||||||
Splash.MakeSplash();
|
Splash.MakeSplash();
|
||||||
|
|
||||||
loginStage:
|
loginStage:
|
||||||
if (login is null)
|
if (username is null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Enter your phone number: ");
|
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!");
|
Console.WriteLine("Login is invalid!");
|
||||||
goto loginStage;
|
goto loginStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
Helpers.Log = (_, _) => { }; //force logger to shut up
|
Helpers.Log = (_, _) => { }; //force logger to shut up
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine("Waiting to login...");
|
Console.WriteLine("Waiting to login...");
|
||||||
|
|
||||||
DoLogin(login).Wait();
|
DoLogin(username).Wait();
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("[DONE]"); //Check logged
|
Console.WriteLine("[DONE]"); //Check logged
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
Console.WriteLine($"Welcome, {Client.User}!");
|
Console.WriteLine($"Welcome, {Client.User}!");
|
||||||
List<CounterInfo> infos = [];
|
List<CounterInfo> infos = [];
|
||||||
foreach(var user in Client.Messages_GetAllDialogs().Result.users.Values)
|
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);
|
var res = GetInfo(user.id);
|
||||||
if (res == null)
|
if (res == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"User {user.id} not found! Skipping...");
|
Console.WriteLine($"[WARN]User {user.id} failed to analyze! Skipping...");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine($"Multiplier {Client.User}/{res.TargetUsername} is: {res.Multiplier} of {res.MyMsg}/{res.TargetMsg} and total {res.FullMsg} messages");
|
Console.WriteLine(
|
||||||
|
$"MessageMultiplier {Client.User}/{res.TargetUsername} is: {res.MessageMultiplier} of {res.UserMessageCount}/{res.TargetMessageCount} and total {res.FullMessageCount} messages");
|
||||||
infos.Add(res);
|
infos.Add(res);
|
||||||
}
|
}
|
||||||
if(path is not null)
|
|
||||||
SaveAndAddStats(infos, path);
|
if (dataRequest.Path.Contains(".csv"))
|
||||||
|
ResultWriter.SaveStatsToCsv(infos, dataRequest.Path);
|
||||||
else
|
else
|
||||||
SaveAndAddStats(infos);
|
ResultWriter.SaveStatsToTxt(infos, dataRequest.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CounterInfo? GetInfo(long targetId)
|
static CounterInfo? GetInfo(long targetId)
|
||||||
{
|
{
|
||||||
var dialogs = Client.Messages_GetAllDialogs().Result;
|
var dialogs = Client.Messages_GetAllDialogs().Result;
|
||||||
int myCounter = 0;
|
int userMsgCount = 0;
|
||||||
int targetCounter = 0;
|
int userSymbolsCount = 0;
|
||||||
|
int targetMsgCount = 0;
|
||||||
|
int targetSymbolsCount = 0;
|
||||||
User? peer;
|
User? peer;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -77,7 +80,7 @@ namespace TelegramMessageCounter
|
|||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("[DONE]");
|
Console.WriteLine("[DONE]");
|
||||||
Console.WriteLine($"Username is: {(peer)?.username}");
|
Console.WriteLine($"Username is: {peer?.username}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -88,7 +91,7 @@ namespace TelegramMessageCounter
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Messages_MessagesBase> messagesList = [];
|
List<Messages_MessagesBase> messagesList = [];
|
||||||
var messageCount = 0;
|
var fullMsgCount = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var res = Client.Messages_GetHistory((InputPeer)peer).Result;
|
var res = Client.Messages_GetHistory((InputPeer)peer).Result;
|
||||||
@ -108,7 +111,8 @@ namespace TelegramMessageCounter
|
|||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageCount =res.Count;
|
|
||||||
|
fullMsgCount = res.Count;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@ -125,55 +129,47 @@ namespace TelegramMessageCounter
|
|||||||
{
|
{
|
||||||
if (msg.from_id != null)
|
if (msg.from_id != null)
|
||||||
{
|
{
|
||||||
myCounter++;
|
userMsgCount++;
|
||||||
|
userSymbolsCount += msg.message.Length;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
targetMsgCount++;
|
||||||
|
targetSymbolsCount += msg.message.Length;
|
||||||
}
|
}
|
||||||
else targetCounter++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("[DONE]");
|
Console.WriteLine("[DONE]");
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
return new(
|
return new(
|
||||||
(float)myCounter / targetCounter,
|
(float)userMsgCount / targetMsgCount,
|
||||||
targetCounter,
|
(float)userSymbolsCount / targetSymbolsCount,
|
||||||
myCounter,
|
userMsgCount,
|
||||||
messageCount,
|
targetMsgCount,
|
||||||
|
userSymbolsCount,
|
||||||
|
targetSymbolsCount,
|
||||||
|
fullMsgCount,
|
||||||
string.IsNullOrEmpty(peer?.username ?? "") ? peer?.id.ToString() ?? "unknown" : $"@{peer?.username}");
|
string.IsNullOrEmpty(peer?.username ?? "") ? peer?.id.ToString() ?? "unknown" : $"@{peer?.username}");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SaveAndAddStats(List<CounterInfo> infos, string path = "results.txt")
|
|
||||||
{
|
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
||||||
Console.Write("Saving results...");
|
|
||||||
File.Create("results.txt");
|
|
||||||
string fileData = "";
|
|
||||||
float multiplier = 0;
|
|
||||||
foreach (CounterInfo info in infos)
|
|
||||||
{
|
|
||||||
fileData += "username: " + info.TargetUsername + "\n" +
|
|
||||||
"multiplier: " + info.Multiplier + "\n" +
|
|
||||||
"total messages: " + info.FullMsg + "\n" +
|
|
||||||
"your messages: " + info.MyMsg + "\n" +
|
|
||||||
"target messages: " + info.TargetMsg + "\n-----\n";
|
|
||||||
multiplier += info.Multiplier;
|
|
||||||
}
|
|
||||||
multiplier /= infos.Count;
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
Console.WriteLine("[DONE]");
|
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
|
||||||
Console.WriteLine($"Middle result is: {multiplier}");
|
|
||||||
File.WriteAllText(path, fileData);
|
|
||||||
Console.WriteLine("Goodbye!");
|
|
||||||
}
|
|
||||||
static async Task DoLogin(string loginInfo)
|
static async Task DoLogin(string loginInfo)
|
||||||
{
|
{
|
||||||
while (Client.User == null)
|
while (Client.User == null)
|
||||||
switch (await Client.Login(loginInfo)) // returns which config is needed to continue login
|
switch (await Client.Login(loginInfo)) // returns which config is needed to continue login
|
||||||
{
|
{
|
||||||
case "verification_code": Console.Write("Code: "); loginInfo = Console.ReadLine()!; break;
|
case "verification_code":
|
||||||
case "password": Console.Write("Password: "); loginInfo = Console.ReadLine()!; break; // if user has enabled 2FA
|
Console.Write("Code: ");
|
||||||
|
loginInfo = Console.ReadLine()!;
|
||||||
|
break;
|
||||||
|
case "password":
|
||||||
|
Console.Write("Password: ");
|
||||||
|
loginInfo = Console.ReadLine()!;
|
||||||
|
break; // if user has enabled 2FA
|
||||||
default: loginInfo = null!; break;
|
default: loginInfo = null!; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
README.md
14
README.md
@ -6,19 +6,21 @@ Program for calculate statistics of messages sended in telegram with your friend
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
.\TelegramMessageCounter.exe <login (phone number)> <path>
|
.\TelegramMessageCounter.exe --login <phone_number> --user <username> <path>
|
||||||
where
|
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
|
||||||
- `path` - Path to save results file. If argument is empty, path will be `results.txt`
|
- `--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`, if path contain '.csv' program
|
||||||
|
will output stats in CSV format.
|
||||||
|
|
||||||
To invoke this text use
|
To invoke this text use
|
||||||
|
|
||||||
.\TelegramMessageCounter.exe --help
|
.\TelegramMessageCounter.exe --help
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
.\TelegramMessageCounter.exe +14928587194
|
.\TelegramMessageCounter.exe --login +14928587194
|
||||||
.\TelegramMessageCounter.exe +14928587194 D:\Results\results.txt
|
.\TelegramMessageCounter.exe -L +14928587194 D:\Results\results.txt
|
||||||
.\TelegramMessageCounter.exe
|
.\TelegramMessageCounter.exe -L +14928587194 --user lisoveliy
|
||||||
|
|
||||||
### Results
|
### Results
|
||||||
|
|
||||||
|
50
ResultWriter.cs
Normal file
50
ResultWriter.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using CsvHelper;
|
||||||
|
|
||||||
|
namespace TelegramMessageCounter;
|
||||||
|
|
||||||
|
public static class ResultWriter
|
||||||
|
{
|
||||||
|
public static void SaveStatsToTxt(List<CounterInfo> infos, string path = "results.txt")
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.Write($"Saving results to {path}...");
|
||||||
|
string fileData = "";
|
||||||
|
float multiplier = 0;
|
||||||
|
foreach (CounterInfo info in infos)
|
||||||
|
{
|
||||||
|
fileData += "username: " + info.TargetUsername + "\n" +
|
||||||
|
"message multiplier (You/Target): " + info.MessageMultiplier + "\n" +
|
||||||
|
"symbol multiplier (You/Target): " + info.SymbolsMultiplier + "\n" +
|
||||||
|
"total messages: " + info.FullMessageCount + "\n" +
|
||||||
|
"your messages: " + info.UserMessageCount + "\n" +
|
||||||
|
"target messages: " + info.TargetMessageCount + "\n" +
|
||||||
|
"your symbols in messages: " + info.UserSymbolsCount + "\n" +
|
||||||
|
"target symbols in messages: " + info.TargetSymbolsCount + "\n-----\n";
|
||||||
|
multiplier += info.MessageMultiplier;
|
||||||
|
}
|
||||||
|
multiplier /= infos.Count;
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[DONE]");
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.WriteLine($"Middle result is: {multiplier}");
|
||||||
|
File.WriteAllText(path, fileData);
|
||||||
|
Console.WriteLine("Goodbye!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveStatsToCsv(List<CounterInfo> infos, string path = "results.csv")
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.Write($"Saving results to {path}...");
|
||||||
|
|
||||||
|
using (var writer = new StreamWriter(path))
|
||||||
|
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
|
||||||
|
{
|
||||||
|
csv.WriteRecords(infos);
|
||||||
|
}
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[DONE]");
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.WriteLine("Goodbye!");
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,7 @@
|
|||||||
Console.WriteLine("/__ \\/\\/\\ / __\\");
|
Console.WriteLine("/__ \\/\\/\\ / __\\");
|
||||||
Console.WriteLine(" / /\\/ \\ / / ");
|
Console.WriteLine(" / /\\/ \\ / / ");
|
||||||
Console.WriteLine(" / / / /\\/\\ \\/ /___ ");
|
Console.WriteLine(" / / / /\\/\\ \\/ /___ ");
|
||||||
Console.WriteLine(" \\/ \\/ \\/\\____/ v1.3 ꞵeta");
|
Console.WriteLine($" \\/ \\/ \\/\\____/ v{System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version} ꞵeta");
|
||||||
Console.WriteLine("Telegram Message Counter by Lisoveliy");
|
Console.WriteLine("Telegram Message Counter by Lisoveliy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,19 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Company>Lisoveliy</Company>
|
<Company>Lisoveliy</Company>
|
||||||
<Authors>Lisoveliy</Authors>
|
<Authors>Lisoveliy</Authors>
|
||||||
<AssemblyVersion>0.1.3</AssemblyVersion>
|
<AssemblyVersion>0.2.1.0</AssemblyVersion>
|
||||||
<FileVersion>0.1.3</FileVersion>
|
<FileVersion>0.2.1.0</FileVersion>
|
||||||
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CsvHelper" Version="33.0.1" />
|
||||||
<PackageReference Include="WTelegramClient" Version="3.5.3" />
|
<PackageReference Include="WTelegramClient" Version="3.5.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="help.txt" />
|
||||||
|
<EmbeddedResource Include="help.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
5
help.txt
Normal file
5
help.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Usage: TelegramMessageCounter --login <phone_number> --user <username> <path>
|
||||||
|
|
||||||
|
--login <phone_number> - Phone number of telegram. If argument is empty, waiting for Keyboard interrupt
|
||||||
|
--user <user> - Username of telegram for individual stats. If argument is empty, analyzing all users history
|
||||||
|
<path> - Path to save results file. If argument is empty, path will be `results.txt`, if path contain '.csv' program will output stats in CSV format.
|
Loading…
x
Reference in New Issue
Block a user