feat(dashboard): working ignored channels page
This commit is contained in:
parent
1c43beb82f
commit
bccf7caf34
13 changed files with 304 additions and 8 deletions
112
Catalogger.Backend/Api/GuildsController.Ignores.cs
Normal file
112
Catalogger.Backend/Api/GuildsController.Ignores.cs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
// Copyright (C) 2021-present sam (starshines.gay)
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published
|
||||
// by the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using Catalogger.Backend.Database.Queries;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Remora.Discord.API;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
|
||||
namespace Catalogger.Backend.Api;
|
||||
|
||||
public partial class GuildsController
|
||||
{
|
||||
[HttpPut("ignored-channels/{channelId}")]
|
||||
public async Task<IActionResult> AddIgnoredChannelAsync(string id, ulong channelId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
|
||||
if (guildConfig.Channels.IgnoredChannels.Contains(channelId))
|
||||
return NoContent();
|
||||
|
||||
var channel = channelCache
|
||||
.GuildChannels(guildId)
|
||||
.FirstOrDefault(c =>
|
||||
c.ID.Value == channelId
|
||||
&& c.Type
|
||||
is ChannelType.GuildText
|
||||
or ChannelType.GuildCategory
|
||||
or ChannelType.GuildAnnouncement
|
||||
or ChannelType.GuildForum
|
||||
or ChannelType.GuildMedia
|
||||
or ChannelType.GuildVoice
|
||||
);
|
||||
if (channel == null)
|
||||
return NoContent();
|
||||
|
||||
guildConfig.Channels.IgnoredChannels.Add(channelId);
|
||||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("ignored-channels/{channelId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredChannelAsync(string id, ulong channelId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
|
||||
guildConfig.Channels.IgnoredChannels.Remove(channelId);
|
||||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("users")]
|
||||
public async Task<IActionResult> ListUsersAsync(string id, [FromQuery] string query)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var members = await memberCache.GetMemberNamesAsync(guildId, query);
|
||||
|
||||
return Ok(members.OrderBy(m => m.Name).Select(m => new UserQueryResponse(m.Name, m.Id)));
|
||||
}
|
||||
|
||||
private record UserQueryResponse(string Name, string Id);
|
||||
|
||||
[HttpPut("ignored-users/{userId}")]
|
||||
public async Task<IActionResult> AddIgnoredUserAsync(string id, ulong userId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
|
||||
if (guildConfig.Channels.IgnoredUsers.Contains(userId))
|
||||
return NoContent();
|
||||
|
||||
var user = await memberCache.TryGetAsync(guildId, DiscordSnowflake.New(userId));
|
||||
if (user == null)
|
||||
return NoContent();
|
||||
|
||||
guildConfig.Channels.IgnoredUsers.Add(userId);
|
||||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("ignored-users/{userId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredUserAsync(string id, ulong userId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
|
||||
guildConfig.Channels.IgnoredUsers.Remove(userId);
|
||||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue