mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	.timely will now have a button to set a reminder
This commit is contained in:
		@@ -67,13 +67,13 @@ public abstract class NadekoModule : ModuleBase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // localized replies
 | 
					    // localized replies
 | 
				
			||||||
    public Task<IUserMessage> ReplyErrorLocalizedAsync(LocStr str, NadekoButtonInteraction inter = null)
 | 
					    public Task<IUserMessage> ReplyErrorLocalizedAsync(LocStr str, NadekoButtonInteraction inter = null)
 | 
				
			||||||
        => SendErrorAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}");
 | 
					        => SendErrorAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}", inter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Task<IUserMessage> ReplyPendingLocalizedAsync(LocStr str, NadekoButtonInteraction inter = null)
 | 
					    public Task<IUserMessage> ReplyPendingLocalizedAsync(LocStr str, NadekoButtonInteraction inter = null)
 | 
				
			||||||
        => SendPendingAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}");
 | 
					        => SendPendingAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}", inter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Task<IUserMessage> ReplyConfirmLocalizedAsync(LocStr str, NadekoButtonInteraction inter = null)
 | 
					    public Task<IUserMessage> ReplyConfirmLocalizedAsync(LocStr str, NadekoButtonInteraction inter = null)
 | 
				
			||||||
        => SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}");
 | 
					        => SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} {GetText(str)}", inter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public async Task<bool> PromptUserConfirmAsync(IEmbedBuilder embed)
 | 
					    public async Task<bool> PromptUserConfirmAsync(IEmbedBuilder embed)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ using NadekoBot.Modules.Utility.Patronage;
 | 
				
			|||||||
using NadekoBot.Modules.Gambling.Bank;
 | 
					using NadekoBot.Modules.Gambling.Bank;
 | 
				
			||||||
using NadekoBot.Modules.Gambling.Common;
 | 
					using NadekoBot.Modules.Gambling.Common;
 | 
				
			||||||
using NadekoBot.Modules.Gambling.Services;
 | 
					using NadekoBot.Modules.Gambling.Services;
 | 
				
			||||||
 | 
					using NadekoBot.Modules.Utility.Services;
 | 
				
			||||||
using NadekoBot.Services.Currency;
 | 
					using NadekoBot.Services.Currency;
 | 
				
			||||||
using NadekoBot.Services.Database.Models;
 | 
					using NadekoBot.Services.Database.Models;
 | 
				
			||||||
using System.Collections.Immutable;
 | 
					using System.Collections.Immutable;
 | 
				
			||||||
@@ -44,6 +45,7 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
    private readonly GamblingConfigService _configService;
 | 
					    private readonly GamblingConfigService _configService;
 | 
				
			||||||
    private readonly IBankService _bank;
 | 
					    private readonly IBankService _bank;
 | 
				
			||||||
    private readonly IPatronageService _ps;
 | 
					    private readonly IPatronageService _ps;
 | 
				
			||||||
 | 
					    private readonly RemindService _remind;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private IUserMessage rdMsg;
 | 
					    private IUserMessage rdMsg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -54,7 +56,8 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
        DownloadTracker tracker,
 | 
					        DownloadTracker tracker,
 | 
				
			||||||
        GamblingConfigService configService,
 | 
					        GamblingConfigService configService,
 | 
				
			||||||
        IBankService bank,
 | 
					        IBankService bank,
 | 
				
			||||||
        IPatronageService ps)
 | 
					        IPatronageService ps,
 | 
				
			||||||
 | 
					        RemindService remind)
 | 
				
			||||||
        : base(configService)
 | 
					        : base(configService)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        _db = db;
 | 
					        _db = db;
 | 
				
			||||||
@@ -62,6 +65,7 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
        _client = client;
 | 
					        _client = client;
 | 
				
			||||||
        _bank = bank;
 | 
					        _bank = bank;
 | 
				
			||||||
        _ps = ps;
 | 
					        _ps = ps;
 | 
				
			||||||
 | 
					        _remind = remind;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        _enUsCulture = new CultureInfo("en-US", false).NumberFormat;
 | 
					        _enUsCulture = new CultureInfo("en-US", false).NumberFormat;
 | 
				
			||||||
        _enUsCulture.NumberDecimalDigits = 0;
 | 
					        _enUsCulture.NumberDecimalDigits = 0;
 | 
				
			||||||
@@ -110,6 +114,39 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
        PrettyName = "Timely"
 | 
					        PrettyName = "Timely"
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public class RemindMeInteraction : NInteraction
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public RemindMeInteraction(
 | 
				
			||||||
 | 
					            [NotNull] DiscordSocketClient client,
 | 
				
			||||||
 | 
					            ulong userId,
 | 
				
			||||||
 | 
					            [NotNull] Func<SocketMessageComponent, Task> action)
 | 
				
			||||||
 | 
					            : base(client, userId, action)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        protected override NadekoInteractionData Data
 | 
				
			||||||
 | 
					            => new NadekoInteractionData(
 | 
				
			||||||
 | 
					                Emote: Emoji.Parse("⏰"),
 | 
				
			||||||
 | 
					                CustomId: "timely:remind_me",
 | 
				
			||||||
 | 
					                Text: "Remind me"
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Func<SocketMessageComponent, Task> RemindTimelyAction(DateTime when)
 | 
				
			||||||
 | 
					        => async smc =>
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var tt = TimestampTag.FromDateTime(when, TimestampTagStyles.Relative);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await _remind.AddReminderAsync(ctx.User.Id,
 | 
				
			||||||
 | 
					                ctx.Channel.Id,
 | 
				
			||||||
 | 
					                ctx.Guild.Id,
 | 
				
			||||||
 | 
					                true,
 | 
				
			||||||
 | 
					                when,
 | 
				
			||||||
 | 
					                GetText(strs.timely_time));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            await smc.RespondConfirmAsync(_eb, GetText(strs.remind_timely(tt)), ephemeral: true);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Cmd]
 | 
					    [Cmd]
 | 
				
			||||||
    public async partial Task Timely()
 | 
					    public async partial Task Timely()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -135,7 +172,11 @@ public partial class Gambling : GamblingModule<GamblingService>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
 | 
					        await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await ReplyConfirmLocalizedAsync(strs.timely(N(val), period));
 | 
					        var inter = new RemindMeInteraction(_client,
 | 
				
			||||||
 | 
					            ctx.User.Id,
 | 
				
			||||||
 | 
					            RemindTimelyAction(DateTime.UtcNow.Add(TimeSpan.FromHours(period))));
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        await ReplyConfirmLocalizedAsync(strs.timely(N(val), period), inter.GetInteraction());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Cmd]
 | 
					    [Cmd]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -178,4 +178,26 @@ public class RemindService : INService, IReadyExecutor
 | 
				
			|||||||
        public string What { get; set; }
 | 
					        public string What { get; set; }
 | 
				
			||||||
        public TimeSpan Time { get; set; }
 | 
					        public TimeSpan Time { get; set; }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public async Task AddReminderAsync(ulong userId,
 | 
				
			||||||
 | 
					        ulong channelId,
 | 
				
			||||||
 | 
					        ulong? guildId,
 | 
				
			||||||
 | 
					        bool isPrivate,
 | 
				
			||||||
 | 
					        DateTime time,
 | 
				
			||||||
 | 
					        string message)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        var rem = new Reminder
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            UserId = userId,
 | 
				
			||||||
 | 
					            ChannelId = channelId,
 | 
				
			||||||
 | 
					            ServerId = guildId ?? 0,
 | 
				
			||||||
 | 
					            IsPrivate = isPrivate,
 | 
				
			||||||
 | 
					            When = time,
 | 
				
			||||||
 | 
					            Message = message,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await using var ctx = _db.GetDbContext();
 | 
				
			||||||
 | 
					        await ctx.Reminders
 | 
				
			||||||
 | 
					                 .AddAsync(rem);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -596,6 +596,7 @@
 | 
				
			|||||||
  "quote_deleted": "Quote #{0} deleted.",
 | 
					  "quote_deleted": "Quote #{0} deleted.",
 | 
				
			||||||
  "region": "Region",
 | 
					  "region": "Region",
 | 
				
			||||||
  "remind": "I will remind {0} to {1} in {2} `({3:d.M.yyyy.} at {4:HH:mm})`",
 | 
					  "remind": "I will remind {0} to {1} in {2} `({3:d.M.yyyy.} at {4:HH:mm})`",
 | 
				
			||||||
 | 
					  "remind_timely": "I will remind you about your timely reward {0}",
 | 
				
			||||||
  "remind_invalid": "Not a valid remind format. Remind must have a target, timer and a reason. Check the command list.",
 | 
					  "remind_invalid": "Not a valid remind format. Remind must have a target, timer and a reason. Check the command list.",
 | 
				
			||||||
  "remind_too_long": "Remind time has exceeded maximum.",
 | 
					  "remind_too_long": "Remind time has exceeded maximum.",
 | 
				
			||||||
  "repeater_redundant_no": "Repeater **#{0}** won't post redundant messages anymore.",
 | 
					  "repeater_redundant_no": "Repeater **#{0}** won't post redundant messages anymore.",
 | 
				
			||||||
@@ -883,6 +884,7 @@
 | 
				
			|||||||
  "timely_set": "Users will be able to claim {0} every {1}h",
 | 
					  "timely_set": "Users will be able to claim {0} every {1}h",
 | 
				
			||||||
  "timely_set_none": "Users will not be able to claim any timely currency.",
 | 
					  "timely_set_none": "Users will not be able to claim any timely currency.",
 | 
				
			||||||
  "timely_reset": "All users will be able to claim timely currency again.",
 | 
					  "timely_reset": "All users will be able to claim timely currency again.",
 | 
				
			||||||
 | 
					  "timely_time": "It's time for your timely reward.",
 | 
				
			||||||
  "price": "Price",
 | 
					  "price": "Price",
 | 
				
			||||||
  "market_cap": "Market Cap",
 | 
					  "market_cap": "Market Cap",
 | 
				
			||||||
  "market_cap_dominance": "Dominance",
 | 
					  "market_cap_dominance": "Dominance",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user