public bool Execute(BotUser sender, Command command, string Label, string[] parameters, Message VkMessage)
 {
     if (sender.HasPermission(command.Permission))
     {
         if (parameters.Length <= 0)
         {
             return(HomeWorkExecutorHelper.GetAllHomeWork(sender));
         }
         if (parameters.Length < 1)
         {
             Api.SendMessage("Вы не вверли необходимый параметер(дату домашнего задания)", sender.UserId);
             return(false);
         }
         var datestr = parameters[0];
         var date    = DateTime.ParseExact(datestr, Settings.Path.DateFormat, null);
         HomeWorkHelper.GetJsonItems();
         var res = HomeWorkHelper.GetJsonItemByDate(date);
         if (res == null)
         {
             Api.SendMessage(ExecutorText.DeleteHomeWorkExecutor.ErrorDelete, sender.UserId);
             return(false);
         }
         HomeWorkHelper.Remove(res);
         HomeWorkHelper.UpdateJson();
         HomeWorkHelper.ClearData();
         Api.SendMessage(ExecutorText.DeleteHomeWorkExecutor.SuccessDelete, sender.UserId);
         return(true);
     }
     Api.SendMessage(ExecutorText.CantPermission, sender.UserId);
     return(false);
 }
Esempio n. 2
0
 private bool SendHomeWork(string datestr,BotUser sender)
 {
     try
     {
         HomeWorkHelper.GetJsonItems();
         if (HomeWorkHelper.HomeWorks == null)
         {
             Api.SendMessage(ExecutorText.CheckHomeWorkExecutor.HomeWorkNull, sender.UserId);
             return false;
         }
         var date = DateTime.ParseExact(datestr, Settings.Path.DateFormat, null);
         var res = HomeWorkHelper.GetJsonItemByDate(date);
         if (res == null)
         {
             Api.SendMessage(ExecutorText.CheckHomeWorkExecutor.HomeWorkDoesntAdded, sender.UserId);
             return false;
         }
         Api.SendMessage($"Дз на {res.Date.DayOfWeek.ToString().ToUpper()}({res.Date.ToShortDateString()}): \n\n"+res.Text, sender.UserId);
         if (res.Attachments != null&&res.Attachments.Count>0)
         {
             Api.SendMessage("", sender.UserId, res.Attachments.ToList<MediaAttachment>());
         }
         HomeWorkHelper.ClearData();
         return true;
     }
     catch (Exception ex)
     {
         Api.SendMessage(ExecutorText.ExepctionText, sender.UserId);
         return false;
     }
 }
Esempio n. 3
0
        private static void Monitoring_Tick(object sender, EventArgs e)
        {
            var d = new Distribution(bot.helper);
            var homeworkhelper = new HomeWorkHelper(new ErrorReporter((ex) => { Console.WriteLine(ex.Message); }));

            homeworkhelper.GetJsonItems();
            var homework = homeworkhelper.GetJsonItemByDate(DateTime.Now);

            d.SendAllSubscribers(homework.Text);
            homeworkhelper.ClearData();
        }
Esempio n. 4
0
 public bool AddHomeWork(JsonItem homework, BotUser sender)
 {
     try
     {
         if (homework.Date.DayOfWeek == DayOfWeek.Saturday || homework.Date.DayOfWeek == DayOfWeek.Sunday)
         {
             Api.SendMessage($"Вы не можете установить домашнее задание на выходные {homework.Date.ToShortDateString()}, {homework.Date.DayOfWeek})", sender.UserId);
             return(false);
         }
         HomeWorkHelper.GetJsonItems();
         HomeWorkHelper.Append(homework);
         HomeWorkHelper.UpdateJson();
         HomeWorkHelper.ClearData();
         Api.SendMessage($"Домашнее задание успешно добавлено на дату {homework.Date.ToShortDateString()} ", sender.UserId);
         return(true);
     }
     catch (Exception ex)
     {
         Api.SendMessage(ExecutorText.ExepctionText, sender.UserId);
         return(false);
     }
 }
 public bool Execute(BotUser sender, Command command, string Label, string[] parameters, Message VkMessage)
 {
     if (sender.HasPermission(command.Permission))
     {
         if (parameters.Length <= 0)
         {
             return(HomeWorkExecutorHelper.GetAllHomeWork(sender));
         }
         if (parameters.Length < 1)
         {
             Api.SendMessage("Вы не вверли необходимый параметер(дату домашнего задания)", sender.UserId);
             return(false);
         }
         if (parameters.Length < 2)
         {
             Api.SendMessage("Вы не вверли необходимый параметер(текст домашнего задания)", sender.UserId);
             return(false);
         }
         var datestr = parameters[0];
         var text    = parameters[1];
         var date    = DateTime.ParseExact(datestr, Settings.Path.DateFormat, null);
         HomeWorkHelper.GetJsonItems();
         var res = HomeWorkHelper.GetJsonItemByDate(date);
         if (res != null)
         {
             HomeWorkHelper.Remove(res);
             HomeWorkHelper.UpdateJson();
         }
         var list = new List <Photo>();
         foreach (var a in VkMessage.Attachments)
         {
             if (a.Instance is Photo)
             {
                 list.Add((Photo)a.Instance);
             }
         }
         HomeWorkHelper.ClearData();
         var homework = new JsonItem(text, sender.UserId, date, VkMessage.Date.Value, list);
         return(HomeWorkExecutorHelper.AddHomeWork(homework, sender));
     }
     Api.SendMessage(ExecutorText.CantPermission, sender.UserId);
     return(false);
 }
        public bool Execute(BotUser sender, Command command, string Label, string[] parameters, Message VkMessage)
        {
            if (sender.HasPermission(command.Permission))
            {
                if (parameters.Length < 1)
                {
                    Api.SendMessage(ExecutorText.AddHomeWorkExecutor.ParamTextError, sender.UserId);
                    return(false);
                }
                if (parameters.Length < 2)
                {
                    Api.SendMessage(ExecutorText.AddHomeWorkExecutor.ParamDateError, sender.UserId);
                    return(false);
                }
                var date         = parameters[1];
                var text         = parameters[0];
                var homeworkdate = DateTime.ParseExact(date, Settings.Path.DateFormat, null);
                HomeWorkHelper.GetJsonItems();
                var h = HomeWorkHelper.GetJsonItemByDate(homeworkdate);
                if (h != null)
                {
                    Api.SendMessage(ExecutorText.AddHomeWorkExecutor.CantAddedTwix, sender.UserId);
                    return(false);
                }
                var list = new List <Photo>();
                foreach (var a in VkMessage.Attachments)
                {
                    if (a.Instance is Photo)
                    {
                        list.Add((Photo)a.Instance);
                    }
                }
                HomeWorkHelper.ClearData();
                var homework = new JsonItem(text, sender.UserId, homeworkdate, VkMessage.Date.Value, list);
                return(HomeWorkExecutorHelper.AddHomeWork(homework, sender));
            }

            Api.SendMessage(ExecutorText.CantPermission, sender.UserId);
            return(false);
        }