public static void Rooms(string[] args, AppData appData) { var vk = new VkApi(); vk.Authorize(appData.AccessToken); var dialogs = vk.Messages.GetDialogs(new MessagesDialogsGetParams() { Count = 200, }); if (dialogs.TotalCount == 0) { return; } var msgs = ( from m in dialogs.Messages where m.ChatId != null where m.ChatActiveIds != null && m.ChatActiveIds.Count() >= 2 select m ).ToList(); CliUtils.PresentField("Rooms", msgs.Count, ConsoleColor.Magenta); foreach (var m in msgs) { Console.WriteLine(); CliUtils.PresentDialog(m, appData); } }
public static void Important(string[] args, AppData appData) { uint n = 0; new OptionSet() { { "n=", _ => n = Convert.ToUInt32(_) } }.Parse(args); CliUtils.Validate(n > 0, AppError.ErrorCode.ArgumentParseError, $"should pass the number of messages to retrieve (-n=..)"); var vk = new VkApi(); vk.Authorize(appData.AccessToken); var messages = vk.Messages.Get(new MessagesGetParams() { Count = n, Filters = MessagesFilter.Important, }).Messages; CliUtils.PresentField("Messages", messages.Count); foreach (var m in messages) { Console.WriteLine(); CliUtils.PresentMessage(m, appData); } }
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); }
public static void Friend(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); User user; ProfileFields fields = ProfileFields.Nickname | ProfileFields.FirstName | ProfileFields.LastName | ProfileFields.Sex | ProfileFields.Status | ProfileFields.BirthDate | ProfileFields.Relation | ProfileFields.RelationPartner; try { user = vk.Users.Get(id, fields | ProfileFields.Online); } catch (Exception e) { if (e.Message == "Can not convert String to Int64.") { Thread.Sleep(400); user = vk.Users.Get(id, fields); } else { throw; } } CliUtils.PresentField("User name", $"{user.FirstName} {user.LastName}"); CliUtils.PresentField("Online", user.Online.HasValue ? (user.Online.Value ? "online" : "offline") : "unknown", user.Online.HasValue ? (user.Online.Value ? ConsoleColor.DarkGreen : ConsoleColor.DarkBlue) : ConsoleColor.Gray); CliUtils.PresentField("VK ID", user.ScreenName); CliUtils.PresentField("Status", user.Status); CliUtils.PresentField("Sex", user.Sex); CliUtils.PresentField("Birth date", MiscUtils.FormatDate(user.BirthDate)); CliUtils.PresentField("Home town", user.HomeTown); CliUtils.PresentField("Relation", user.Relation); CliUtils.PresentField("Relation partner", user.RelationPartner != null ? $"{user.RelationPartner.FirstName} {user.RelationPartner.LastName}" : null); }
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))); }
public static void Profile(string[] args, AppData appData) { var vk = new VkApi(); vk.Authorize(appData.AccessToken); var profile = vk.Account.GetProfileInfo(); CliUtils.PresentField("User name", $"{profile.FirstName} {profile.LastName}"); CliUtils.PresentField("VK ID", profile.ScreenName); CliUtils.PresentField("Status", profile.Status); CliUtils.PresentField("Sex", profile.Sex.HasValue ? profile.Sex.Value.ToString() : null); CliUtils.PresentField("Birth date", MiscUtils.FormatDate(profile.BirthDate)); CliUtils.PresentField("Home town", profile.HomeTown); CliUtils.PresentField("Relation", profile.Relation.HasValue ? profile.Relation.Value.ToString() : null); CliUtils.PresentField("Relation partner", profile.RelationPartner != null ? $"{profile.RelationPartner.FirstName} {profile.RelationPartner.LastName}" : null); }
public static void Recv(string[] args, AppData appData) { bool quiet = false; bool all = false; uint n = 200; bool reverse = false; bool room = false; string[] opts = new OptionSet() { { "q|quiet", _ => quiet = true }, { "a=|all=", _ => { all = true; n = Convert.ToUInt32(_); } }, { "r|reverse", _ => reverse = true }, { "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, all ? (int?)n : null, reverse, quiet); if (msgs.Count > 0) { CliUtils.PresentField("Messages", msgs.Count, ConsoleColor.Magenta); CliUtils.PresentField("Quiet", quiet); foreach (var m in msgs) { Console.WriteLine(); CliUtils.PresentMessage(m, appData); } } }
public static void State(string[] args, AppData appData) { bool accessToken = false; new OptionSet() { { "access-token", _ => accessToken = true }, }.Parse(args); CliUtils.PresentField("State", appData.Authorized ? "authorized" : "not authorized", appData.Authorized ? ConsoleColor.DarkGreen : ConsoleColor.DarkRed); if (accessToken) { CliUtils.PresentField("Access token", appData.AccessToken); } CliUtils.PresentField("User name", appData.FullName); }
public static void Check(string[] args, AppData appData) { bool all = false; new OptionSet() { { "a|all", _ => all = true } }.Parse(args); var vk = new VkApi(); vk.Authorize(appData.AccessToken); var dialogs = vk.Messages.GetDialogs(new MessagesDialogsGetParams() { Count = 200, Unread = !all, }); var msgs = ( from m in dialogs.Messages where !all || m.ChatId == null select m ).ToList(); if (msgs.Count == 0) { return; } CliUtils.PresentField("Dialogs", msgs.Count, ConsoleColor.Magenta); Console.WriteLine(); foreach (var m in msgs) { Console.WriteLine(); CliUtils.PresentDialog(m, appData); } }