public static KeyValuePair <Photo, string> GetNextPictureAndMessageForDialog_Ad(VkApi vk, DialogSettings dialog, Album album = null) { Photo photo = null; string message = null; if (AdPicturesSettings.IsNeedAd(dialog)) { photo = AdPicturesSettings.GetNextPicAndCommit(vk); if (photo != null) { message = photo.Text; } } if (photo == null) { photo = album == null?GetRandomPicture(vk) : GetRandomPicture(vk, album); message = GetNextMessageForDialog_Ad(dialog, false); } dialog.IncrementImgsCountAndCommit(); return(new KeyValuePair <Photo, string>(photo, message)); }
static void Main(string[] args) { //authorization var vk = new VkApi(new VkCaptchaSolver.VkCaptchaSolver()); vk.Authorize(VkUtils.GetCredentials()); //dialogs loading DialogSettings.NeedApi = () => vk; DialogSettings.NeedMessage = (id) => VkUtils.GetLastMessage(vk, id); //reloader EroRepository.Reload(); RandomMessages.Reload(); AdTextSettings.Reload(vk); AdPicturesSettings.Reload(vk); var reloaderThread = new Thread(() => { while (true) { lock (vk) { EroRepository.Reload(); RandomMessages.Reload(); AdTextSettings.Reload(vk); AdPicturesSettings.Reload(vk); } //Thread.Sleep(10000); Thread.Sleep(1000 * 60 * 60); } }); reloaderThread.Start(); //initialize dialogs settings DialogSettings.LoadSessions(); //main actions while (true) { try { lock (vk) { var newMessages = vk.Messages.GetDialogs(new MessagesDialogsGetParams() { Offset = 0, Count = 200, Unread = true }); foreach (var message in newMessages.Messages) { if (!VkNet.VkUtils.IsChat(message) || CommandUtils.StartCommand.IsIt(message.Body)) { CommandUtils.StartCommand.Execute(vk, message, message.Body); } } } VkNet.VkUtils.TechnicalSleepForVk(); } catch (Exception e) { if (!e.Message.Contains("Flood")) { Log.Write(e); Console.WriteLine(e.Message); } else if (VkUtils.IsAccessTokenError(e)) { vk.RefreshToken(); } } } }