Add support for announcement channels

Closes #222
pull/241/head
Alexey Golub 5 years ago
parent 632b9f953b
commit 0d2ae8b5db

@ -26,7 +26,7 @@ namespace DiscordChatExporter.Cli.Commands
var channels = await DataService.GetGuildChannelsAsync(GetToken(), GuildId);
// Filter and order channels
channels = channels.Where(c => c.Type == ChannelType.GuildTextChat).OrderBy(c => c.Name).ToArray();
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
// Loop through channels
foreach (var channel in channels)

@ -24,7 +24,7 @@ namespace DiscordChatExporter.Cli.Commands
var channels = await DataService.GetGuildChannelsAsync(GetToken(), GuildId);
// Filter and order channels
channels = channels.Where(c => c.Type == ChannelType.GuildTextChat).OrderBy(c => c.Name).ToArray();
channels = channels.Where(c => c.Type.IsExportable()).OrderBy(c => c.Name).ToArray();
// Print result
foreach (var channel in channels)

@ -1,6 +1,7 @@
namespace DiscordChatExporter.Core.Models
{
// https://discordapp.com/developers/docs/resources/channel#channel-object-channel-types
// Order of enum fields needs to match the order in the docs.
public enum ChannelType
{
@ -8,6 +9,8 @@
DirectTextChat,
GuildVoiceChat,
DirectGroupTextChat,
Category
GuildCategory,
GuildNews,
GuildStore
}
}

@ -4,6 +4,13 @@ namespace DiscordChatExporter.Core.Models
{
public static class Extensions
{
public static bool IsExportable(this ChannelType channelType) =>
channelType == ChannelType.GuildTextChat ||
channelType == ChannelType.DirectTextChat ||
channelType == ChannelType.DirectGroupTextChat ||
channelType == ChannelType.GuildNews ||
channelType == ChannelType.GuildStore;
public static string GetFileExtension(this ExportFormat format) =>
format switch
{

@ -4,25 +4,25 @@ using System.Windows.Data;
namespace DiscordChatExporter.Gui.Converters
{
[ValueConversion(typeof(DateTimeOffset), typeof(DateTime))]
[ValueConversion(typeof(DateTimeOffset?), typeof(DateTime?))]
public class DateTimeOffsetToDateTimeConverter : IValueConverter
{
public static DateTimeOffsetToDateTimeConverter Instance { get; } = new DateTimeOffsetToDateTimeConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is DateTimeOffset dateTimeOffsetValue)
return dateTimeOffsetValue.DateTime;
return default(DateTime);
return default(DateTime?);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is DateTime dateTimeValue)
return new DateTimeOffset(dateTimeValue);
return default(DateTimeOffset);
return default(DateTimeOffset?);
}
}
}

@ -201,14 +201,14 @@ namespace DiscordChatExporter.Gui.ViewModels
var channels = await _dataService.GetGuildChannelsAsync(token, guild.Id);
// Get category channels
var categoryChannels = channels.Where(c => c.Type == ChannelType.Category).ToArray();
var categoryChannels = channels.Where(c => c.Type == ChannelType.GuildCategory).ToArray();
// Get text channels
var textChannels = channels.Where(c => c.Type == ChannelType.GuildTextChat).ToArray();
// Get exportable channels
var exportableChannels = channels.Where(c => c.Type.IsExportable()).ToArray();
// Create channel view models
var channelViewModels = new List<ChannelViewModel>();
foreach (var channel in textChannels)
foreach (var channel in exportableChannels)
{
// Get category
var category = categoryChannels.FirstOrDefault(c => c.Id == channel.ParentId)?.Name;

Loading…
Cancel
Save