6

我正在尝试使用 c# 中的 TLSharp 库检测在电报上的订阅频道上编辑或删除了哪些消息。

1- 在一个while(true)循环中,我正在获取最新更新。

2-当我删除或编辑一条消息进行测试时,我只收到 TLUpdateChannelTooLong。

3-然后我使用client.GetHistoryAsync函数来获取频道消息,并检查他们的 EditDate。

但我不知道我应该深入了解多少历史,而且我无法轻松找到使用此代码删除的消息。

是否有任何解决方案可以轻松安全地查找已删除/已编辑的消息?

我的部分代码:

state = await client.SendRequestAsync<TLState>(new TLRequestGetState());
while (true)
{
    await Task.Delay(1000);
    var req = new TLRequestGetDifference() { Date = state.Date, Pts = state.Pts, Qts = state.Qts };
    TLDifference diff = null;
    try
    {
        diff = await client.SendRequestAsync<TLAbsDifference>(req) as TLDifference;
    }
    catch (Exception ex)
    {
        HandleThisException(ex);
    }
    //--
    if (diff != null)
    {
        state = await client.SendRequestAsync<TLState>(new TLRequestGetState());
        foreach (var upd in diff.OtherUpdates.OfType<TLUpdateNewChannelMessage>())
        {
            var tm = (upd.Message as TLMessage);
            if (tm == null) { continue; } // ?
            var textMessage = tm.Message;
            if (tm.Media != null)
            {
                if (tm.Media.GetType().ToString() == "TeleSharp.TL.TLMessageMediaPhoto")
                {
                    var tLMessageMediaPhoto = (tm.Media as TLMessageMediaPhoto);
                    textMessage = tLMessageMediaPhoto.Caption;
                }
            }
            try
            {
                var from = (tm.ToId as TLPeerChannel).ChannelId;
                long replyTo = tm.ReplyToMsgId == null ? 0 : (long)tm.ReplyToMsgId;
                await AnalyzeNewMessage( ... );
            }
            catch (Exception exParsing)
            {
                HandleThisException(exParsing);
            }
        }
         // Checking Edited/Deleted Messages
        foreach(var upLong in diff.OtherUpdates.OfType<TLUpdateChannelTooLong>())
        {
            TLChannel theChat = null;
            foreach(var chat in diff.Chats.OfType<TLChannel>())
            {
                if(chat.Id == upLong.ChannelId) { theChat = chat;  break; }
            }
            if (theChat != null)
            {
                var x = await client.GetHistoryAsync(
                    new TLInputPeerChannel { ChannelId = theChat.Id, AccessHash = (long)theChat.AccessHash },
                    0,-1,2
                    ); // checking only 2 last messages!
                var ChMsgs = x as TLChannelMessages;
                foreach (var msg in ChMsgs.Messages.OfType<TLMessage>())
                {
                    if(msg.EditDate != null)
                    {
                        var txt = msg.Message;
                        if (msg.Media != null)
                        {
                            if (msg.Media.GetType().ToString() == "TeleSharp.TL.TLMessageMediaPhoto")
                            {
                                txt = (msg.Media as TLMessageMediaPhoto).Caption;
                            }
                        }
                        await AnalyzeEditedMessage( ... );
                    }
                }
            }
        }
    }
}
4

0 回答 0