mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	Removed music playlist and warning repositories
This commit is contained in:
		@@ -11,10 +11,8 @@ namespace NadekoBot.Core.Services.Database
 | 
			
		||||
        IQuoteRepository Quotes { get; }
 | 
			
		||||
        IGuildConfigRepository GuildConfigs { get; }
 | 
			
		||||
        ICustomReactionRepository CustomReactions { get; }
 | 
			
		||||
        IMusicPlaylistRepository MusicPlaylists { get; }
 | 
			
		||||
        IWaifuRepository Waifus { get; }
 | 
			
		||||
        IDiscordUserRepository DiscordUsers { get; }
 | 
			
		||||
        IWarningsRepository Warnings { get; }
 | 
			
		||||
        IXpRepository Xp { get; }
 | 
			
		||||
 | 
			
		||||
        int SaveChanges();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +0,0 @@
 | 
			
		||||
using NadekoBot.Core.Services.Database.Models;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Core.Services.Database.Repositories
 | 
			
		||||
{
 | 
			
		||||
    public interface IMusicPlaylistRepository : IRepository<MusicPlaylist>
 | 
			
		||||
    {
 | 
			
		||||
        List<MusicPlaylist> GetPlaylistsOnPage(int num);
 | 
			
		||||
        MusicPlaylist GetWithSongs(int id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,13 +0,0 @@
 | 
			
		||||
using NadekoBot.Core.Services.Database.Models;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Core.Services.Database.Repositories
 | 
			
		||||
{
 | 
			
		||||
    public interface IWarningsRepository : IRepository<Warning>
 | 
			
		||||
    {
 | 
			
		||||
        Warning[] ForId(ulong guildId, ulong userId);
 | 
			
		||||
        Task ForgiveAll(ulong guildId, ulong userId, string moderator);
 | 
			
		||||
        bool Forgive(ulong guildId, ulong userId, string moderator, int index);
 | 
			
		||||
        Warning[] GetForGuild(ulong id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Xp.Common
 | 
			
		||||
        public static ClubInfo GetByMember(this DbSet<ClubInfo> clubs, ulong userId)
 | 
			
		||||
            => Include(clubs).FirstOrDefault(c => c.Users.Any(u => u.UserId == userId));
 | 
			
		||||
 | 
			
		||||
        public static ClubInfo? GetByName(this DbSet<ClubInfo> clubs, string name, int discrim)
 | 
			
		||||
        public static ClubInfo GetByName(this DbSet<ClubInfo> clubs, string name, int discrim)
 | 
			
		||||
            => Include(clubs).FirstOrDefault(c => c.Name.ToUpper() == name.ToUpper() && c.Discrim == discrim);
 | 
			
		||||
 | 
			
		||||
        public static int GetNextDiscrim(this DbSet<ClubInfo> clubs, string name)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,28 +4,26 @@ using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using Microsoft.EntityFrameworkCore;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
 | 
			
		||||
namespace NadekoBot.Modules.Music
 | 
			
		||||
{
 | 
			
		||||
    public class MusicPlaylistRepository : Repository<MusicPlaylist>, IMusicPlaylistRepository
 | 
			
		||||
    public static class MusicPlaylistExtensions
 | 
			
		||||
    {
 | 
			
		||||
        public MusicPlaylistRepository(DbContext context) : base(context)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public List<MusicPlaylist> GetPlaylistsOnPage(int num)
 | 
			
		||||
        public static List<MusicPlaylist> GetPlaylistsOnPage(this DbSet<MusicPlaylist> playlists, int num)
 | 
			
		||||
        {
 | 
			
		||||
            if (num < 1)
 | 
			
		||||
                throw new IndexOutOfRangeException();
 | 
			
		||||
 | 
			
		||||
            return _set.AsQueryable()
 | 
			
		||||
            return playlists
 | 
			
		||||
                .AsQueryable()
 | 
			
		||||
                .Skip((num - 1) * 20)
 | 
			
		||||
                .Take(20)
 | 
			
		||||
                .Include(pl => pl.Songs)
 | 
			
		||||
                .ToList();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public MusicPlaylist GetWithSongs(int id) => 
 | 
			
		||||
            _set.Include(mpl => mpl.Songs)
 | 
			
		||||
        public static MusicPlaylist GetWithSongs(this DbSet<MusicPlaylist> playlists, int id) => 
 | 
			
		||||
            playlists
 | 
			
		||||
                .Include(mpl => mpl.Songs)
 | 
			
		||||
                .FirstOrDefault(mpl => mpl.Id == id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -4,28 +4,25 @@ using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
 | 
			
		||||
namespace NadekoBot.Modules.Administration.Common
 | 
			
		||||
{
 | 
			
		||||
    public class WarningsRepository : Repository<Warning>, IWarningsRepository
 | 
			
		||||
    public static class WarningExtensions
 | 
			
		||||
    {
 | 
			
		||||
        public WarningsRepository(DbContext context) : base(context)
 | 
			
		||||
        public static Warning[] ForId(this DbSet<Warning> warnings, ulong guildId, ulong userId)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Warning[] ForId(ulong guildId, ulong userId)
 | 
			
		||||
        {
 | 
			
		||||
            var query = _set.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
 | 
			
		||||
            var query = warnings.AsQueryable()
 | 
			
		||||
                .Where(x => x.GuildId == guildId && x.UserId == userId)
 | 
			
		||||
                .OrderByDescending(x => x.DateAdded);
 | 
			
		||||
 | 
			
		||||
            return query.ToArray();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Forgive(ulong guildId, ulong userId, string mod, int index)
 | 
			
		||||
        public static bool Forgive(this DbSet<Warning> warnings, ulong guildId, ulong userId, string mod, int index)
 | 
			
		||||
        {
 | 
			
		||||
            if (index < 0)
 | 
			
		||||
                throw new ArgumentOutOfRangeException(nameof(index));
 | 
			
		||||
 | 
			
		||||
            var warn = _set.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
 | 
			
		||||
            var warn = warnings.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
 | 
			
		||||
                .OrderByDescending(x => x.DateAdded)
 | 
			
		||||
                .Skip(index)
 | 
			
		||||
                .FirstOrDefault();
 | 
			
		||||
@@ -38,9 +35,9 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task ForgiveAll(ulong guildId, ulong userId, string mod)
 | 
			
		||||
        public static async Task ForgiveAll(this DbSet<Warning> warnings, ulong guildId, ulong userId, string mod)
 | 
			
		||||
        {
 | 
			
		||||
            await _set.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
 | 
			
		||||
            await warnings.AsQueryable().Where(x => x.GuildId == guildId && x.UserId == userId)
 | 
			
		||||
                .ForEachAsync(x =>
 | 
			
		||||
                {
 | 
			
		||||
                    if (x.Forgiven != true)
 | 
			
		||||
@@ -51,9 +48,9 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
 | 
			
		||||
                });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Warning[] GetForGuild(ulong id)
 | 
			
		||||
        public static Warning[] GetForGuild(this DbSet<Warning> warnings, ulong id)
 | 
			
		||||
        {
 | 
			
		||||
            return _set.AsQueryable().Where(x => x.GuildId == id).ToArray();
 | 
			
		||||
            return warnings.AsQueryable().Where(x => x.GuildId == id).ToArray();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -15,9 +15,6 @@ namespace NadekoBot.Core.Services.Database
 | 
			
		||||
        private IGuildConfigRepository _guildConfigs;
 | 
			
		||||
        public IGuildConfigRepository GuildConfigs => _guildConfigs ?? (_guildConfigs = new GuildConfigRepository(_context));
 | 
			
		||||
 | 
			
		||||
        private IMusicPlaylistRepository _musicPlaylists;
 | 
			
		||||
        public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
 | 
			
		||||
 | 
			
		||||
        private ICustomReactionRepository _customReactions;
 | 
			
		||||
        public ICustomReactionRepository CustomReactions => _customReactions ?? (_customReactions = new CustomReactionsRepository(_context));
 | 
			
		||||
 | 
			
		||||
@@ -27,9 +24,6 @@ namespace NadekoBot.Core.Services.Database
 | 
			
		||||
        private IDiscordUserRepository _discordUsers;
 | 
			
		||||
        public IDiscordUserRepository DiscordUsers => _discordUsers ?? (_discordUsers = new DiscordUserRepository(_context));
 | 
			
		||||
 | 
			
		||||
        private IWarningsRepository _warnings;
 | 
			
		||||
        public IWarningsRepository Warnings => _warnings ?? (_warnings = new WarningsRepository(_context));
 | 
			
		||||
 | 
			
		||||
        private IXpRepository _xp;
 | 
			
		||||
        public IXpRepository Xp => _xp ?? (_xp = new XpRepository(_context));
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user