Added .filterlist command

This commit is contained in:
Kwoth
2022-10-16 22:57:36 +02:00
parent 1a132fd234
commit 584193db18
6 changed files with 81 additions and 0 deletions

View File

@@ -2,6 +2,12 @@
Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
## Unreleased
### Added
- `.filterlist` / `.fl` command which lists link and invite filtering channels and status
## [4.3.9] - 12.10.2022
### Added

View File

@@ -25,6 +25,47 @@ public partial class Permissions
await ReplyConfirmLocalizedAsync(strs.fw_cleared);
}
[Cmd]
[RequireContext(ContextType.Guild)]
public async Task FilterList()
{
var embed = _eb.Create(ctx)
.WithOkColor()
.WithTitle("Server filter settings");
var config = await _service.GetFilterSettings(ctx.Guild.Id);
string GetEnabledEmoji(bool value)
=> value ? "\\🟢" : "\\🔴";
async Task<string> GetChannelListAsync(IReadOnlyCollection<ulong> channels)
{
var toReturn = (await channels
.Select(async cid =>
{
var ch = await ctx.Guild.GetChannelAsync(cid);
return ch is null
? $"{cid} *missing*"
: $"<#{cid}>";
})
.WhenAll())
.Join('\n');
if (string.IsNullOrWhiteSpace(toReturn))
return GetText(strs.no_channel_found);
return toReturn;
}
embed.AddField($"{GetEnabledEmoji(config.FilterLinksEnabled)} Filter Links",
await GetChannelListAsync(config.FilterLinksChannels));
embed.AddField($"{GetEnabledEmoji(config.FilterInvitesEnabled)} Filter Invites",
await GetChannelListAsync(config.FilterInvitesChannels));
await ctx.Channel.EmbedAsync(embed);
}
[Cmd]
[RequireContext(ContextType.Guild)]
public async Task SrvrFilterInv()

View File

@@ -1,4 +1,5 @@
#nullable disable
using AngleSharp.Dom;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Db;
@@ -222,4 +223,20 @@ public sealed class FilterService : IExecOnMessage
return false;
}
public async Task<ServerFilterSettings> GetFilterSettings(ulong guildId)
{
await using var uow = _db.GetDbContext();
var gc = uow.GuildConfigsForId(guildId, set => set
.Include(x => x.FilterInvitesChannelIds)
.Include(x => x.FilterLinksChannelIds));
return new()
{
FilterInvitesChannels = gc.FilterInvitesChannelIds.Map(x => x.ChannelId),
FilterLinksChannels = gc.FilterLinksChannelIds.Map(x => x.ChannelId),
FilterInvitesEnabled = gc.FilterInvites,
FilterLinksEnabled = gc.FilterLinks,
};
}
}

View File

@@ -0,0 +1,10 @@
#nullable disable
namespace NadekoBot.Modules.Permissions.Services;
public readonly struct ServerFilterSettings
{
public bool FilterInvitesEnabled { get; init; }
public bool FilterLinksEnabled { get; init; }
public IReadOnlyCollection<ulong> FilterInvitesChannels { get; init; }
public IReadOnlyCollection<ulong> FilterLinksChannels { get; init; }
}

View File

@@ -246,6 +246,9 @@ roles:
channeltopic:
- channeltopic
- ct
filterlist:
- filterlist
- fl
chnlfilterinv:
- chnlfilterinv
- cfi

View File

@@ -236,6 +236,10 @@ fwclear:
desc: "Deletes all filtered words on this server."
args:
- ""
filterlist:
desc: "Lists invite and link filter channels and status."
args:
- ""
aliasesclear:
desc: "Deletes all aliases on this server."
args: