Ejemplo n.º 1
0
 public static void SyncNightScheduleToDatabase()
 {
     foreach (Models.Group.NightSchedule nightSchedule in CacheData.NightSchedules.Values)
     {
         nsl.Update(nightSchedule, -2);
     }
 }
Ejemplo n.º 2
0
        private void SetOpenTime(Message message, string time)
        {
            string   groupId = CacheData.Groups[message.Chat.Id].GroupId;
            DateTime endTime = new DateTime(
                DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day,
                Convert.ToInt32(time.Split(":")[0]), Convert.ToInt32(time.Split(":")[1]), 0);

            if (endTime < DateTime.UtcNow)
            {
                endTime = endTime.AddDays(1);
            }
            if (CacheData.NightSchedules.ContainsKey(groupId))
            {
                if (CacheData.NightSchedules[groupId].UtcStartDate.HasValue)
                {
                    if (CacheData.NightSchedules[groupId].UtcStartDate.Value.Hour == endTime.Hour)
                    {
                        MessageQueueManager.EnqueueMessage(
                            new Models.ChatMessage()
                        {
                            Timestamp                = DateTime.UtcNow,
                            Chat                     = message.Chat,
                            ParseMode                = ParseMode.Markdown,
                            Text                     = "Opening and closing time matches the same hour. Please select a different time.",
                            PostSentAction           = Models.ChatMessage.PostSentActions.Destroy,
                            AutoDestroyTimeInSeconds = 5
                        });
                        return;
                    }
                }
                nsl.Update(groupId, CacheData.NightSchedules[groupId].State,
                           CacheData.NightSchedules[groupId].UtcStartDate, endTime, -2);
            }
            else
            {
                nsl.Add(groupId, Models.Group.NightSchedule.Status.Deactivated,
                        null, endTime, -2);
            }

            CacheData.NightSchedules[groupId] = nsl.GetByChat(groupId);
            Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
            SendKeyboard(message.ReplyToMessage, "close");
        }