mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
various minor stuff
This commit is contained in:
parent
e6f1087c54
commit
0c1785596d
|
|
@ -126,6 +126,7 @@ long chatId = long.Parse(Console.ReadLine());
|
|||
await client.SendMessageAsync(chats.chats[chatId], "Hello, World");
|
||||
```
|
||||
Notes:
|
||||
- This list does not include discussions with other users. For this, you need to use [Messages_GetDialogs](#list-dialogs).
|
||||
- The list returned by Messages_GetAllChats contains the `access_hash` for those chats. Read [FAQ #4](FAQ.MD#access-hash) about this.
|
||||
- If a small private chat group has been migrated to a supergroup, you may find both the old `Chat` and a `Channel` with different IDs in the `chats.chats` result,
|
||||
but the old `Chat` will be marked with flag [deactivated] and should not be used anymore. See [Terminology in ReadMe](README.md#terminology).
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ namespace WTelegram
|
|||
public static string DefaultConfig(string what) => what switch
|
||||
{
|
||||
"session_pathname" => Path.Combine(
|
||||
Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar))),
|
||||
"WTelegram.session"),
|
||||
Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar)))
|
||||
?? AppDomain.CurrentDomain.BaseDirectory, "WTelegram.session"),
|
||||
#if DEBUG
|
||||
"server_address" => "149.154.167.40:443",
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ namespace WTelegram
|
|||
/// <summary>For serializing indented Json with fields included</summary>
|
||||
public static readonly JsonSerializerOptions JsonOptions = new() { IncludeFields = true, WriteIndented = true, IgnoreReadOnlyProperties = true };
|
||||
|
||||
public static V GetOrCreate<K, V>(this Dictionary<K, V> dictionary, K key) where V : new()
|
||||
=> dictionary.TryGetValue(key, out V value) ? value : dictionary[key] = new V();
|
||||
|
||||
private static readonly ConsoleColor[] LogLevelToColor = new[] { ConsoleColor.DarkGray, ConsoleColor.DarkCyan, ConsoleColor.Cyan,
|
||||
ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.DarkBlue };
|
||||
private static void DefaultLogger(int level, string message)
|
||||
|
|
@ -26,6 +23,9 @@ namespace WTelegram
|
|||
Console.ResetColor();
|
||||
}
|
||||
|
||||
public static V GetOrCreate<K, V>(this Dictionary<K, V> dictionary, K key) where V : new()
|
||||
=> dictionary.TryGetValue(key, out V value) ? value : dictionary[key] = new V();
|
||||
|
||||
/// <summary>Get a cryptographic random 64-bit value</summary>
|
||||
public static long RandomLong()
|
||||
{
|
||||
|
|
@ -42,11 +42,11 @@ namespace WTelegram
|
|||
|
||||
internal static byte[] ToBigEndian(ulong value) // variable-size buffer
|
||||
{
|
||||
int i;
|
||||
var temp = value;
|
||||
for (i = 1; (temp >>= 8) != 0; i++) ;
|
||||
int i = 1;
|
||||
for (ulong temp = value; (temp >>= 8) != 0; ) i++;
|
||||
var result = new byte[i];
|
||||
while (--i >= 0) { result[i] = (byte)value; value >>= 8; }
|
||||
for (; --i >= 0; value >>= 8)
|
||||
result[i] = (byte)value;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -257,6 +257,52 @@ namespace TL
|
|||
partial class Updates_DifferenceSlice { public override Updates_State State => intermediate_state; }
|
||||
partial class Updates_DifferenceTooLong { public override Updates_State State => null; }
|
||||
|
||||
partial class UpdatesBase
|
||||
{
|
||||
public abstract Update[] UpdateList { get; }
|
||||
public virtual Dictionary<long, User> Users => NoUsers;
|
||||
public virtual Dictionary<long, ChatBase> Chats => NoChats;
|
||||
private static readonly Dictionary<long, User> NoUsers = new();
|
||||
private static readonly Dictionary<long, ChatBase> NoChats = new();
|
||||
}
|
||||
partial class UpdatesCombined
|
||||
{
|
||||
public override Update[] UpdateList => updates;
|
||||
public override Dictionary<long, User> Users => users;
|
||||
public override Dictionary<long, ChatBase> Chats => chats;
|
||||
}
|
||||
partial class Updates
|
||||
{
|
||||
public override Update[] UpdateList => updates;
|
||||
public override Dictionary<long, User> Users => users;
|
||||
public override Dictionary<long, ChatBase> Chats => chats;
|
||||
}
|
||||
partial class UpdatesTooLong { public override Update[] UpdateList => Array.Empty<Update>(); }
|
||||
partial class UpdateShort { public override Update[] UpdateList => new[] { update }; }
|
||||
partial class UpdateShortSentMessage { public override Update[] UpdateList => Array.Empty<Update>(); }
|
||||
partial class UpdateShortMessage { public override Update[] UpdateList => new[] { new UpdateNewMessage
|
||||
{
|
||||
message = new Message
|
||||
{
|
||||
flags = (Message.Flags)flags | Message.Flags.has_from_id, id = id, date = date,
|
||||
message = message, entities = entities, reply_to = reply_to,
|
||||
from_id = new PeerUser { user_id = user_id },
|
||||
peer_id = new PeerUser { user_id = user_id },
|
||||
fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period
|
||||
}, pts = pts, pts_count = pts_count
|
||||
} }; }
|
||||
partial class UpdateShortChatMessage { public override Update[] UpdateList => new[] { new UpdateNewMessage
|
||||
{
|
||||
message = new Message
|
||||
{
|
||||
flags = (Message.Flags)flags | Message.Flags.has_from_id, id = id, date = date,
|
||||
message = message, entities = entities, reply_to = reply_to,
|
||||
from_id = new PeerUser { user_id = from_id },
|
||||
peer_id = new PeerChat { chat_id = chat_id },
|
||||
fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period
|
||||
}, pts = pts, pts_count = pts_count
|
||||
} }; }
|
||||
|
||||
partial class EncryptedFile
|
||||
{
|
||||
public static implicit operator InputEncryptedFile(EncryptedFile file) => file == null ? null : new InputEncryptedFile { id = file.id, access_hash = file.access_hash };
|
||||
|
|
@ -365,54 +411,10 @@ namespace TL
|
|||
partial class ChannelParticipantBanned { public override long UserID => peer is PeerUser pu ? pu.user_id : 0; }
|
||||
partial class ChannelParticipantLeft { public override long UserID => peer is PeerUser pu ? pu.user_id : 0; }
|
||||
|
||||
partial class UpdatesBase
|
||||
{
|
||||
public abstract Update[] UpdateList { get; }
|
||||
public virtual Dictionary<long, User> Users => NoUsers;
|
||||
public virtual Dictionary<long, ChatBase> Chats => NoChats;
|
||||
private static readonly Dictionary<long, User> NoUsers = new();
|
||||
private static readonly Dictionary<long, ChatBase> NoChats = new();
|
||||
}
|
||||
partial class UpdatesCombined
|
||||
{
|
||||
public override Update[] UpdateList => updates;
|
||||
public override Dictionary<long, User> Users => users;
|
||||
public override Dictionary<long, ChatBase> Chats => chats;
|
||||
}
|
||||
partial class Updates
|
||||
{
|
||||
public override Update[] UpdateList => updates;
|
||||
public override Dictionary<long, User> Users => users;
|
||||
public override Dictionary<long, ChatBase> Chats => chats;
|
||||
}
|
||||
partial class UpdatesTooLong { public override Update[] UpdateList => Array.Empty<Update>(); }
|
||||
partial class UpdateShort { public override Update[] UpdateList => new[] { update }; }
|
||||
partial class UpdateShortSentMessage { public override Update[] UpdateList => Array.Empty<Update>(); }
|
||||
partial class UpdateShortMessage { public override Update[] UpdateList => new[] { new UpdateNewMessage
|
||||
{
|
||||
message = new Message
|
||||
{
|
||||
flags = (Message.Flags)flags | Message.Flags.has_from_id, id = id, date = date,
|
||||
message = message, entities = entities, reply_to = reply_to,
|
||||
from_id = new PeerUser { user_id = user_id },
|
||||
peer_id = new PeerUser { user_id = user_id },
|
||||
fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period
|
||||
}, pts = pts, pts_count = pts_count
|
||||
} }; }
|
||||
partial class UpdateShortChatMessage { public override Update[] UpdateList => new[] { new UpdateNewMessage
|
||||
{
|
||||
message = new Message
|
||||
{
|
||||
flags = (Message.Flags)flags | Message.Flags.has_from_id, id = id, date = date,
|
||||
message = message, entities = entities, reply_to = reply_to,
|
||||
from_id = new PeerUser { user_id = from_id },
|
||||
peer_id = new PeerChat { chat_id = chat_id },
|
||||
fwd_from = fwd_from, via_bot_id = via_bot_id, ttl_period = ttl_period
|
||||
}, pts = pts, pts_count = pts_count
|
||||
} }; }
|
||||
|
||||
partial class Messages_PeerDialogs { public IPeerInfo UserOrChat(DialogBase dialog) => dialog.Peer.UserOrChat(users, chats); }
|
||||
|
||||
partial class WebDocument { public static implicit operator InputWebFileLocation(WebDocument doc) => new() { url = doc.url, access_hash = doc.access_hash }; }
|
||||
|
||||
partial class SecureFile
|
||||
{
|
||||
public static implicit operator InputSecureFile(SecureFile file) => new() { id = file.id, access_hash = file.access_hash };
|
||||
|
|
|
|||
|
|
@ -8298,7 +8298,7 @@ namespace TL
|
|||
}
|
||||
/// <summary>Remote document <para>See <a href="https://corefork.telegram.org/constructor/webDocument"/></para></summary>
|
||||
[TLDef(0x1C570ED1)]
|
||||
public class WebDocument : WebDocumentBase
|
||||
public partial class WebDocument : WebDocumentBase
|
||||
{
|
||||
/// <summary>Document URL</summary>
|
||||
public string url;
|
||||
|
|
|
|||
Loading…
Reference in a new issue