Beispiel #1
0
        public override async Task ExecuteAsync(CommandEventArgs e)
        {
            if (!e.IsBotOwner)
            {
                return;
            }

            _storage.ClearPrices();

            await Bot.SendTextMessageAsync(e.ChatId, "База данных очищена.", replyToMessageId : (int)e.MessageId);
        }
Beispiel #2
0
        /// <inheritdoc />
        public override async Task HandleAsync(Message message)
        {
            _log.Information("Handling a new document {filename}...", message.Document.FileName);

            var member = await Bot.GetChatMemberAsync(message.Chat.Id, message.From.Id);

            if (!message.Document.FileName.EndsWith("xlsx") ||
                !member.IsBotOwner())
            {
                return;
            }

            _log.Information("Downloading the file {filename}", message.Document.FileName);

            var file = await Bot.GetFileAsync(message.Document.FileId);

            using (var stream = new MemoryStream())
            {
                await Bot.DownloadFileAsync(file.FilePath, stream);

                stream.Seek(0, SeekOrigin.Begin);

                var parsed = _parser.Parse(stream);

                if (parsed.Length == 0)
                {
                    await Bot.SendTextMessageAsync(message.Chat.Id, "Позиции отсутсвуют.", replyToMessageId : message.MessageId);

                    return;
                }

                // remove old positions
                _storage.ClearPrices();

                // add new positions
                _storage.AddPositions(parsed);
            }

            await Bot.SendTextMessageAsync(message.Chat.Id, "Прайс добавлен.", replyToMessageId : message.MessageId);
        }