-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add !donationrecords command to check current records
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NodaTime; | ||
using TPP.Model; | ||
using TPP.Persistence; | ||
|
||
namespace TPP.Core.Commands.Definitions; | ||
|
||
public class DonationCommands( | ||
IDonationRepo donationRepo, | ||
IClock clock | ||
) : ICommandCollection | ||
{ | ||
public IEnumerable<Command> Commands => | ||
[ | ||
new("donationrecords", DonationRecords) | ||
{ | ||
Aliases = ["tiprecords"], | ||
Description = | ||
"Shows the current donation records. " + | ||
"Check !support for how to tip, and get bonus token for every record you break!" | ||
} | ||
]; | ||
|
||
public async Task<CommandResult> DonationRecords(CommandContext context) | ||
{ | ||
SortedDictionary<DonationRecordBreakType, Donation> recordBreaks = | ||
await donationRepo.GetRecordDonations(clock.GetCurrentInstant()); | ||
|
||
IEnumerable<string> recordStrings = DonationRecordBreaks.Types | ||
.Select(recordBreakType => | ||
{ | ||
Donation? donation = recordBreaks.GetValueOrDefault(recordBreakType); | ||
string x = donation == null | ||
? "no donation" | ||
: "$" + (donation.Cents / 100f).ToString("F2") + " by " + donation.UserName; | ||
return recordBreakType.Name + ": " + x; | ||
}); | ||
string response = "Current donation records: " + string.Join(", ", recordStrings); | ||
return new CommandResult { Response = response }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters