Added .qdelauth - Delete all quotes by the specified author on this server. If you target yourself - no permission required

This commit is contained in:
Kwoth
2022-08-30 15:46:10 +02:00
parent b69e25edf4
commit fb4f470b44
7 changed files with 100 additions and 32 deletions

View File

@@ -0,0 +1,33 @@
#nullable disable warnings
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using Nadeko.Common;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Utility;
public sealed class QuoteService : IQuoteService, INService
{
private readonly DbService _db;
public QuoteService(DbService db)
{
_db = db;
}
/// <summary>
/// Delete all quotes created by the author in a guild
/// </summary>
/// <param name="guildId">ID of the guild</param>
/// <param name="userId">ID of the user</param>
/// <returns>Number of deleted qutoes</returns>
public async Task<int> DeleteAllAuthorQuotesAsync(ulong guildId, ulong userId)
{
await using var ctx = _db.GetDbContext();
var deleted = await ctx.GetTable<Quote>()
.Where(x => x.GuildId == guildId && x.AuthorId == userId)
.DeleteAsync();
return deleted;
}
}