private async Task ResponseWithBalance(GetBalanceMessage msg) { _logger.LogInformation("Balance Request {Admin} {User}", msg.Admin, msg.UserId); if (msg.Admin) { var resp = await _getUserBalance.GetAsync(_currentPeriod.Period, msg.UserId, null, msg.Admin); if (resp.Count > 0) { await FormatAndReplyWithSystemBalance(msg, resp); } else { await _slackResponse.ResponseWithText(msg.ResponseUrl, "Увы и ах, в системе пусто. Добавь монеток с помощью */emit*"); } } else { var resp = await _getUserBalance.GetAsync(_currentPeriod.Period, msg.UserId, null, msg.Admin); if (resp.Count > 0) { await FormatAndReplyWithUserBalance(msg, resp); } else { await _slackResponse.ResponseWithText(msg.ResponseUrl, "Увы и ах, на счету пусто :cry:"); } } }
private async Task FormatAndReplyWithUserBalance(GetBalanceMessage msg, List <AccountWithAmount> resp) { var sb = new StringBuilder(); sb.AppendLine($"<@{msg.UserId}>. У тебя на счету:"); foreach (var v in resp.OrderByDescending(a => a.Amount)) { if (v.Amount != 0) { sb.AppendLine($"{v.Account.Currency}{v.Amount}"); } } sb.AppendLine("Вухуху, продолжай в том же духе!\nПодари кому-нибудь монетку с помощью */toss*"); await _slackResponse.ResponseWithText(msg.ResponseUrl, sb.ToString(), true, true); }
private async Task FormatAndReplyWithSystemBalance(GetBalanceMessage msg, List <AccountWithAmount> resp) { var sb = new StringBuilder(); sb.AppendLine(":tada::tada::tada: В текущий момент на всех счетах!"); foreach (var v in resp.OrderByDescending(a => a.Amount)) { if (v.Account.UserId != Constants.CashAccount && v.Amount != 0 && !v.Account.UserId.StartsWith("tote_")) { if (msg.UserId == "U033GDN1S" || !_slackCfg.Value.Admins.Contains(v.Account.UserId)) { sb.AppendLine($"<@{v.Account.UserId}> {v.Account.Currency}{v.Amount.Trim()}"); } } } sb.AppendLine("Прекрасно! Давайте дарить друг другу монетки! Используйте */toss*\n"); await _slackResponse.ResponseWithText(msg.ResponseUrl, sb.ToString(), true, true); }