示例#1
0
        private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timer.Interval = new TimeSpan(1, 0, 0, 0).TotalMilliseconds;

            todayDayName = WorkingDays.Contains(DateTime.Now.DayOfWeek.ToString()) ?
                           DateTime.Now.DayOfWeek.ToString() : WorkingDays[0];

            ewh = new EventWaitHandle(false, EventResetMode.AutoReset);

            Thread th = new Thread(g =>
            {
                Parallel.For(0, Bot.Keyboards.Keys.Count(), parallelOptions:
                             new ParallelOptions {
                    MaxDegreeOfParallelism = 2
                }, k => {
                    if (Bot.Keyboards.ElementAt(k).Value.inlineKeyboardForSchedule != null)
                    {
                        int MessageID = Bot.Keyboards.ElementAt(k).Value.inlineKeyboardForSchedule.MessageID;

                        Bot.Keyboards.ElementAt(k).Value.inlineKeyboardForSchedule =
                            GettingKeyboardWithRelevantLessons.
                            GetKeyboardWithRelevantLessonsForAutomaticRefresh(
                                Bot.Keyboards.ElementAt(k).Key.ToString());

                        Bot.Keyboards.ElementAt(k).Value.inlineKeyboardForSchedule.MessageID = MessageID;
                    }
                });

                ewh.Set();
            });

            th.Start();
            ewh.WaitOne();
        }
示例#2
0
        private async void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            if (!Keyboards.ContainsKey(e.Message.From.Id))
            {
                Keyboards[e.Message.From.Id] = new UsersKeyboards();
            }

            if (e.Message.Text == "Send Again" || e.Message.Text == "/send_again")
            {
                logger.Info("User typed Send Again button");

                var keyboard = GettingKeyboardWithRelevantLessons.GetKeyboardWithRelevantLessons(e, true);
                if (keyboard != null)
                {
                    if (keyboard is InlineKeyboardForSchedule)
                    {
                        Keyboards[e.Message.From.Id].inlineKeyboardForSchedule = (InlineKeyboardForSchedule)keyboard;
                    }
                    else
                    {
                        Keyboards[e.Message.From.Id].inlineKeyboardForSchedule = keyboard;
                    }
                    return;
                }
            }

            #region RedistrationAndRessetingAccount
            if (e.Message.Text == "/start")
            {
                logger.Info("User typed Send /start button");

                Messages.SendPossibleGroups(e.Message.Chat);
                Keyboards[e.Message.From.Id] = new UsersKeyboards();

                Keyboards[e.Message.From.Id].startitngRegistration_plot = new StartitngRegistration();


                Messages.SendInstruction(e.Message.Chat);

                return;
            }

            if (Program.Groups.Contains(e.Message.Text) &&
                Keyboards[e.Message.From.Id].startitngRegistration_plot != null)
            {
                Keyboards[e.Message.From.Id].inlineKeyboardForRegistration =
                    Keyboards[e.Message.From.Id].startitngRegistration_plot.UserSelectedGroup(e);

                Keyboards[e.Message.From.Id].startitngRegistration_plot = null;
                return;
            }

            if (Keyboards[e.Message.From.Id].inlineKeyboardForRegistration != null && e.Message.Text == "READY")
            {
                logger.Info("User typed READY text.");
                if (Keyboards[e.Message.From.Id].inlineKeyboardForRegistration.Name_Of_Choosen_Objects.Count() != 0)
                {
                    var keyboard = GettingKeyboardWithRelevantLessons.EndRegistrationGetKeyboardWithRelevantLessons(e,
                                                                                                                    Keyboards[e.Message.From.Id].inlineKeyboardForRegistration.Name_Of_Choosen_Objects.ToArray());

                    if (keyboard is InlineKeyboardForSchedule)
                    {
                        Keyboards[e.Message.From.Id].inlineKeyboardForSchedule = (InlineKeyboardForSchedule)keyboard;
                    }
                    else
                    {
                        Keyboards[e.Message.From.Id].inlineKeyboardForSchedule = keyboard;
                    }

                    Keyboards[e.Message.From.Id].inlineKeyboardForRegistration = null;

                    await botClient.SendTextMessageAsync(
                        chatId : e.Message.Chat,
                        text : "Or Press /send_again button if keyboard doesn't work ",
                        replyMarkup : new ReplyKeyboardMarkup
                    {
                        Keyboard = new KeyboardButton[][]
                        {
                            new KeyboardButton[]
                            {
                                new KeyboardButton {
                                    Text = "Send Again"
                                }
                            }
                        },
                        OneTimeKeyboard = true,
                        ResizeKeyboard  = true
                    });

                    return;
                }
                else
                {
                    await botClient.SendTextMessageAsync(
                        chatId : e.Message.Chat,
                        text : "You didn't choose anything. Please choose!");
                }
            }

            #endregion

            if (e.Message.Text == "/help")
            {
                logger.Info("User typed /help text.");
                Messages.SendInstruction(e.Message.Chat);
                return;
            }

            if (e.Message.Text.Contains("/sndmsg"))
            {
                logger.Info($"User typed /sndmsg {e.Message.From.FirstName} {e.Message.From.LastName}");

                Thread th = new Thread(g =>
                {
                    if (e.Message.Text.Contains("-q"))
                    {
                        Messages.SendСustomMessage(string.Join(' ', e.Message.Text.Split(' ').Skip(2).ToArray()), true,
                                                   (true, e.Message.Chat));
                    }
                    else
                    {
                        Messages.SendСustomMessage(string.Join(' ', e.Message.Text.Split(' ').Skip(1).ToArray()), false,
                                                   (true, e.Message.Chat));
                    }
                });
                th.IsBackground = true;
                th.Start();
                return;
            }
        }