· 6 years ago · Jan 22, 2020, 07:26 PM
1using System;
2using System.Linq;
3using System.IO;
4using System.Threading;
5using System.Threading.Tasks;
6using VkNet;
7using VkNet.Enums.SafetyEnums;
8using VkNet.Exception;
9using VkNet.Model;
10using VkNet.Model.Keyboard;
11using VkNet.Model.RequestParams;
12
13namespace ConsoleApp19
14{
15 class Program
16 {
17 #region Info
18 private static string MyAppToken = "c252b43a65233177e191548b0ad4ce746ee8e22b6ea2e5ee2b482c9a84a8805928997783bedf6098fb936";
19 private static ulong MyGroupId = 184265009;
20 #endregion
21
22 static void Main(string[] args)
23 {
24 var api = new VkApi();
25 api.Authorize(new ApiAuthParams { AccessToken = MyAppToken });
26 var random = new Random();
27 var server = api.Groups.GetLongPollServer(MyGroupId);
28
29 KeyboardBuilder key = new KeyboardBuilder();
30 key.AddButton("Тест", "1", KeyboardButtonColor.Primary, "1");
31 MessageKeyboard keyboard = key.Build();
32
33 Console.WriteLine("Цикл запущен");
34 while (true)
35 {
36 try
37 {
38 var poll = api.Groups.GetBotsLongPollHistory(
39 new BotsLongPollHistoryParams
40 { Server = server.Server, Ts = server.Ts, Key = server.Key, Wait = 1 });
41 if (poll?.Updates == null) continue;
42 server.Ts = poll.Ts;
43 foreach (var update in poll.Updates)
44 {
45 if (update.Type == GroupUpdateType.MessageNew)
46 { var p = api.Users.Get(new long[] {
47 Convert.ToInt32(update.Message.FromId)
48 }).FirstOrDefault();
49 string FNS = $"[id{p.Id}|{p.FirstName}]";
50 }
51 }
52 }
53 }
54 catch (LongPollException exception)
55 {
56 if (exception is LongPollOutdateException outdateException)
57 server.Ts = outdateException.Ts;
58 else
59 {
60 server = api.Groups.GetLongPollServer(MyGroupId);
61 }
62 }
63 catch (Exception e)
64 {
65 Console.WriteLine(e);
66 }
67 }
68
69 }
70}