Exemple #1
0
        public static void Chat(string[] args, AppData appData)
        {
            int  p    = -1;
            bool room = false;

            string[] opts = new OptionSet()
            {
                { "p=|prev=", _ => p = Convert.ToInt32(_) },
                { "R|room", _ => room = true },
            }.Parse(args).ToArray();

            long id = appData.GetId(opts.GetArg(1));

            bool?roomAbbr = appData.IsRoom(opts.GetArg(1));

            if (roomAbbr.HasValue && roomAbbr.Value != room)
            {
                Console.WriteLine($"Warning: setting -R|--room flag to {roomAbbr.Value} according to abbreviations data.");
                room = roomAbbr.Value;
            }

            var vk = new VkApi();

            vk.Authorize(appData.AccessToken);

            var msgs = MiscUtils.RecvMessages(vk, id, p >= 0 ? (int?)p : null, false, false);

            Console.WriteLine("Entering chat mode. Press enter at any time to begin typing.");
            if (!room)
            {
                CliUtils.PresentField("Buddy", appData.GetAbbr(id));
            }
            else
            {
                CliUtils.PresentField("Room", appData.GetAbbr(id));
            }

            if (p != 0)
            {
                foreach (var m in msgs)
                {
                    Console.WriteLine();
                    CliUtils.PresentMessage(m, appData);
                }
            }

            CliUtils.LaunchChatMode(vk, appData, id, room);
        }
Exemple #2
0
        public static void PresentDialog(Message msg, AppData appData)
        {
            string room = msg.ChatId.HasValue ? appData.GetAbbr(msg.ChatId.Value) : null;
            string abbr = appData.GetAbbr(msg.UserId ?? 0);
            string date = MiscUtils.FormatDate(msg.Date);
            string body = msg.Body ?? "";

            if (room != null)
            {
                PresentField("Room", room, ConsoleColor.Yellow);
                PresentField("Last message", $"{date}, by {abbr}");
            }
            else
            {
                PresentField("Buddy", abbr, ConsoleColor.Yellow);
                PresentField("Last message", date);
            }

            Console.WriteLine(body);
        }
Exemple #3
0
        public static void PresentMessage(Message msg, AppData appData)
        {
            if (msg.ChatId.HasValue)
            {
                PresentField("Room", appData.GetAbbr(msg.ChatId.Value));
            }

            string abbr = appData.GetAbbr(msg.UserId ?? 0);
            string date = MiscUtils.FormatDate(msg.Date);
            string body = msg.Body ?? "";

            if (msg.Type == MessageType.Sended)
            {
                Console.WriteLine(date);
                Console.Write("> ");
                WriteLineColor(body, ConsoleColor.DarkGreen);
            }
            else
            {
                Console.WriteLine($"{date}  {abbr}");
                WriteLineColor(body, ConsoleColor.Cyan);
            }
        }
Exemple #4
0
        public static void Room(string[] args, AppData appData)
        {
            string[] opts = new OptionSet()
            {
            }.Parse(args).ToArray();

            long id = appData.GetId(opts.GetArg(1));

            var vk = new VkApi();

            vk.Authorize(appData.AccessToken);

            var res = vk.Messages.GetChat(id);

            CliUtils.PresentField("Title", res.Title);
            CliUtils.PresentField("Admin", appData.GetAbbr(res.AdminId ?? 0));
            CliUtils.PresentField("Users", String.Join(" ", from i in res.Users select appData.GetAbbr(i)));
        }
Exemple #5
0
        public static void Friends(string[] args, AppData appData)
        {
            bool onlyOnline = false;
            bool sort       = false;

            Action <UserCollection> fullPF = (friends) => {
                if (friends.Count == 0)
                {
                    Console.WriteLine("You have no friends :(");
                }

                var table = new Table();

                foreach (var friend in friends)
                {
                    table.Add(
                        appData.GetAbbr(friend.Id),
                        friend.Online.HasValue ? (friend.Online.Value ? "online" : "") : "",
                        $"{friend.FirstName} {friend.LastName}",
                        MiscUtils.FormatDate(friend.BirthDate)
                        );
                }

                if (sort)
                {
                    table.SortBy(2);
                }

                table.Display();
            };

            Action <UserCollection> idsPF = (friends) => {
                bool first = true;
                foreach (var friend in friends)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                    Console.Write(appData.GetAbbr(friend.Id));
                }
                Console.WriteLine();
            };

            Action <UserCollection> act = fullPF;

            new OptionSet()
            {
                { "i|ids", _ => act = idsPF },
                { "o|online", _ => onlyOnline = true },
                { "s|sort", _ => sort = true }
            }.Parse(args);

            var vk = new VkApi();

            vk.Authorize(appData.AccessToken);

            var res = vk.Friends.Get(new FriendsGetParams()
            {
                Count  = null,
                Fields =
                    ProfileFields.Nickname
                    | ProfileFields.FirstName
                    | ProfileFields.LastName
                    | ProfileFields.BirthDate
            });

            if (onlyOnline)
            {
                var res2 = (
                    from f in res
                    where f.Online.HasValue
                    where f.Online.Value
                    select f
                    ).ToArray();

                res = new UserCollection(res2);
            }

            act(res);
        }