Пример #1
0
 public void Connect()
 {
     InitToken();
     apiRequests.Token = () => Token;
     apiRequests.Ver   = ver;
     interacter.WriteLine($"Welcome, {usersManager.GetNameById(user)}!");
 }
Пример #2
0
        public bool GetMessages(out List <IMessage> messages)
        {
            var result = apiRequests.SendRequest(VkApiCommands.GetMessages,
                                                 new Dictionary <string, string>
            {
                { "last_message_id", lastMessageId.ToString() }
            });
            var content = JObject.Parse(result);

            messages = new List <IMessage>(content["items"]
                                           .Select(x =>
            {
                lastMessageId = Math.Max(lastMessageId, int.Parse(x.SelectToken("id").ToString()));
                return(x);
            })
                                           .Where(x => x.SelectToken("chat_id")?.ToString() == chat)
                                           .Select(x => new Message(
                                                       x.SelectToken("body").ToString(),
                                                       UsersManager.GetNameById(x.SelectToken("user_id").ToString())
                                                       ))
                                           .Reverse()
                                           .ToList());
            return(messages.Count != 0);
        }