예제 #1
0
        public static async Task <bool> CheckMessagesToSend(bool force_send_everything_in_queue,
                                                            TelegramBotAbstract telegramBotAbstract)
        {
            DataTable dt = null;
            var       q  = "SELECT * " +
                           "FROM Messages ";

            dt = SqLite.ExecuteSelect(q);
            if (dt == null || dt.Rows.Count == 0)
            {
                return(false);
            }

            foreach (DataRow dr in dt.Rows)
            {
                try
                {
                    var botToReportException = FindBotIfNeeded(null, telegramBotAbstract);
                    var r1 = await SendMessageToSend(dr, null, !force_send_everything_in_queue, botToReportException);

                    telegramBotAbstract = FindBotIfNeeded(r1, telegramBotAbstract);
                    if (telegramBotAbstract != null &&
                        r1 != null) // && r1.scheduleMessageSentResult != Enums.ScheduleMessageSentResult.ALREADY_SENT)
                    {
                        switch (r1.scheduleMessageSentResult)
                        {
                        case ScheduleMessageSentResult.NOT_THE_RIGHT_TIME:
                        case ScheduleMessageSentResult.FAILED_SEND:
                        case ScheduleMessageSentResult.SUCCESS:
                        case ScheduleMessageSentResult.WE_DONT_KNOW_IF_IT_HAS_BEEN_SENT:
                        {
                            await NotifyOwnersOfResultAsync(r1, telegramBotAbstract);

                            break;
                        }

                        case ScheduleMessageSentResult.THE_MESSAGE_IS_NOT_SCHEDULED:
                        case ScheduleMessageSentResult.ALREADY_SENT:
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    await NotifyUtil.NotifyOwners(e, BotUtil.GetFirstModerationRealBot(telegramBotAbstract));
                }
            }

            return(true);
        }
예제 #2
0
        private static TelegramBotAbstract FindBotIfNeeded(MessageSendScheduled r1,
                                                           TelegramBotAbstract telegramBotAbstract)
        {
            if (telegramBotAbstract != null)
            {
                return(telegramBotAbstract);
            }

            if (r1 == null)
            {
                return(BotUtil.GetFirstModerationRealBot());
            }

            var r2 = r1.scheduleMessageSentResult;

            switch (r2)
            {
            case ScheduleMessageSentResult.NOT_THE_RIGHT_TIME:
                return(null);

            case ScheduleMessageSentResult.THE_MESSAGE_IS_NOT_SCHEDULED:
                return(null);

            case ScheduleMessageSentResult.FAILED_SEND:
                break;

            case ScheduleMessageSentResult.SUCCESS:
                return(null);

            case ScheduleMessageSentResult.WE_DONT_KNOW_IF_IT_HAS_BEEN_SENT:
                break;

            case ScheduleMessageSentResult.ALREADY_SENT:
                return(null);
            }

            return(BotUtil.GetFirstModerationRealBot());
        }