attempt to add ignored channels page
This commit is contained in:
parent
cb425fe3cd
commit
1c43beb82f
13 changed files with 238 additions and 124 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue