예제 #1
0
        private async Task OnCallbackQueryHandler(Update update)
        {
            if (string.IsNullOrEmpty(update.CallbackQuery.Data))
            {
                return;
            }

            if (Authorization.IsAuthorized(update.CallbackQuery.Message.Chat.FirstName + " " + update.CallbackQuery.Message.Chat.LastName) == false)
            {
                return;
            }

            this.Log(
                update.CallbackQuery.Message.Chat.Id,
                update.CallbackQuery.Message.Chat.Username,
                update.CallbackQuery.Message.Chat.FirstName,
                update.CallbackQuery.Message.Chat.LastName,
                update.CallbackQuery.Message.MessageId);

            try
            {
                await this.client.EditMessageReplyMarkupAsync(
                    update.CallbackQuery.Message.Chat.Id,
                    update.CallbackQuery.Message.MessageId).ConfigureAwait(false);
            }
            catch (AggregateException ex)
            {
                this.logger.LogError(ex.ToString());
            }

            switch (update.CallbackQuery.Data.Trim())
            {
            case "start":
            case "timetable":
                await this.OnTimetableAsync(update.CallbackQuery.Message.Chat.Id, TimetableType.General)
                .ConfigureAwait(false);

                break;

            case "session":
                await this.OnTimetableAsync(update.CallbackQuery.Message.Chat.Id, TimetableType.Session)
                .ConfigureAwait(false);

                break;

            default:
                await this.client.SendTextMessageAsync(
                    chatId : update.CallbackQuery.Message.Chat,
                    text : $"Неверная команда: {update.CallbackQuery.Data}\nИспользуйте /timetable для получения прогноза погоды.")
                .ConfigureAwait(false);

                break;
            }
        }
예제 #2
0
        private async Task OnMessageHandler(Update update)
        {
            if (string.IsNullOrEmpty(update.Message.Text))
            {
                return;
            }

            if (Authorization.IsAuthorized(update.Message.Chat.FirstName + " " + update.Message.Chat.LastName) == false)
            {
                return;
            }

            this.Log(
                update.Message.Chat.Id,
                update.Message.Chat.Username,
                update.Message.Chat.FirstName,
                update.Message.Chat.LastName,
                update.Message.MessageId);

            switch (update.Message.Text.Trim())
            {
            case "/start":
            case "/timetable":
                await this.OnTimetableAsync(update.Message.Chat.Id, TimetableType.General)
                .ConfigureAwait(false);

                break;

            case "/session":
                await this.OnTimetableAsync(update.Message.Chat.Id, TimetableType.Session)
                .ConfigureAwait(false);

                break;

            default:
                await this.client.SendTextMessageAsync(
                    chatId : update.Message.Chat,
                    text : $"Неверная команда: {update.Message.Text}\nИспользуйте /timetable для получения прогноза погоды.")
                .ConfigureAwait(false);

                break;
            }
        }