public async Task <IActionResult> ChannelDesignations() { var designatedChannels = await ChannelService.GetDesignatedChannelsAsync(ModixAuth.CurrentGuildId.Value); var mapped = designatedChannels.Select(d => new DesignatedChannelApiData { Id = d.Id, ChannelId = d.Channel.Id, ChannelDesignation = d.Type, Name = UserGuild?.GetChannel(d.Channel.Id)?.Name ?? d.Channel.Id.ToString() }); return(Ok(mapped)); }
public async Task <IActionResult> GetDeletionContext(long batchId) { var deletedMessages = await ModerationService.SearchDeletedMessagesAsync(new DeletedMessageSearchCriteria { BatchId = batchId }, new SortingCriteria[] { //Sort ascending, so the earliest message is first new SortingCriteria { PropertyName = nameof(DeletedMessageSummary.MessageId), Direction = SortDirection.Ascending } }, new PagingCriteria()); var firstMessage = deletedMessages.Records.FirstOrDefault(); if (firstMessage == null) { return(NotFound($"Couldn't find messages for batch id {batchId}")); } var batchChannelId = deletedMessages.Records.First().Channel.Id; var foundChannel = UserGuild.GetChannel(batchChannelId) as ISocketMessageChannel; if (foundChannel == null) { return(NotFound($"Couldn't recreate context - text channel with id {batchChannelId} not found")); } if (SocketUser.GetPermissions(foundChannel as IGuildChannel).ReadMessageHistory == false) { return(Unauthorized($"You don't have read permissions for the channel this batch was deleted in (#{foundChannel.Name})")); } var beforeMessages = await foundChannel.GetMessagesAsync(firstMessage.MessageId, Direction.Before, 25).FlattenAsync(); var afterMessages = await foundChannel.GetMessagesAsync(firstMessage.MessageId, Direction.After, 25 + (int)deletedMessages.FilteredRecordCount).FlattenAsync(); var allMessages = new List <DeletedMessageAbstraction>(); allMessages.AddRange(deletedMessages.Records.Select(d => DeletedMessageAbstraction.FromSummary(d))); allMessages.AddRange(beforeMessages.Select(d => DeletedMessageAbstraction.FromIMessage(d))); allMessages.AddRange(afterMessages.Select(d => DeletedMessageAbstraction.FromIMessage(d))); var sorted = allMessages.OrderBy(d => d.MessageId); return(Ok(sorted)); }