diff --git a/src/EllieBot/Modules/Gambling/BlackJack/BlackJackCommands.cs b/src/EllieBot/Modules/Gambling/BlackJack/BlackJackCommands.cs index 772cb4f..ea9c8b8 100644 --- a/src/EllieBot/Modules/Gambling/BlackJack/BlackJackCommands.cs +++ b/src/EllieBot/Modules/Gambling/BlackJack/BlackJackCommands.cs @@ -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; diff --git a/src/EllieBot/Modules/Gambling/BlackJack/Blackjack.cs b/src/EllieBot/Modules/Gambling/BlackJack/Blackjack.cs index e21d2cd..c36845e 100644 --- a/src/EllieBot/Modules/Gambling/BlackJack/Blackjack.cs +++ b/src/EllieBot/Modules/Gambling/BlackJack/Blackjack.cs @@ -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); } diff --git a/src/EllieBot/Modules/Gambling/Gambling.cs b/src/EllieBot/Modules/Gambling/Gambling.cs index 428f756..52789d0 100644 --- a/src/EllieBot/Modules/Gambling/Gambling.cs +++ b/src/EllieBot/Modules/Gambling/Gambling.cs @@ -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 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 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 _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 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 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 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 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 private static readonly ImmutableArray _emojis = new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray(); + [Cmd] public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount) { diff --git a/src/EllieBot/Modules/Gambling/Shop/ShopCommands.cs b/src/EllieBot/Modules/Gambling/Shop/ShopCommands.cs index 8b5230b..a7910de 100644 --- a/src/EllieBot/Modules/Gambling/Shop/ShopCommands.cs +++ b/src/EllieBot/Modules/Gambling/Shop/ShopCommands.cs @@ -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( diff --git a/src/EllieBot/Modules/Gambling/Slot/SlotCommands.cs b/src/EllieBot/Modules/Gambling/Slot/SlotCommands.cs index 238e97e..979cbae 100644 --- a/src/EllieBot/Modules/Gambling/Slot/SlotCommands.cs +++ b/src/EllieBot/Modules/Gambling/Slot/SlotCommands.cs @@ -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; diff --git a/src/EllieBot/Modules/Gambling/Waifus/db/Waifu.cs b/src/EllieBot/Modules/Gambling/Waifus/db/Waifu.cs index fa7c5d5..559f8ba 100644 --- a/src/EllieBot/Modules/Gambling/Waifus/db/Waifu.cs +++ b/src/EllieBot/Modules/Gambling/Waifus/db/Waifu.cs @@ -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; } diff --git a/src/EllieBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs b/src/EllieBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs index 45f3055..a1b6142 100644 --- a/src/EllieBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs +++ b/src/EllieBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs @@ -66,12 +66,12 @@ public static class WaifuExtensions await ctx.Set() .ToLinqToDBTable() .InsertOrUpdateAsync(() => new() - { - AffinityId = null, - ClaimerId = null, - Price = 1, - WaifuId = ctx.Set().Where(x => x.UserId == userId).Select(x => x.Id).First() - }, + { + AffinityId = null, + ClaimerId = null, + Price = 1, + WaifuId = ctx.Set().Where(x => x.UserId == userId).Select(x => x.Id).First() + }, _ => new(), () => new() { diff --git a/src/EllieBot/Modules/Gambling/Waifus/db/WaifuItem.cs b/src/EllieBot/Modules/Gambling/Waifus/db/WaifuItem.cs index 89125c8..5b8630f 100644 --- a/src/EllieBot/Modules/Gambling/Waifus/db/WaifuItem.cs +++ b/src/EllieBot/Modules/Gambling/Waifus/db/WaifuItem.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable namespace EllieBot.Db.Models; public class WaifuItem : DbEntity diff --git a/src/EllieBot/Modules/Gambling/Waifus/db/WaifuUpdate.cs b/src/EllieBot/Modules/Gambling/Waifus/db/WaifuUpdate.cs index 736bd0d..64608c2 100644 --- a/src/EllieBot/Modules/Gambling/Waifus/db/WaifuUpdate.cs +++ b/src/EllieBot/Modules/Gambling/Waifus/db/WaifuUpdate.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable namespace EllieBot.Db.Models; public class WaifuUpdate : DbEntity diff --git a/src/EllieBot/Modules/Gambling/_common/RollDuelGame.cs b/src/EllieBot/Modules/Gambling/_common/RollDuelGame.cs index 24b634a..1244252 100644 --- a/src/EllieBot/Modules/Gambling/_common/RollDuelGame.cs +++ b/src/EllieBot/Modules/Gambling/_common/RollDuelGame.cs @@ -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(