feat(dashboard): ignore messages page, remove ignore channel page
This commit is contained in:
parent
0cac964aa6
commit
19d9f33454
18 changed files with 575 additions and 315 deletions
|
|
@ -13,18 +13,15 @@
|
|||
// 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 System.Net;
|
||||
using Catalogger.Backend.Api.Middleware;
|
||||
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)
|
||||
[HttpPut("ignored-messages/channels/{channelId}")]
|
||||
public async Task<IActionResult> AddIgnoredMessageChannelAsync(string id, ulong channelId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
|
@ -53,8 +50,8 @@ public partial class GuildsController
|
|||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("ignored-channels/{channelId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredChannelAsync(string id, ulong channelId)
|
||||
[HttpDelete("ignored-messages/channels/{channelId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredMessageChannelAsync(string id, ulong channelId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
|
@ -65,40 +62,109 @@ public partial class GuildsController
|
|||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPut("key-roles/{roleId}")]
|
||||
public async Task<IActionResult> AddKeyRoleAsync(string id, ulong roleId)
|
||||
[HttpPut("ignored-messages/roles/{roleId}")]
|
||||
public async Task<IActionResult> AddIgnoredMessageRoleAsync(string id, ulong roleId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
if (guildConfig.Messages.IgnoredRoles.Contains(roleId))
|
||||
return NoContent();
|
||||
|
||||
if (roleCache.GuildRoles(guildId).All(r => r.ID.Value != roleId))
|
||||
throw new ApiError(HttpStatusCode.BadRequest, ErrorCode.BadRequest, "Role not found");
|
||||
return NoContent();
|
||||
|
||||
if (guildConfig.KeyRoles.Contains(roleId))
|
||||
throw new ApiError(
|
||||
HttpStatusCode.BadRequest,
|
||||
ErrorCode.BadRequest,
|
||||
"Role is already a key role"
|
||||
);
|
||||
guildConfig.Messages.IgnoredRoles.Add(roleId);
|
||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
||||
|
||||
await guildRepository.AddKeyRoleAsync(guildId, DiscordSnowflake.New(roleId));
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("key-roles/{roleId}")]
|
||||
public async Task<IActionResult> RemoveKeyRoleAsync(string id, ulong roleId)
|
||||
[HttpDelete("ignored-messages/roles/{roleId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredMessageRoleAsync(string id, ulong roleId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
if (!guildConfig.KeyRoles.Contains(roleId))
|
||||
throw new ApiError(
|
||||
HttpStatusCode.BadRequest,
|
||||
ErrorCode.BadRequest,
|
||||
"Role is already not a key role"
|
||||
);
|
||||
guildConfig.Messages.IgnoredRoles.Remove(roleId);
|
||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPut("ignored-entities/channels/{channelId}")]
|
||||
public async Task<IActionResult> AddIgnoredEntityChannelAsync(string id, ulong channelId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
if (guildConfig.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.IgnoredChannels = [.. guildConfig.IgnoredChannels, channelId];
|
||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("ignored-entities/channels/{channelId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredEntityChannelAsync(string id, ulong channelId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
var channels = guildConfig.IgnoredChannels.ToList();
|
||||
channels.Remove(channelId);
|
||||
guildConfig.IgnoredChannels = channels.ToArray();
|
||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPut("ignored-entities/roles/{roleId}")]
|
||||
public async Task<IActionResult> AddIgnoredEntityRoleAsync(string id, ulong roleId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
if (guildConfig.Messages.IgnoredRoles.Contains(roleId))
|
||||
return NoContent();
|
||||
|
||||
if (roleCache.GuildRoles(guildId).All(r => r.ID.Value != roleId))
|
||||
return NoContent();
|
||||
|
||||
guildConfig.IgnoredRoles = [.. guildConfig.IgnoredRoles, roleId];
|
||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("ignored-entities/roles/{roleId}")]
|
||||
public async Task<IActionResult> RemoveIgnoredEntityRoleAsync(string id, ulong roleId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
var roles = guildConfig.IgnoredRoles.ToList();
|
||||
roles.Remove(roleId);
|
||||
guildConfig.IgnoredRoles = roles.ToArray();
|
||||
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig);
|
||||
|
||||
await guildRepository.RemoveKeyRoleAsync(guildId, DiscordSnowflake.New(roleId));
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue