-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: added .gsreset and .bsreset commands change: improved .timely rewards for patrons dev: Improved how blacklist works under the hood
- Loading branch information
1 parent
7f2dcd2
commit 53f9b37
Showing
22 changed files
with
451 additions
and
213 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
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,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(); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.