Skip to content

Commit

Permalink
add: added .snipe command
Browse files Browse the repository at this point in the history
add: added .gsreset and .bsreset commands
change: improved .timely rewards for patrons
dev: Improved how blacklist works under the hood
  • Loading branch information
Wizkiller96 committed Nov 10, 2024
1 parent 7f2dcd2 commit 53f9b37
Show file tree
Hide file tree
Showing 22 changed files with 451 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace WizBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public partial class AnimalRacingCommands : GamblingSubmodule<AnimalRaceService>
public partial class AnimalRacingCommands : GamblingModule<AnimalRaceService>
{
private readonly ICurrencyService _cs;
private readonly DiscordSocketClient _client;
Expand Down
175 changes: 175 additions & 0 deletions src/WizBot/Modules/Gambling/BetStatsCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#nullable disable
using WizBot.Modules.Gambling.Common;
using WizBot.Modules.Gambling.Services;

namespace WizBot.Modules.Gambling;

public partial class Gambling
{
[Group]
public sealed class BetStatsCommands : GamblingModule<UserBetStatsService>
{
private readonly GamblingTxTracker _gamblingTxTracker;

public BetStatsCommands(
GamblingTxTracker gamblingTxTracker,
GamblingConfigService gcs)
: base(gcs)
{
_gamblingTxTracker = gamblingTxTracker;
}

[Cmd]
public async Task BetStatsReset(GamblingGame? game = null)
{
var price = await _service.GetResetStatsPriceAsync(ctx.User.Id, game);

var result = await PromptUserConfirmAsync(_sender.CreateEmbed()
.WithDescription(
$"""
Are you sure you want to reset your bet stats for **{GetGameName(game)}**?
It will cost you {N(price)}
"""));

if (!result)
return;

var success = await _service.ResetStatsAsync(ctx.User.Id, game);

if (success)
{
await ctx.OkAsync();
}
else
{
await Response()
.Error(strs.not_enough(CurrencySign))
.SendAsync();
}
}

private string GetGameName(GamblingGame? game)
{
if (game is null)
return "all games";

return game.ToString();
}

[Cmd]
[Priority(3)]
public async Task BetStats()
=> await BetStats(ctx.User, null);

[Cmd]
[Priority(2)]
public async Task BetStats(GamblingGame game)
=> await BetStats(ctx.User, game);

[Cmd]
[Priority(1)]
public async Task BetStats([Leftover] IUser user)
=> await BetStats(user, null);

[Cmd]
[Priority(0)]
public async Task BetStats(IUser user, GamblingGame? game)
{
var stats = await _gamblingTxTracker.GetUserStatsAsync(user.Id, game);

if (stats.Count == 0)
stats = new()
{
new()
{
TotalBet = 1
}
};

var eb = _sender.CreateEmbed()
.WithOkColor()
.WithAuthor(user)
.AddField("Total Won", N(stats.Sum(x => x.PaidOut)), true)
.AddField("Biggest Win", N(stats.Max(x => x.MaxWin)), true)
.AddField("Biggest Bet", N(stats.Max(x => x.MaxBet)), true)
.AddField("# Bets", stats.Sum(x => x.WinCount + x.LoseCount), true)
.AddField("Payout",
(stats.Sum(x => x.PaidOut) / stats.Sum(x => x.TotalBet)).ToString("P2", Culture),
true);
if (game == null)
{
var favGame = stats.MaxBy(x => x.WinCount + x.LoseCount);
eb.AddField("Favorite Game",
favGame.Game + "\n" + Format.Italics((favGame.WinCount + favGame.LoseCount) + " plays"),
true);
}
else
{
eb.WithDescription(game.ToString())
.AddField("# Wins", stats.Sum(x => x.WinCount), true);
}

await Response()
.Embed(eb)
.SendAsync();
}

[Cmd]
public async Task GambleStats()
{
var stats = await _gamblingTxTracker.GetAllAsync();

var eb = _sender.CreateEmbed()
.WithOkColor();

var str = "` Feature `|`   Bet  `|`Paid Out`|`  RoI  `\n";
str += "――――――――――――――――――――\n";
foreach (var stat in stats)
{
var perc = (stat.PaidOut / stat.Bet).ToString("P2", Culture);
str += $"`{stat.Feature.PadBoth(9)}`"
+ $"|`{stat.Bet.ToString("N0").PadLeft(8, ' ')}`"
+ $"|`{stat.PaidOut.ToString("N0").PadLeft(8, ' ')}`"
+ $"|`{perc.PadLeft(6, ' ')}`\n";
}

var bet = stats.Sum(x => x.Bet);
var paidOut = stats.Sum(x => x.PaidOut);

if (bet == 0)
bet = 1;

var tPerc = (paidOut / bet).ToString("P2", Culture);
str += "――――――――――――――――――――\n";
str += $"` {("TOTAL").PadBoth(7)}` "
+ $"|**{N(bet).PadLeft(8, ' ')}**"
+ $"|**{N(paidOut).PadLeft(8, ' ')}**"
+ $"|`{tPerc.PadLeft(6, ' ')}`";

eb.WithDescription(str);

await Response().Embed(eb).SendAsync();
}

[Cmd]
[OwnerOnly]
public async Task GambleStatsReset()
{
if (!await PromptUserConfirmAsync(_sender.CreateEmbed()
.WithDescription(
"""
Are you sure?
This will completely reset Gambling Stats.
This action is irreversible.
""")))
return;

await GambleStats();
await _service.ResetGamblingStatsAsync();

await ctx.OkAsync();
}
}
}
2 changes: 1 addition & 1 deletion src/WizBot/Modules/Gambling/BlackJack/BlackJackCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace WizBot.Modules.Gambling;

public partial class Gambling
{
public partial class BlackJackCommands : GamblingSubmodule<BlackJackService>
public partial class BlackJackCommands : GamblingModule<BlackJackService>
{
public enum BjAction
{
Expand Down
2 changes: 1 addition & 1 deletion src/WizBot/Modules/Gambling/Connect4/Connect4Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace WizBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public partial class Connect4Commands : GamblingSubmodule<GamblingService>
public partial class Connect4Commands : GamblingModule<GamblingService>
{
private static readonly string[] _numbers =
[
Expand Down
2 changes: 1 addition & 1 deletion src/WizBot/Modules/Gambling/Draw/DrawCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace WizBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public partial class DrawCommands : GamblingSubmodule<IGamblingService>
public partial class DrawCommands : GamblingModule<IGamblingService>
{
private static readonly ConcurrentDictionary<IGuild, Deck> _allDecks = new();
private readonly IImageCache _images;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace WizBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public partial class CurrencyEventsCommands : GamblingSubmodule<CurrencyEventsService>
public partial class CurrencyEventsCommands : GamblingModule<CurrencyEventsService>
{
public CurrencyEventsCommands(GamblingConfigService gamblingConf)
: base(gamblingConf)
Expand Down
2 changes: 1 addition & 1 deletion src/WizBot/Modules/Gambling/FlipCoin/FlipCoinCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace WizBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public partial class FlipCoinCommands : GamblingSubmodule<IGamblingService>
public partial class FlipCoinCommands : GamblingModule<IGamblingService>
{
public enum BetFlipGuess : byte
{
Expand Down
95 changes: 0 additions & 95 deletions src/WizBot/Modules/Gambling/Gambling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,101 +80,6 @@ public async Task<string> GetBalanceStringAsync(ulong userId)
return N(bal);
}

[Cmd]
[Priority(3)]
public async Task BetStats()
=> await BetStats(ctx.User, null);

[Cmd]
[Priority(2)]
public async Task BetStats(GamblingGame game)
=> await BetStats(ctx.User, game);

[Cmd]
[Priority(1)]
public async Task BetStats([Leftover] IUser user)
=> await BetStats(user, null);

[Cmd]
[Priority(0)]
public async Task BetStats(IUser user, GamblingGame? game)
{
var stats = await _gamblingTxTracker.GetUserStatsAsync(user.Id, game);

if (stats.Count == 0)
stats = new()
{
new()
{
TotalBet = 1
}
};

var eb = _sender.CreateEmbed()
.WithOkColor()
.WithAuthor(user)
.AddField("Total Won", N(stats.Sum(x => x.PaidOut)), true)
.AddField("Biggest Win", N(stats.Max(x => x.MaxWin)), true)
.AddField("Biggest Bet", N(stats.Max(x => x.MaxBet)), true)
.AddField("# Bets", stats.Sum(x => x.WinCount + x.LoseCount), true)
.AddField("Payout",
(stats.Sum(x => x.PaidOut) / stats.Sum(x => x.TotalBet)).ToString("P2", Culture),
true);
if (game == null)
{
var favGame = stats.MaxBy(x => x.WinCount + x.LoseCount);
eb.AddField("Favorite Game",
favGame.Game + "\n" + Format.Italics((favGame.WinCount + favGame.LoseCount) + " plays"),
true);
}
else
{
eb.WithDescription(game.ToString())
.AddField("# Wins", stats.Sum(x => x.WinCount), true);
}

await Response()
.Embed(eb)
.SendAsync();
}

[Cmd]
public async Task GambleStats()
{
var stats = await _gamblingTxTracker.GetAllAsync();

var eb = _sender.CreateEmbed()
.WithOkColor();

var str = "` Feature `|`   Bet  `|`Paid Out`|`  RoI  `\n";
str += "――――――――――――――――――――\n";
foreach (var stat in stats)
{
var perc = (stat.PaidOut / stat.Bet).ToString("P2", Culture);
str += $"`{stat.Feature.PadBoth(9)}`"
+ $"|`{stat.Bet.ToString("N0").PadLeft(8, ' ')}`"
+ $"|`{stat.PaidOut.ToString("N0").PadLeft(8, ' ')}`"
+ $"|`{perc.PadLeft(6, ' ')}`\n";
}

var bet = stats.Sum(x => x.Bet);
var paidOut = stats.Sum(x => x.PaidOut);

if (bet == 0)
bet = 1;

var tPerc = (paidOut / bet).ToString("P2", Culture);
str += "――――――――――――――――――――\n";
str += $"` {("TOTAL").PadBoth(7)}` "
+ $"|**{N(bet).PadLeft(8, ' ')}**"
+ $"|**{N(paidOut).PadLeft(8, ' ')}**"
+ $"|`{tPerc.PadLeft(6, ' ')}`";

eb.WithDescription(str);

await Response().Embed(eb).SendAsync();
}

private async Task RemindTimelyAction(SocketMessageComponent smc, DateTime when)
{
var tt = TimestampTag.FromDateTime(when, TimestampTagStyles.Relative);
Expand Down
8 changes: 0 additions & 8 deletions src/WizBot/Modules/Gambling/GamblingTopLevelModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,4 @@ protected Task<bool> CheckBetOptional(long amount)
return Task.FromResult(true);
return InternalCheckBet(amount);
}
}

public abstract class GamblingSubmodule<TService> : GamblingModule<TService>
{
protected GamblingSubmodule(GamblingConfigService gamblingConfService)
: base(gamblingConfService)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace WizBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public partial class PlantPickCommands : GamblingSubmodule<PlantPickService>
public partial class PlantPickCommands : GamblingModule<PlantPickService>
{
private readonly ILogCommandService _logService;

Expand Down
2 changes: 1 addition & 1 deletion src/WizBot/Modules/Gambling/Shop/ShopCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace WizBot.Modules.Gambling;
public partial class Gambling
{
[Group]
public partial class ShopCommands : GamblingSubmodule<IShopService>
public partial class ShopCommands : GamblingModule<IShopService>
{
public enum List
{
Expand Down
2 changes: 1 addition & 1 deletion src/WizBot/Modules/Gambling/Slot/SlotCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum GamblingError
public partial class Gambling
{
[Group]
public partial class SlotCommands : GamblingSubmodule<IGamblingService>
public partial class SlotCommands : GamblingModule<IGamblingService>
{
private readonly IImageCache _images;
private readonly FontProvider _fonts;
Expand Down
Loading

0 comments on commit 53f9b37

Please sign in to comment.