From f3f1b37b85eaf4cc55a888198b4a147f11f01312 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Sat, 24 Sep 2022 15:34:31 +0200 Subject: [PATCH] _saltChangeCounter is now in seconds --- EXAMPLES.md | 25 +++++++++++++++++++++---- src/Client.cs | 6 +++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index 1415cd4..1a62b18 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -417,17 +417,34 @@ await client.Account_UpdatePasswordSettings(password, new Account_PasswordInputS -### Send a message reaction on pinned messages -This code fetches the available reactions in a given chat, and sends the first reaction emoji (usually 👍) on the last 2 pinned messages: + +### Fun with custom emojies and reactions on pinned messages ```csharp +// • Fetch all available standard emoji reactions +var all_emoji = await client.Messages_GetAvailableReactions(); + var chats = await client.Messages_GetAllChats(); var chat = chats.chats[1234567890]; // the chat we want + +// • Check reactions available in this chat var full = await client.GetFullChat(chat); -var reaction = full.full_chat.AvailableReactions[0]; // choose the first available reaction emoji +Reaction reaction = full.full_chat.AvailableReactions switch +{ + ChatReactionsSome some => some.reactions[0],// only some reactions are allowed => pick the first + ChatReactionsAll all => // all reactions are allowed in this chat + all.flags.HasFlag(ChatReactionsAll.Flags.allow_custom) && client.User.flags.HasFlag(TL.User.Flags.premium) + ? new ReactionCustomEmoji { document_id = 5190875290439525089 } // we can use custom emoji reactions here + : new ReactionEmoji { emoticon = all_emoji.reactions[0].reaction }, // else, pick the first standard emoji reaction + _ => null // reactions are not allowed in this chat +}; +if (reaction == null) return; + +// • Send the selected reaction on the last 2 pinned messages var messages = await client.Messages_Search(chat, limit: 2); foreach (var msg in messages.Messages) - await client.Messages_SendReaction(chat, msg.ID, reaction); + await client.Messages_SendReaction(chat, msg.ID, reaction: new[] { reaction }); ``` +*Note: you can find custom emojies document ID via API methods like [Messages_GetFeaturedEmojiStickers](https://corefork.telegram.org/method/messages.getFeaturedEmojiStickers). Access hash is not required* ### Store session data to database or elsewhere, instead of files diff --git a/src/Client.cs b/src/Client.cs index 5548888..550dcb8 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -428,8 +428,8 @@ namespace WTelegram { Helpers.Log(2, $"{_dcSession.DcID}>Server salt has changed: {_dcSession.Salt:X} -> {serverSalt:X}"); _dcSession.Salt = serverSalt; - _saltChangeCounter += 20; // counter is decreased by KeepAlive every minute (we have margin of 10) - if (_saltChangeCounter >= 30) + _saltChangeCounter += 1200; // counter is decreased by KeepAlive (we have margin of 10 min) + if (_saltChangeCounter >= 1800) throw new ApplicationException("Server salt changed too often! Security issue?"); } if ((seqno & 1) != 0) lock (_msgsToAck) _msgsToAck.Add(msgId); @@ -862,7 +862,7 @@ namespace WTelegram while (!ct.IsCancellationRequested) { await Task.Delay(Math.Abs(PingInterval) * 1000, ct); - if (_saltChangeCounter > 0) --_saltChangeCounter; + if (_saltChangeCounter > 0) _saltChangeCounter -= Math.Abs(PingInterval); if (PingInterval <= 0) await this.Ping(ping_id++); else // see https://core.telegram.org/api/optimisation#grouping-updates