Skip to content

Commit

Permalink
add !donationrecords command to check current records
Browse files Browse the repository at this point in the history
  • Loading branch information
Felk committed Dec 19, 2024
1 parent 067c22d commit 34e2084
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions TPP.Core/Commands/Definitions/DonationCommands.cs
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 };
}
}
1 change: 1 addition & 0 deletions TPP.Core/Setups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public static CommandProcessor SetUpCommandProcessor(
new StaticResponseCommands().Commands,
new MiscCommands(SystemClock.Instance).Commands,
new UserCommands(databases.UserRepo).Commands,
new DonationCommands(databases.DonationRepo, SystemClock.Instance).Commands,
new TransmuteCommands(transmuter).Commands,
new JoinChatCommands(databases.CoStreamChannelsRepo).Commands,
new OperatorCommands(
Expand Down

0 comments on commit 34e2084

Please sign in to comment.