Updated Gambling module
This commit is contained in:
parent
f9b21520fb
commit
3181f4dcaa
10 changed files with 53 additions and 30 deletions
|
@ -3,6 +3,7 @@ using EllieBot.Common.TypeReaders;
|
|||
using EllieBot.Modules.Gambling.Common;
|
||||
using EllieBot.Modules.Gambling.Common.Blackjack;
|
||||
using EllieBot.Modules.Gambling.Services;
|
||||
using EllieBot.Modules.Utility;
|
||||
|
||||
namespace EllieBot.Modules.Gambling;
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ public class Blackjack
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "REPORT THE MESSAGE BELOW IN Ellie's Home SERVER PLEASE");
|
||||
Log.Error(ex, "REPORT THE MESSAGE BELOW IN #NadekoLog SERVER PLEASE");
|
||||
State = GameState.Ended;
|
||||
_ = GameEnded?.Invoke(this);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#nullable disable
|
||||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using EllieBot.Db;
|
||||
using EllieBot.Db.Models;
|
||||
using EllieBot.Modules.Gambling.Bank;
|
||||
using EllieBot.Modules.Gambling.Common;
|
||||
|
@ -14,6 +13,7 @@ using System.Text;
|
|||
using EllieBot.Modules.Gambling.Rps;
|
||||
using EllieBot.Common.TypeReaders;
|
||||
using EllieBot.Modules.Patronage;
|
||||
using EllieBot.Modules.Utility;
|
||||
|
||||
namespace EllieBot.Modules.Gambling;
|
||||
|
||||
|
@ -27,9 +27,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
private readonly DownloadTracker _tracker;
|
||||
private readonly GamblingConfigService _configService;
|
||||
private readonly IBankService _bank;
|
||||
private readonly IPatronageService _ps;
|
||||
private readonly IRemindService _remind;
|
||||
private readonly GamblingTxTracker _gamblingTxTracker;
|
||||
private readonly IPatronageService _ps;
|
||||
|
||||
private IUserMessage rdMsg;
|
||||
|
||||
|
@ -41,8 +41,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
DownloadTracker tracker,
|
||||
GamblingConfigService configService,
|
||||
IBankService bank,
|
||||
IPatronageService ps,
|
||||
IRemindService remind,
|
||||
IPatronageService patronage,
|
||||
GamblingTxTracker gamblingTxTracker)
|
||||
: base(configService)
|
||||
{
|
||||
|
@ -51,9 +51,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
_cs = currency;
|
||||
_client = client;
|
||||
_bank = bank;
|
||||
_ps = ps;
|
||||
_remind = remind;
|
||||
_gamblingTxTracker = gamblingTxTracker;
|
||||
_ps = patronage;
|
||||
|
||||
_enUsCulture = new CultureInfo("en-US", false).NumberFormat;
|
||||
_enUsCulture.NumberDecimalDigits = 0;
|
||||
|
@ -133,12 +133,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
private static readonly FeatureLimitKey _timelyKey = new FeatureLimitKey()
|
||||
{
|
||||
Key = "timely:extra_percent",
|
||||
PrettyName = "Timely"
|
||||
};
|
||||
|
||||
private async Task RemindTimelyAction(SocketMessageComponent smc, DateTime when)
|
||||
{
|
||||
var tt = TimestampTag.FromDateTime(when, TimestampTagStyles.Relative);
|
||||
|
@ -154,6 +148,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
await smc.RespondConfirmAsync(_sender, GetText(strs.remind_timely(tt)), ephemeral: true);
|
||||
}
|
||||
|
||||
// Creates timely reminder button, parameter in hours.
|
||||
private EllieInteractionBase CreateRemindMeInteraction(int period)
|
||||
=> _inter
|
||||
.Create(ctx.User.Id,
|
||||
|
@ -163,6 +158,17 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
customId: "timely:remind_me"),
|
||||
(smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromHours(period)))
|
||||
);
|
||||
|
||||
// Creates timely reminder button, parameter in milliseconds.
|
||||
private EllieInteractionBase CreateRemindMeInteraction(double ms)
|
||||
=> _inter
|
||||
.Create(ctx.User.Id,
|
||||
new ButtonBuilder(
|
||||
label: "Remind me",
|
||||
emote: Emoji.Parse("⏰"),
|
||||
customId: "timely:remind_me"),
|
||||
(smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromMilliseconds(ms)))
|
||||
);
|
||||
|
||||
[Cmd]
|
||||
public async Task Timely()
|
||||
|
@ -175,25 +181,31 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
return;
|
||||
}
|
||||
|
||||
var inter = CreateRemindMeInteraction(period);
|
||||
|
||||
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } rem)
|
||||
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder)
|
||||
{
|
||||
// Get correct time form remainder
|
||||
var interaction = CreateRemindMeInteraction(remainder.TotalMilliseconds);
|
||||
|
||||
// Removes timely button if there is a timely reminder in DB
|
||||
if (_service.UserHasTimelyReminder(ctx.User.Id))
|
||||
{
|
||||
inter = null;
|
||||
interaction = null;
|
||||
}
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var relativeTag = TimestampTag.FromDateTime(now.Add(rem), TimestampTagStyles.Relative);
|
||||
await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(inter).SendAsync();
|
||||
var relativeTag = TimestampTag.FromDateTime(now.Add(remainder), TimestampTagStyles.Relative);
|
||||
await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(interaction).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var result = await _ps.TryGetFeatureLimitAsync(_timelyKey, ctx.User.Id, 0);
|
||||
var patron = await _ps.GetPatronAsync(ctx.User.Id);
|
||||
|
||||
val = (int)(val * (1 + (result.Quota! * 0.01f)));
|
||||
var percentBonus = (_ps.PercentBonus(patron) / 100f);
|
||||
|
||||
val += (int)(val * percentBonus);
|
||||
|
||||
var inter = CreateRemindMeInteraction(period);
|
||||
|
||||
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
|
||||
|
||||
|
@ -892,6 +904,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
private static readonly ImmutableArray<string> _emojis =
|
||||
new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray();
|
||||
|
||||
|
||||
[Cmd]
|
||||
public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount)
|
||||
{
|
||||
|
|
|
@ -247,7 +247,14 @@ public partial class Gambling
|
|||
}
|
||||
else
|
||||
{
|
||||
var cmd = entry.Command.Replace("%you%", ctx.User.Id.ToString());
|
||||
var buyer = (IGuildUser)ctx.User;
|
||||
var cmd = entry.Command
|
||||
.Replace("%you%", buyer.Mention)
|
||||
.Replace("%you.mention%", buyer.Mention)
|
||||
.Replace("%you.username%", buyer.Username)
|
||||
.Replace("%you.name%", buyer.GlobalName ?? buyer.Username)
|
||||
.Replace("%you.nick%", buyer.DisplayName);
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
.WithPendingColor()
|
||||
.WithTitle("Executing shop command")
|
||||
|
@ -259,6 +266,7 @@ public partial class Gambling
|
|||
GetProfitAmount(entry.Price),
|
||||
new("shop", "sell", entry.Name));
|
||||
|
||||
await Task.Delay(250);
|
||||
await _cmdHandler.TryRunCommand(guild,
|
||||
channel,
|
||||
new DoAsUserMessage(
|
||||
|
|
|
@ -9,6 +9,7 @@ using SixLabors.ImageSharp.PixelFormats;
|
|||
using SixLabors.ImageSharp.Processing;
|
||||
using EllieBot.Modules.Gambling;
|
||||
using EllieBot.Common.TypeReaders;
|
||||
using EllieBot.Modules.Utility;
|
||||
using Color = SixLabors.ImageSharp.Color;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ public class WaifuInfo : DbEntity
|
|||
{
|
||||
public int WaifuId { get; set; }
|
||||
public DiscordUser Waifu { get; set; }
|
||||
|
||||
|
||||
public int? ClaimerId { get; set; }
|
||||
public DiscordUser Claimer { get; set; }
|
||||
|
||||
|
|
|
@ -66,12 +66,12 @@ public static class WaifuExtensions
|
|||
await ctx.Set<WaifuInfo>()
|
||||
.ToLinqToDBTable()
|
||||
.InsertOrUpdateAsync(() => new()
|
||||
{
|
||||
AffinityId = null,
|
||||
ClaimerId = null,
|
||||
Price = 1,
|
||||
WaifuId = ctx.Set<DiscordUser>().Where(x => x.UserId == userId).Select(x => x.Id).First()
|
||||
},
|
||||
{
|
||||
AffinityId = null,
|
||||
ClaimerId = null,
|
||||
Price = 1,
|
||||
WaifuId = ctx.Set<DiscordUser>().Where(x => x.UserId == userId).Select(x => x.Id).First()
|
||||
},
|
||||
_ => new(),
|
||||
() => new()
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#nullable disable
|
||||
#nullable disable
|
||||
namespace EllieBot.Db.Models;
|
||||
|
||||
public class WaifuItem : DbEntity
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#nullable disable
|
||||
#nullable disable
|
||||
namespace EllieBot.Db.Models;
|
||||
|
||||
public class WaifuUpdate : DbEntity
|
||||
|
|
|
@ -34,7 +34,7 @@ public class RollDuelGame
|
|||
private readonly ICurrencyService _cs;
|
||||
|
||||
private readonly Timer _timeoutTimer;
|
||||
private readonly EllieRandom _rng = new();
|
||||
private readonly NadekoRandom _rng = new();
|
||||
private readonly SemaphoreSlim _locker = new(1, 1);
|
||||
|
||||
public RollDuelGame(
|
||||
|
|
Loading…
Reference in a new issue