Пример #1
0
        public override async Task ExecuteAsync(CommandEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(e.CommandLine))
            {
                return;
            }

            var me = await Bot.GetMeAsync();

            var filtered = _storage.Find(e.CommandLine, null, 10)
                           .Where(p => p.RetailPrice > 0m)
                           .ToArray();

            if (filtered.Length == 0)
            {
                await Bot.SendTextMessageAsync(e.ChatId, "Ничего не найдено, сорянба :(", replyToMessageId : (int)e.MessageId);
            }
            else
            {
                var rate   = filtered.FirstOrDefault()?.CurrencyRate ?? 1.0m;
                var result = filtered.GroupBy(p => p.Category)
                             .Select(g => g.ToFindResult())
                             .ToArray();

                var message = result.ToFindResult(e.CommandLine, rate, me.Username);
                await Bot.SendTextMessageAsync(e.ChatId, message, ParseMode.Markdown, replyToMessageId : (int)e.MessageId);
            }
        }
Пример #2
0
        /// <inheritdoc />
        public override async Task HandleAsync(InlineQuery query)
        {
            _log.Information("Handling a new inline query: {query}", query.Query);

            if (string.IsNullOrWhiteSpace(query.Query))
            {
                return;
            }

            var me = await Bot.GetMeAsync();

            // log user query
            _storage.AddUserQuery(new UserQuery(query.From, query.Query));

            var filtered = _storage.Find(query.Query, null, 10)
                           .Where(p => p.RetailPrice > 0m)
                           .ToArray();

            if (filtered.Length == 0)
            {
                await Bot.AnswerInlineQueryAsync(query.Id, Enumerable.Empty <InlineQueryResultBase>());
            }
            else
            {
                var rate   = filtered.FirstOrDefault()?.CurrencyRate ?? 1.0m;
                var result = filtered
                             .Select((p, i) => p.ToInlineResult(i, query.Query, rate, me.Username));
                await Bot.AnswerInlineQueryAsync(query.Id, result);
            }
        }