mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Added .qdelauth - Delete all quotes by the specified author on this server. If you target yourself - no permission required
This commit is contained in:
33
src/NadekoBot/Modules/Utility/Quote/QuoteService.cs
Normal file
33
src/NadekoBot/Modules/Utility/Quote/QuoteService.cs
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user