Skip to content

Commit

Permalink
donations: make cents per tokens configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Felk committed Dec 19, 2024
1 parent 7a77feb commit 067c22d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions TPP.Core/Configuration/BaseConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public sealed class BaseConfig : ConfigBase, IRootConfig
[Description("Donation handling via Streamlabs")]
public StreamlabsConfig StreamlabsConfig { get; init; } = new();

/// How many cents donated give you 1 token. Smaller number = more tokens per money
public int CentsPerToken { get; init; } = 50;
/// How many cents donated total before a user gets the donor badge
public int DonorBadgeCents { get; init; } = 20000;
}

Expand Down
3 changes: 1 addition & 2 deletions TPP.Core/DonationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DonationHandler(
IMessageSender messageSender,
OverlayConnection overlayConnection,
IChattersSnapshotsRepo chattersSnapshotsRepo,
int centsPerToken,
int donorBadgeCents)
{
public record NewDonation(
Expand Down Expand Up @@ -129,8 +130,6 @@ private async Task<ImmutableSortedSet<DonationRecordBreakType>> GetRecordBreaks(
/// plus bonus tokens obtained from donation record breaks.
private DonationTokens GetDonationTokens(int cents, ISet<DonationRecordBreakType> recordBreaks)
{
const int centsPerToken = 50;

int baseTokens = cents / centsPerToken;
int bonusTokens = recordBreaks.Sum(recordBreakType => recordBreakType.TokenWinning);

Expand Down
3 changes: 2 additions & 1 deletion TPP.Core/Modes/ModeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public ModeBase(
_logger.LogWarning("Multiple chats configured, using {Chat} for donation token whispers", chatName);
DonationHandler donationHandler = new(loggerFactory.CreateLogger<DonationHandler>(),
repos.DonationRepo, repos.UserRepo, repos.TokensBank, chat, overlayConnection,
repos.ChattersSnapshotsRepo, baseConfig.DonorBadgeCents);
repos.ChattersSnapshotsRepo,
centsPerToken: baseConfig.CentsPerToken, donorBadgeCents: baseConfig.DonorBadgeCents);
StreamlabsClient streamlabsClient = new(loggerFactory.CreateLogger<StreamlabsClient>(),
streamlabsConfig.AccessToken);
_donationsWorker = new DonationsWorker(loggerFactory, streamlabsConfig.PollingInterval,
Expand Down
3 changes: 3 additions & 0 deletions TPP.Core/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
"StreamlabsConfig": {
"$ref": "#/definitions/StreamlabsConfig"
},
"CentsPerToken": {
"type": "integer"
},
"DonorBadgeCents": {
"type": "integer"
}
Expand Down

0 comments on commit 067c22d

Please sign in to comment.