mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 12:32:03 -04:00
Implemented rakeback
This commit is contained in:
@@ -4,6 +4,7 @@ using Humanizer.Localisation;
|
|||||||
using KfChatDotNetBot.Extensions;
|
using KfChatDotNetBot.Extensions;
|
||||||
using KfChatDotNetBot.Models.DbModels;
|
using KfChatDotNetBot.Models.DbModels;
|
||||||
using KfChatDotNetBot.Services;
|
using KfChatDotNetBot.Services;
|
||||||
|
using KfChatDotNetBot.Settings;
|
||||||
using KfChatDotNetWsClient.Models.Events;
|
using KfChatDotNetWsClient.Models.Events;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@@ -105,3 +106,51 @@ public class SendJuiceCommand : ICommand
|
|||||||
await botInstance.SendChatMessageAsync($"@{user.KfUsername}, {await amount.FormatKasinoCurrencyAsync()} has been sent to {targetUser.KfUsername}", true);
|
await botInstance.SendChatMessageAsync($"@{user.KfUsername}, {await amount.FormatKasinoCurrencyAsync()} has been sent to {targetUser.KfUsername}", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[KasinoCommand]
|
||||||
|
public class RakebackCommand : ICommand
|
||||||
|
{
|
||||||
|
public List<Regex> Patterns => [
|
||||||
|
new Regex(@"^rakeback", RegexOptions.IgnoreCase),
|
||||||
|
new Regex(@"^rapeback", RegexOptions.IgnoreCase)
|
||||||
|
];
|
||||||
|
public string? HelpText => "Collect your rakeback";
|
||||||
|
public UserRight RequiredRight => UserRight.Loser;
|
||||||
|
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||||
|
|
||||||
|
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
|
||||||
|
CancellationToken ctx)
|
||||||
|
{
|
||||||
|
await using var db = new ApplicationDbContext();
|
||||||
|
var gambler = await user.GetGamblerEntity(ct: ctx);
|
||||||
|
var settings = await SettingsProvider.GetMultipleValuesAsync([
|
||||||
|
BuiltIn.Keys.MoneyRakebackPercentage, BuiltIn.Keys.MoneyRakebackMinimumAmount
|
||||||
|
]);
|
||||||
|
var mostRecentRakeback = await db.Transactions.LastOrDefaultAsync(tx =>
|
||||||
|
tx.EventSource == TransactionSourceEventType.Rakeback && tx.Gambler == gambler, cancellationToken: ctx);
|
||||||
|
long offset = 0;
|
||||||
|
if (mostRecentRakeback != null)
|
||||||
|
{
|
||||||
|
offset = mostRecentRakeback.TimeUnixEpochSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
var wagers = db.Wagers.Where(w => w.Gambler == gambler && w.TimeUnixEpochSeconds > offset);
|
||||||
|
if (!await wagers.AnyAsync(ctx))
|
||||||
|
{
|
||||||
|
await botInstance.SendChatMessageAsync(
|
||||||
|
$"@{user.KfUsername}, you haven't wagered since your last rakeback.", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var wagered = await wagers.SumAsync(w => w.WagerAmount, ctx);
|
||||||
|
var rakeback = wagered * (decimal)(settings[BuiltIn.Keys.MoneyRakebackPercentage].ToType<float>() / 100.0);
|
||||||
|
var minimumRakeback = settings[BuiltIn.Keys.MoneyRakebackMinimumAmount].ToType<decimal>();
|
||||||
|
if (rakeback < minimumRakeback)
|
||||||
|
{
|
||||||
|
await botInstance.SendChatMessageAsync($"@{user.KfUsername}, your rakeback payout of {await rakeback.FormatKasinoCurrencyAsync()} is below the minimum amount of {await minimumRakeback.FormatKasinoCurrencyAsync()}", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await gambler!.ModifyBalance(rakeback, TransactionSourceEventType.Rakeback, "Rakeback claimed by gambler",
|
||||||
|
ct: ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -993,6 +993,21 @@ public static class BuiltIn
|
|||||||
ValueType = SettingValueType.Boolean,
|
ValueType = SettingValueType.Boolean,
|
||||||
Regex = BooleanRegex
|
Regex = BooleanRegex
|
||||||
},
|
},
|
||||||
|
new BuiltInSettingsModel
|
||||||
|
{
|
||||||
|
Key = Keys.MoneyRakebackPercentage,
|
||||||
|
Description = "Percentage of total wagered amount that should be returned for rakeback.",
|
||||||
|
Default = "2.5",
|
||||||
|
ValueType = SettingValueType.Text
|
||||||
|
},
|
||||||
|
new BuiltInSettingsModel
|
||||||
|
{
|
||||||
|
Key = Keys.MoneyRakebackMinimumAmount,
|
||||||
|
Description = "Minimum rakeback to pay out. Anything below this will tell the user to go away.",
|
||||||
|
Default = "10",
|
||||||
|
ValueType = SettingValueType.Text,
|
||||||
|
Regex = WholeNumberRegex
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
public static class Keys
|
public static class Keys
|
||||||
@@ -1105,5 +1120,7 @@ public static class BuiltIn
|
|||||||
public static string TwitchGraphQlPersistedCurrentlyLive = "TwitchGraphQl.PersistedCurrentlyLive";
|
public static string TwitchGraphQlPersistedCurrentlyLive = "TwitchGraphQl.PersistedCurrentlyLive";
|
||||||
public static string OwncastCheckInterval = "Owncast.CheckInterval";
|
public static string OwncastCheckInterval = "Owncast.CheckInterval";
|
||||||
public static string OwncastPersistedCurrentlyLive = "Owncast.PersistedCurrentlyLive";
|
public static string OwncastPersistedCurrentlyLive = "Owncast.PersistedCurrentlyLive";
|
||||||
|
public static string MoneyRakebackPercentage = "Money.Rakeback.Percentage";
|
||||||
|
public static string MoneyRakebackMinimumAmount = "Money.Rakeback.MinimumAmount";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user