attempt to add ignored channels page

This commit is contained in:
sam 2024-10-19 23:27:57 +02:00
parent cb425fe3cd
commit 1c43beb82f
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
13 changed files with 238 additions and 124 deletions

View file

@ -18,6 +18,7 @@ using Catalogger.Backend.Api.Middleware;
using Catalogger.Backend.Cache.InMemoryCache;
using Catalogger.Backend.Database;
using Catalogger.Backend.Database.Queries;
using Catalogger.Backend.Database.Redis;
using Microsoft.AspNetCore.Mvc;
using Remora.Discord.API;
using Remora.Discord.API.Abstractions.Objects;
@ -30,16 +31,10 @@ public partial class GuildsController(
Config config,
DatabaseContext db,
ChannelCache channelCache,
RedisService redisService,
DiscordRequestService discordRequestService
) : ApiControllerBase
{
public IActionResult AddGuild(ulong id) =>
Redirect(
$"https://discord.com/oauth2/authorize?client_id={config.Discord.ApplicationId}"
+ "&permissions=537250993&scope=bot%20applications.commands"
+ $"&guild_id={id}"
);
private async Task<(Snowflake GuildId, Guild Guild)> ParseGuildAsync(string id)
{
var guilds = await discordRequestService.GetGuildsAsync(CurrentToken);
@ -135,6 +130,28 @@ public partial class GuildsController(
.ToList();
var guildConfig = await db.GetGuildAsync(guildId);
if (req.IgnoredChannels != null)
{
var categories = channelCache
.GuildChannels(guildId)
.Where(c => c.Type is ChannelType.GuildCategory)
.ToList();
if (
req.IgnoredChannels.Any(cId =>
guildChannels.All(c => c.ID.Value != cId)
&& categories.All(c => c.ID.Value != cId)
)
)
throw new ApiError(
HttpStatusCode.BadRequest,
ErrorCode.BadRequest,
"One or more ignored channels are unknown"
);
guildConfig.Channels.IgnoredChannels = req.IgnoredChannels.ToList();
}
// i love repeating myself wheeeeee
if (
req.GuildUpdate == null
@ -295,6 +312,7 @@ public partial class GuildsController(
}
public record ChannelRequest(
ulong[]? IgnoredChannels = null,
ulong? GuildUpdate = null,
ulong? GuildEmojisUpdate = null,
ulong? GuildRoleCreate = null,