Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using TeleSharp.TL;
- using TeleSharp.TL.Messages;
- using TLSharp.Core;
- //using other standard...
- //code for authorization etc. is skipped
- int VKFID = 1175259547;
- int offset = 0;
- int n = 1;
- StringBuilder sb = new StringBuilder();
- TelegramClient client = new TelegramClient(<key>, <hash>);
- TLUser user;
- private DateTime ConvertFromUnixTimestamp(double timestamp)
- {
- DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
- return origin.AddSeconds(timestamp);
- }
- private async void button3_Click(object sender, EventArgs e)
- {
- sb.Append("#\tDate\tTime\tMID\tTUID\tText" + Environment.NewLine);
- TLDialogsSlice dialogs = (TLDialogsSlice)await client.GetUserDialogsAsync();
- TLChannel chat = dialogs.Chats.Where(c => c.GetType() == typeof(TLChannel)).Cast<TLChannel>().FirstOrDefault(c => c.Id == VKFID);
- TLInputPeerChannel inputPeer = new TLInputPeerChannel() { ChannelId = chat.Id, AccessHash = (long)chat.AccessHash };
- while (true)
- {
- try
- {
- TLChannelMessages res = await client.SendRequestAsync<TLChannelMessages>
- (new TLRequestGetHistory() { Peer = inputPeer, Limit = 1000, AddOffset = offset, OffsetId = 0 });
- var msgs = res.Messages;
- if (res.Count > offset)
- {
- offset += msgs.Count;
- foreach (TLAbsMessage msg in msgs)
- {
- if (msg is TLMessage)
- {
- TLMessage message = msg as TLMessage;
- sb.Append(n.ToString() + "\t" +
- ConvertFromUnixTimestamp(message.Date).ToLocalTime().ToString("dd'.'MM'.'yyyy") + "\t" +
- ConvertFromUnixTimestamp(message.Date).ToLocalTime().ToString("HH':'mm':'ss") + "\t" +
- message.Id + "\t" + message.FromId + "\t" + message.Message + Environment.NewLine);
- }
- if (msg is TLMessageService)
- continue;
- n++;
- }
- //Thread.Sleep(22000); //чтобы обойти TelegramFloodException
- }
- else
- break;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- break;
- }
- finally
- {
- await Task.Delay(22000);
- }
- }
- textBox2.Text = sb.ToString();
- MessageBox.Show("Done");
- }
Add Comment
Please, Sign In to add comment