Ejemplo n.º 1
0
        private async Task HandlePositivePromo(PromoTransferMessage msg)
        {
            var resp = await _getUserBalance.GetAsync(_currentPeriod.Period, msg.FromUser, msg.Currency, false);

            var userAccount = resp.Count == 0 ? 0 : resp[0].Amount;

            var amount = msg.Amount;

            _logger.LogInformation($"On balance for promo: {userAccount}, amount {amount} {msg.Currency}");
            if (userAccount < amount || userAccount == 0)
            {
                await _slackResponse.ResponseWithText(msg.ResponseUrl,
                                                      $":cry: печально, но в банке промокодов нет столько ({amount}) {msg.Currency}.",
                                                      true);
            }
            else
            {
                Address.Tell(new ValidatedTransferMessage(msg.FromUser, msg.ToUser, amount, msg.Currency,
                                                          $"За найденный промокод `{msg.Code}`!"));
            }
        }
Ejemplo n.º 2
0
        private async Task HandleNegativePromo(PromoTransferMessage msg)
        {
            var resp = await _getUserBalance.GetAsync(_currentPeriod.Period, msg.ToUser, msg.Currency, false);

            var userAccount = resp.Count == 0 ? 0 : resp[0].Amount;

            var amount = Math.Abs(msg.Amount);

            if (userAccount < amount || userAccount == 0)
            {
                await _slackResponse.ResponseWithText(msg.ResponseUrl,
                                                      $"Повезло! Было бы у тебя нужное количество монет - они бы пропали :)",
                                                      true);
            }
            else
            {
                Address.Tell(new ValidatedTransferMessage(msg.ToUser, msg.FromUser, amount, msg.Currency,
                                                          "Промокоды бывают не очень-то хорошими!"));
                MessengerActor.Send(new MessageToChannel(msg.ToUser, $"Промокод промокоду рознь, прости, но этот - не самый удачный. Вжух и {amount}{msg.Currency} сгорают."));
                MessengerActor.Send(new MessageToChannel(_app.Value.AnnouncementsChannelId, $"<@{msg.ToUser}> нашёл чооорный промокод `{msg.Code}` и *теряет* {amount}{msg.Currency}"));
            }
        }
Ejemplo n.º 3
0
        private Task HandlePromo(PromoTransferMessage msg)
        {
            _logger.LogInformation($"Handle promo! {msg.Amount} {msg.FromUser} {msg.Currency} {msg.ToUser}");
            try
            {
                if (msg.Amount > 0)
                {
                    return(HandlePositivePromo(msg));
                }
                else if (msg.Amount < 0)
                {
                    return(HandleNegativePromo(msg));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error handling promo code");
                throw;
            }

            return(Task.CompletedTask);
        }