Fix potential conflict on System.Collections.Immutable

This commit is contained in:
Wizou 2024-04-16 15:19:12 +02:00
parent 8c271f50f6
commit 1d07039f04
10 changed files with 18 additions and 15 deletions

View file

@ -11,7 +11,7 @@ await client.LoginUserIfNeeded();
``` ```
In this case, environment variables are used for configuration so make sure to In this case, environment variables are used for configuration so make sure to
go to your **Project Properties > Debug > Environment variables** go to your **Project Properties > Debug > Launch Profiles > Environment variables**
and add at least these variables with adequate values: **api_id, api_hash, phone_number** and add at least these variables with adequate values: **api_id, api_hash, phone_number**
Remember that these are just simple example codes that you should adjust to your needs. Remember that these are just simple example codes that you should adjust to your needs.
@ -389,9 +389,9 @@ var chat = chats.chats[1234567890]; // the target chat
After the above code, once you [have obtained](FAQ.md#access-hash) an `InputUser` or `User`, you can: After the above code, once you [have obtained](FAQ.md#access-hash) an `InputUser` or `User`, you can:
```csharp ```csharp
// • Directly add the user to a Chat/Channel/group: // • Directly add the user to a Chat/Channel/group:
await client.AddChatUser(chat, user); var miu = await client.AddChatUser(chat, user);
// You may get exception USER_PRIVACY_RESTRICTED if the user has denied the right to be added to a chat // You may get exception USER_NOT_MUTUAL_CONTACT if the user left the chat previously and you want to add him again
// or exception USER_NOT_MUTUAL_CONTACT if the user left the chat previously and you want to add him again // or a result with miu.missing_invitees listing users that denied the right to be added to a chat
// • Obtain the main invite link for the chat, and send it to the user: // • Obtain the main invite link for the chat, and send it to the user:
var mcf = await client.GetFullChat(chat); var mcf = await client.GetFullChat(chat);

View file

@ -7,7 +7,7 @@ namespace WTelegramClientTest
{ {
static class Program_DownloadSavedMedia static class Program_DownloadSavedMedia
{ {
// go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number
static async Task Main(string[] _) static async Task Main(string[] _)
{ {
Console.WriteLine("The program will download photos/medias from messages you send/forward to yourself (Saved Messages)"); Console.WriteLine("The program will download photos/medias from messages you send/forward to yourself (Saved Messages)");

View file

@ -9,7 +9,7 @@ namespace WTelegramClientTest
// This code is similar to what you should have obtained if you followed the README introduction // This code is similar to what you should have obtained if you followed the README introduction
// I've just added a few comments to explain further what's going on // I've just added a few comments to explain further what's going on
// go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number
static string Config(string what) static string Config(string what)
{ {
if (what == "api_id") return Environment.GetEnvironmentVariable("api_id"); if (what == "api_id") return Environment.GetEnvironmentVariable("api_id");

View file

@ -75,7 +75,7 @@ namespace WTelegramClientTest
var parts = databaseUrl.Split(':', '/', '@'); var parts = databaseUrl.Split(':', '/', '@');
_sql = new NpgsqlConnection($"User ID={parts[3]};Password={parts[4]};Host={parts[5]};Port={parts[6]};Database={parts[7]};Pooling=true;SSL Mode=Require;Trust Server Certificate=True;"); _sql = new NpgsqlConnection($"User ID={parts[3]};Password={parts[4]};Host={parts[5]};Port={parts[6]};Database={parts[7]};Pooling=true;SSL Mode=Require;Trust Server Certificate=True;");
_sql.Open(); _sql.Open();
using (var create = new NpgsqlCommand($"CREATE TABLE IF NOT EXISTS WTelegram_sessions (name text NOT NULL PRIMARY KEY, data bytea)", _sql)) using (var create = new NpgsqlCommand("CREATE TABLE IF NOT EXISTS WTelegram_sessions (name text NOT NULL PRIMARY KEY, data bytea)", _sql))
create.ExecuteNonQuery(); create.ExecuteNonQuery();
using var cmd = new NpgsqlCommand($"SELECT data FROM WTelegram_sessions WHERE name = '{_sessionName}'", _sql); using var cmd = new NpgsqlCommand($"SELECT data FROM WTelegram_sessions WHERE name = '{_sessionName}'", _sql);
using var rdr = cmd.ExecuteReader(); using var rdr = cmd.ExecuteReader();
@ -134,7 +134,7 @@ HOW TO USE AND DEPLOY THIS EXAMPLE HEROKU USERBOT:
- In Visual Studio, Clone the Heroku git repository and add some standard .gitignore .gitattributes files - In Visual Studio, Clone the Heroku git repository and add some standard .gitignore .gitattributes files
- In this repository folder, create a new .NET Console project with this Program.cs file - In this repository folder, create a new .NET Console project with this Program.cs file
- Add these Nuget packages: WTelegramClient and Npgsql - Add these Nuget packages: WTelegramClient and Npgsql
- In Project properties > Debug > Environment variables, configure the same values for DATABASE_URL, api_hash, phone_number - In Project properties > Debug > Launch Profiles > Environment variables, configure the same values for DATABASE_URL, api_hash, phone_number
- Run the project in Visual Studio. The first time, it should ask you interactively for elements to complete the connection - Run the project in Visual Studio. The first time, it should ask you interactively for elements to complete the connection
- On the following runs, the PostgreSQL database contains the session data and it should connect automatically - On the following runs, the PostgreSQL database contains the session data and it should connect automatically
- You can test the userbot by sending him "Ping" in private message (or saved messages). It should respond with "Pong" - You can test the userbot by sending him "Ping" in private message (or saved messages). It should respond with "Pong"

View file

@ -10,7 +10,7 @@ namespace WTelegramClientTest
static WTelegram.UpdateManager Manager; static WTelegram.UpdateManager Manager;
static User My; static User My;
// go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number
static async Task Main(string[] _) static async Task Main(string[] _)
{ {
Console.WriteLine("The program will display updates received for the logged-in user. Press any key to terminate"); Console.WriteLine("The program will display updates received for the logged-in user. Press any key to terminate");

View file

@ -8,7 +8,7 @@ namespace WTelegramClientTest
{ {
static WTelegram.Client Client; static WTelegram.Client Client;
// go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number
static async Task Main(string[] _) static async Task Main(string[] _)
{ {
Console.WriteLine("The program demonstrate how to handle ReactorError. Press any key to terminate"); Console.WriteLine("The program demonstrate how to handle ReactorError. Press any key to terminate");

View file

@ -16,7 +16,7 @@ namespace WTelegramClientTest
static readonly Dictionary<long, User> Users = []; static readonly Dictionary<long, User> Users = [];
static readonly Dictionary<long, ChatBase> Chats = []; static readonly Dictionary<long, ChatBase> Chats = [];
// go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number // go to Project Properties > Debug > Launch Profiles > Environment variables and add at least these: api_id, api_hash, phone_number
static async Task Main() static async Task Main()
{ {
Helpers.Log = (l, s) => System.Diagnostics.Debug.WriteLine(s); Helpers.Log = (l, s) => System.Diagnostics.Debug.WriteLine(s);

View file

@ -80,7 +80,7 @@ namespace TL
return reader.ReadTL(ctorNb); return reader.ReadTL(ctorNb);
#else #else
if (ctorNb == 0) ctorNb = reader.ReadUInt32(); if (ctorNb == 0) ctorNb = reader.ReadUInt32();
if (ctorNb == Layer.GZipedCtor) return reader.ReadTLGzipped(); if (ctorNb == Layer.GZipedCtor) return (IObject)reader.ReadTLGzipped(typeof(IObject));
if (!Layer.Table.TryGetValue(ctorNb, out var type)) if (!Layer.Table.TryGetValue(ctorNb, out var type))
throw new WTelegram.WTException($"Cannot find type for ctor #{ctorNb:x}"); throw new WTelegram.WTException($"Cannot find type for ctor #{ctorNb:x}");
if (type == null) return null; // nullable ctor (class meaning is associated with null) if (type == null) return null; // nullable ctor (class meaning is associated with null)

View file

@ -58,7 +58,7 @@ namespace WTelegram
_onUpdate = onUpdate; _onUpdate = onUpdate;
_collector = collector ?? new Services.CollectorPeer(Users = [], Chats = []); _collector = collector ?? new Services.CollectorPeer(Users = [], Chats = []);
if (state == null) if (state == null || state.Count < 3)
_local = new() { [L_SEQ] = new() { access_hash = UndefinedSeqDate }, [L_QTS] = new(), [L_PTS] = new() }; _local = new() { [L_SEQ] = new() { access_hash = UndefinedSeqDate }, [L_QTS] = new(), [L_PTS] = new() };
else else
_local = state as Dictionary<long, MBoxState> ?? new Dictionary<long, MBoxState>(state); _local = state as Dictionary<long, MBoxState> ?? new Dictionary<long, MBoxState>(state);

View file

@ -43,7 +43,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" /> <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>--> </ItemGroup>-->
<ItemGroup Condition="$(DefineConstants.Contains('MTPG'))" > <ItemGroup Condition="$(DefineConstants.Contains('MTPG'))">
<ProjectReference Include="..\generator\MTProtoGenerator.csproj" OutputItemType="Analyzer" PrivateAssets="All" /> <ProjectReference Include="..\generator\MTProtoGenerator.csproj" OutputItemType="Analyzer" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
@ -53,5 +53,8 @@
<PackageReference Include="System.Text.Json" Version="6.0.5" /> <PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" /> <PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
</ItemGroup>
</Project> </Project>