Esempio n. 1
0
        public static void LoadAndFixLogs(long groupId)
        {
            if (File.Exists(ParametersClass.logsPath))
            {
                ParametersClass.logs = IOClass.ReadLogsJson();
                List <Logs> UpdateLogs = new List <Logs>();

                PostInfo[] posts = VkApiClass.GetAllPostponed(groupId).ToArray();

                for (int i = 0; i < ParametersClass.logs.Count; i++)
                {
                    for (int p = 0; p < posts.Length; p++)
                    {
                        if (ParametersClass.logs[i].groupId == posts[p].groupId)
                        {
                            if (ParametersClass.logs[i].postId == posts[p].postId)
                            {
                                UpdateLogs.Add(ParametersClass.logs[i]);
                            }
                        }
                    }
                }
                ParametersClass.logs = UpdateLogs;
            }
        }
Esempio n. 2
0
        public void Post(bool force = false) //Создание поста
        {
            int   postMultiply = 0;
            int   wallid       = 0;
            ulong CoutPosts    = 0;
            int   FileCount    = 0;

            postMultiply = groupItem.ImageInPost;
            wallid       = -groupItem.WallId;
            FileCount    = Directory.GetFiles(groupItem.ForPublic).Length;

            var vkpost = ParametersClass.vkapi.Wall.Get(new WallGetParams
            {
                OwnerId = wallid,
                Filter  = WallFilter.Postponed,
            });

            if (!ParametersClass.AutostartValue || force)
            {
                CoutPosts = (ulong)CoutPost;
            }
            else
            {
                CoutPosts = (ulong)groupItem.MaxPostInAuto;
            }

            if (vkpost.TotalCount + (ulong)(CoutPost * groupItem.ImageInPost) > 150)
            {
                CoutPosts = 150 - vkpost.TotalCount;
            }

            if (CoutPosts > 0)
            {
                if ((int)CoutPosts * postMultiply > FileCount)
                {
                    MessageBox.Show("В папке всего: " + FileCount + ", а не " + (int)CoutPosts * postMultiply + " файла.");
                }
                else
                {
                    if ((CoutPosts + vkpost.TotalCount) <= 150)
                    {
                        for (int i = 0; i < (int)CoutPosts; i++) //Сколько будет постов
                        {
                            time.Time();

                            DateTime datenow = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 00);
                            DateTime date    = new DateTime(time.year, time.month, time.day, time.hour, time.minute, 00);

                            if (date < datenow)
                            {
                                MessageBox.Show("Мы не можем отправлять посты в прошлое.");
                            }

                            file = IOClass.GetFile(groupItem.ForPublic);
                            long ownerid = ParametersClass.vkapi.Users.Get(new long[] { })[0].Id;
                            try
                            {
                                var get = ParametersClass.vkapi.Wall.Post(new WallPostParams //Создание поста
                                {
                                    OwnerId     = -groupItem.WallId,
                                    FromGroup   = true,
                                    Message     = groupItem.Hesh != null ? groupItem.Hesh : "",
                                    Attachments = VkApiClass.Posts(postMultiply, ownerid, groupItem.WallId, file.ToArray()).getIEMA(),
                                    PublishDate = new DateTime(time.year, time.month, time.day, time.hour, time.minute, 0)
                                });

                                for (int f = 0; f < postMultiply; f++)
                                {
                                    string new_path = groupItem.Public + @"\" + DateTime.Now.Hour + "." + DateTime.Now.Minute + "." + DateTime.Now.Second + "_" + DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year + "_" + "f" + f + "_" + (Path.GetFileName(file[f]).Split('_').Length > 1 ? Path.GetFileName(file[f]).Split('_')[Path.GetFileName(file[f]).Split('_').Length - 1] : Path.GetFileName(file[f]));
                                    File.Move(file[f], new_path); //Перемещение файла в папку после загрузки
                                    IOClass.SaveGroupJson(this);  //Сохраняем переменные json

                                    ParametersClass.logs.Add(new Logs {
                                        file = new_path, groupId = groupItem.WallId, postId = get
                                    });
                                    IOClass.SaveLogsJson(ParametersClass.logs);

                                    DesuBot.progressBarPlus(Program.desuBot);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex is VkNet.Exception.PostLimitException)
                                {
                                    MessageBox.Show(date + " : Возможно в данное время уже запланирован пост или вы достигли лимита 150 постов в отложенных записях. error: P1. \n" + ex.Message);
                                }
                                else if (ex is VkNet.Exception.CaptchaNeededException cap)
                                {
                                    csid       = cap.Sid;
                                    captchaUrl = cap.Img.AbsoluteUri;
                                    using (Captcha captcha = new Captcha())
                                    {
                                        captcha.Show();

                                        if (captcha.ShowDialog() == DialogResult.OK)
                                        {
                                            captchaKey = captcha.TheValue;
                                        }
                                    }
                                    System.Windows.Forms.Application.Exit();
                                }
                                else
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("В отложенные записи нельзя добавить больше 150 постов.");
                    }
                }
            }
        }