mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 08:34:27 -05:00 
			
		
		
		
	Added .repeatskip
This commit is contained in:
		@@ -9,6 +9,32 @@ public partial class Utility
 | 
			
		||||
    [Group]
 | 
			
		||||
    public partial class RepeatCommands : NadekoModule<RepeaterService>
 | 
			
		||||
    {
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [RequireContext(ContextType.Guild)]
 | 
			
		||||
        [UserPerm(GuildPerm.ManageMessages)]
 | 
			
		||||
        public async Task RepeatSkip(int index)
 | 
			
		||||
        {
 | 
			
		||||
            if (--index < 0)
 | 
			
		||||
                return;
 | 
			
		||||
            
 | 
			
		||||
            var result = await _service.ToggleSkipNextAsync(ctx.Guild.Id, index);
 | 
			
		||||
            
 | 
			
		||||
            if (result is null)
 | 
			
		||||
            {
 | 
			
		||||
                await ReplyErrorLocalizedAsync(strs.index_out_of_range);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (result is true)
 | 
			
		||||
            {
 | 
			
		||||
                await ReplyConfirmLocalizedAsync(strs.repeater_skip_next);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                await ReplyConfirmLocalizedAsync(strs.repeater_dont_skip_next);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        [Cmd]
 | 
			
		||||
        [RequireContext(ContextType.Guild)]
 | 
			
		||||
        [UserPerm(GuildPerm.ManageMessages)]
 | 
			
		||||
@@ -149,7 +175,7 @@ public partial class Utility
 | 
			
		||||
            foreach (var runner in repeaters.OrderBy(r => r.Repeater.Id))
 | 
			
		||||
            {
 | 
			
		||||
                var description = GetRepeaterInfoString(runner);
 | 
			
		||||
                var name = $"#`{++i}`";
 | 
			
		||||
                var name = $"#`{++i}` {(_service.IsRepeaterSkipped(runner.Repeater.Id) ? "🦘" : "")}";
 | 
			
		||||
                embed.AddField(name, description);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
using LinqToDB;
 | 
			
		||||
using LinqToDB.EntityFrameworkCore;
 | 
			
		||||
using Microsoft.EntityFrameworkCore;
 | 
			
		||||
using Nadeko.Common;
 | 
			
		||||
using NadekoBot.Common.ModuleBehaviors;
 | 
			
		||||
using NadekoBot.Services.Database.Models;
 | 
			
		||||
 | 
			
		||||
@@ -16,6 +15,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
 | 
			
		||||
    private readonly DiscordSocketClient _client;
 | 
			
		||||
    private readonly LinkedList<RunningRepeater> _repeaterQueue;
 | 
			
		||||
    private readonly ConcurrentHashSet<int> _noRedundant;
 | 
			
		||||
    private readonly ConcurrentHashSet<int> _skipNext = new();
 | 
			
		||||
 | 
			
		||||
    private readonly object _queueLocker = new();
 | 
			
		||||
 | 
			
		||||
@@ -82,7 +82,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
 | 
			
		||||
 | 
			
		||||
                // execute
 | 
			
		||||
                foreach (var chunk in toExecute.Chunk(5))
 | 
			
		||||
                    await chunk.Select(Trigger).WhenAll();
 | 
			
		||||
                    await chunk.Where(x => !_skipNext.TryRemove(x.Repeater.Id)).Select(Trigger).WhenAll();
 | 
			
		||||
 | 
			
		||||
                // reinsert
 | 
			
		||||
                foreach (var rep in toExecute)
 | 
			
		||||
@@ -396,6 +396,27 @@ public sealed class RepeaterService : IReadyExecutor, INService
 | 
			
		||||
        return newValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async Task<bool?> ToggleSkipNextAsync(ulong guildId, int index)
 | 
			
		||||
    {
 | 
			
		||||
        await using var ctx = _db.GetDbContext();
 | 
			
		||||
        var toSkip = await ctx.Repeaters
 | 
			
		||||
            .Where(x => x.GuildId == guildId)
 | 
			
		||||
            .Skip(index)
 | 
			
		||||
            .FirstOrDefaultAsyncEF();
 | 
			
		||||
 | 
			
		||||
        if (toSkip is null)
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
        if (_skipNext.Add(toSkip.Id))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        _skipNext.TryRemove(toSkip.Id);
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public bool IsNoRedundant(int repeaterId)
 | 
			
		||||
        => _noRedundant.Contains(repeaterId);
 | 
			
		||||
 | 
			
		||||
    public bool IsRepeaterSkipped(int repeaterId)
 | 
			
		||||
        => _skipNext.Contains(repeaterId);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user