public static DialogSettings GetSession(VkApi vk, Message message) { var id = VkUtils.GetId(message); if (!Sessions.ContainsKey(id)) { Sessions.Add(id, new DialogSettings(id, vk, message)); } return(Sessions[id]); }
public static void Reload(VkApi vk) { var hData = HierarchicalObject.FromFile(StringConstants.AdPicturesSettingsFileName); Album = new Album() { Link = hData[0] }; Interval = hData[1]; ImagePosition = hData[2]; IsAllow = hData[3]; VkUtils.PrepareAlbumSize(vk, Album); }
public static Photo GetNextPicAndCommit(VkApi vk) { if (Album.PhotosCount.Value == 0) { return(null); } var index = ImagePosition; ImagePosition++; if (ImagePosition >= Album.PhotosCount.Value) { ImagePosition = 0; } Save(); return(VkUtils.GetPicture(vk, Album, index, false)); }
public void StartIntervalDispatching(bool sendMessage, bool save) { if (IntervalDispatcher != null) { StopIntervalDispatching(false, false); } if (IntervalDispatcher == null) { IntervalDispatcher = new Thread(() => { while (true) { try { lock (Vk) VkNet.VkUtils.SendImages(Vk, Message, VkUtils.GetRandomPictures(Vk, 5), VkUtils.GetNextMessageForDialog_Ad(this, true)); Thread.Sleep((int)(1000 * 60 * 60 * IntervalDispatchingValue)); } catch (Exception e) { if (!(e is ThreadAbortException)) { Log.Write(e); Console.WriteLine("Dialog " + this.Id + " error. Stopped."); break; } } } }); IsIntervalDispatcherStarted = true; IntervalDispatcher.Start(); if (sendMessage) { lock (Vk) VkNet.VkUtils.SendMessage(Vk, Message, StringConstants.Dialog_IntervalOkResponse.Set(IntervalDispatchingValue)); } if (save) { SaveToFile(); } } }
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(); } } } }