Ejemplo n.º 1
0
        public async Task ExportAsync(string token, string channelId, string filePath, ExportFormat format, DateTime?from,
                                      DateTime?to)
        {
            // Get channel and guild
            var channel = await _dataService.GetChannelAsync(token, channelId);

            var guild = channel.GuildId == Guild.DirectMessages.Id
                ? Guild.DirectMessages
                : await _dataService.GetGuildAsync(token, channel.GuildId);

            // Generate file path if not set
            if (filePath.IsBlank())
            {
                filePath = $"{guild.Name} - {channel.Name}.{format.GetFileExtension()}"
                           .Replace(Path.GetInvalidFileNameChars(), '_');
            }

            // Get messages
            var messages = await _dataService.GetChannelMessagesAsync(token, channelId, from, to);

            // Group them
            var messageGroups = _messageGroupService.GroupMessages(messages);

            // Create log
            var log = new ChannelChatLog(guild, channel, messageGroups, messages.Count);

            // Export
            await _exportService.ExportAsync(format, filePath, log);
        }
Ejemplo n.º 2
0
        public static string GetDefaultExportFileName(ExportFormat format, Guild guild, Channel channel = null,
                                                      DateTimeOffset?after = null, DateTimeOffset?before = null)
        {
            var result = new StringBuilder();

            // Append guild and channel names
            result.Append($"{guild.Id}");
            if (channel == null)
            {
                result.Append("-Message");
            }
            else
            {
                result.Append($" - {channel.Name} [{channel.Id}]");

                // Append date range
                if (after != null || before != null)
                {
                    result.Append(" (");

                    // Both 'after' and 'before' are set
                    if (after != null && before != null)
                    {
                        result.Append($"{after:yyyy-MM-dd} to {before:yyyy-MM-dd}");
                    }
                    // Only 'after' is set
                    else if (after != null)
                    {
                        result.Append($"after {after:yyyy-MM-dd}");
                    }
                    // Only 'before' is set
                    else
                    {
                        result.Append($"before {before:yyyy-MM-dd}");
                    }

                    result.Append(")");
                }
            }

            // Append extension
            result.Append($".{format.GetFileExtension()}");

            // Replace invalid chars
            foreach (var invalidChar in Path.GetInvalidFileNameChars())
            {
                result.Replace(invalidChar, '_');
            }

            return(result.ToString());
        }
        public static string GetDefaultExportFileName(
            Guild guild,
            Channel channel,
            ExportFormat format,
            DateTimeOffset?after  = null,
            DateTimeOffset?before = null)
        {
            var buffer = new StringBuilder();

            // Guild and channel names
            buffer.Append($"{guild.Name} - {channel.Category} - {channel.Name} [{channel.Id}]");

            // Date range
            if (after != null || before != null)
            {
                buffer.Append(" (");

                // Both 'after' and 'before' are set
                if (after != null && before != null)
                {
                    buffer.Append($"{after:yyyy-MM-dd} to {before:yyyy-MM-dd}");
                }
                // Only 'after' is set
                else if (after != null)
                {
                    buffer.Append($"after {after:yyyy-MM-dd}");
                }
                // Only 'before' is set
                else
                {
                    buffer.Append($"before {before:yyyy-MM-dd}");
                }

                buffer.Append(")");
            }

            // File extension
            buffer.Append($".{format.GetFileExtension()}");

            // Replace invalid chars
            foreach (var invalidChar in Path.GetInvalidFileNameChars())
            {
                buffer.Replace(invalidChar, '_');
            }

            return(buffer.ToString());
        }
Ejemplo n.º 4
0
        public static string GetDefaultExportFileName(ExportFormat format, Guild guild, Channel channel,
                                                      DateTime?from = null, DateTime?to = null)
        {
            var result = new StringBuilder();

            // Append guild and channel names
            result.Append($"{guild.Name} - {channel.Name} [{channel.Id}]");

            // Append date range
            if (from != null || to != null)
            {
                result.Append(" (");

                // Both 'from' and 'to' are set
                if (from != null && to != null)
                {
                    result.Append($"{from:yyyy-MM-dd} to {to:yyyy-MM-dd}");
                }
                // Only 'from' is set
                else if (from != null)
                {
                    result.Append($"after {from:yyyy-MM-dd}");
                }
                // Only 'to' is set
                else
                {
                    result.Append($"before {to:yyyy-MM-dd}");
                }

                result.Append(")");
            }

            // Append extension
            result.Append($".{format.GetFileExtension()}");

            // Replace invalid chars
            foreach (var invalidChar in Path.GetInvalidFileNameChars())
            {
                result.Replace(invalidChar, '_');
            }

            return(result.ToString());
        }
Ejemplo n.º 5
0
        public static string GetDefaultExportFileName(ExportFormat format, Guild guild, string remark)
        {
            var result = new StringBuilder();

            // Append guild and channel names
            result.Append($"{guild.Id}-{remark}");


            // Append extension
            result.Append($".{format.GetFileExtension()}");

            // Replace invalid chars
            foreach (var invalidChar in Path.GetInvalidFileNameChars())
            {
                result.Replace(invalidChar, '_');
            }

            return(result.ToString());
        }
Ejemplo n.º 6
0
        internal static string GetPath(string channelId, ExportFormat exportType)
        {
            var nowhex = DateTime.Now.Ticks.ToString("X2");

            return($"/tmp/exports/{nowhex}/{channelId}.{exportType.GetFileExtension()}");
        }
 public string GetPath(ExportFormat format)
 {
     return($"{ResourceRootNamespace}.{format}.{format.GetFileExtension()}");
 }