mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-23 03:06:53 -04:00
parent
28a67ab60d
commit
01f0e6952d
7 changed files with 73 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
using DiscordChatExporter.Models;
|
||||
using System;
|
||||
using DiscordChatExporter.Models;
|
||||
|
||||
namespace DiscordChatExporter.Messages
|
||||
{
|
||||
|
@ -10,11 +11,18 @@ namespace DiscordChatExporter.Messages
|
|||
|
||||
public ExportFormat Format { get; }
|
||||
|
||||
public StartExportMessage(Channel channel, string filePath, ExportFormat format)
|
||||
public DateTime? From { get; }
|
||||
|
||||
public DateTime? To { get; }
|
||||
|
||||
public StartExportMessage(Channel channel, string filePath, ExportFormat format,
|
||||
DateTime? from, DateTime? to)
|
||||
{
|
||||
Channel = channel;
|
||||
FilePath = filePath;
|
||||
Format = format;
|
||||
From = from;
|
||||
To = to;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -71,7 +71,7 @@ namespace DiscordChatExporter.Services
|
|||
return channels;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Message>> GetChannelMessagesAsync(string token, string channelId)
|
||||
public async Task<IReadOnlyList<Message>> GetChannelMessagesAsync(string token, string channelId, DateTime? from, DateTime? to)
|
||||
{
|
||||
var result = new List<Message>();
|
||||
|
||||
|
@ -102,6 +102,9 @@ namespace DiscordChatExporter.Services
|
|||
// If no messages - break
|
||||
if (currentMessageId == null) break;
|
||||
|
||||
// If last message is older than from date - break
|
||||
if (from != null && result.Last().TimeStamp < from) break;
|
||||
|
||||
// Otherwise offset the next request
|
||||
beforeId = currentMessageId;
|
||||
}
|
||||
|
@ -109,6 +112,12 @@ namespace DiscordChatExporter.Services
|
|||
// Messages appear newest first, we need to reverse
|
||||
result.Reverse();
|
||||
|
||||
// Filter
|
||||
if (from != null)
|
||||
result.RemoveAll(m => m.TimeStamp < from);
|
||||
if (to != null)
|
||||
result.RemoveAll(m => m.TimeStamp > to);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Models;
|
||||
|
||||
|
@ -12,6 +13,7 @@ namespace DiscordChatExporter.Services
|
|||
|
||||
Task<IReadOnlyList<Channel>> GetGuildChannelsAsync(string token, string guildId);
|
||||
|
||||
Task<IReadOnlyList<Message>> GetChannelMessagesAsync(string token, string channelId);
|
||||
Task<IReadOnlyList<Message>> GetChannelMessagesAsync(string token, string channelId,
|
||||
DateTime? from, DateTime? to);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,8 @@ namespace DiscordChatExporter.ViewModels
|
|||
|
||||
private string _filePath;
|
||||
private ExportFormat _format;
|
||||
private DateTime? _from;
|
||||
private DateTime? _to;
|
||||
|
||||
public Guild Guild { get; private set; }
|
||||
|
||||
|
@ -40,6 +42,18 @@ namespace DiscordChatExporter.ViewModels
|
|||
set => Set(ref _format, value);
|
||||
}
|
||||
|
||||
public DateTime? From
|
||||
{
|
||||
get => _from;
|
||||
set => Set(ref _from, value);
|
||||
}
|
||||
|
||||
public DateTime? To
|
||||
{
|
||||
get => _to;
|
||||
set => Set(ref _to, value);
|
||||
}
|
||||
|
||||
// Commands
|
||||
public RelayCommand ExportCommand { get; }
|
||||
|
||||
|
@ -59,14 +73,17 @@ namespace DiscordChatExporter.ViewModels
|
|||
Guild = m.Guild;
|
||||
Channel = m.Channel;
|
||||
SelectedFormat = _settingsService.LastExportFormat;
|
||||
FilePath = Path.Combine($"{Guild} - {Channel}.{SelectedFormat.GetFileExtension()}");
|
||||
FilePath = $"{Guild} - {Channel}.{SelectedFormat.GetFileExtension()}"
|
||||
.Replace(Path.GetInvalidFileNameChars(), '_');
|
||||
From = null;
|
||||
To = null;
|
||||
});
|
||||
}
|
||||
|
||||
private void Export()
|
||||
{
|
||||
_settingsService.LastExportFormat = SelectedFormat;
|
||||
MessengerInstance.Send(new StartExportMessage(Channel, FilePath, SelectedFormat));
|
||||
MessengerInstance.Send(new StartExportMessage(Channel, FilePath, SelectedFormat, From, To));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscordChatExporter.Models;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
|
||||
|
@ -11,6 +12,8 @@ namespace DiscordChatExporter.ViewModels
|
|||
string FilePath { get; set; }
|
||||
IReadOnlyList<ExportFormat> AvailableFormats { get; }
|
||||
ExportFormat SelectedFormat { get; set; }
|
||||
DateTime? From { get; set; }
|
||||
DateTime? To { get; set; }
|
||||
|
||||
RelayCommand ExportCommand { get; }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
@ -104,7 +105,7 @@ namespace DiscordChatExporter.ViewModels
|
|||
// Messages
|
||||
MessengerInstance.Register<StartExportMessage>(this, m =>
|
||||
{
|
||||
Export(m.Channel, m.FilePath, m.Format);
|
||||
Export(m.Channel, m.FilePath, m.Format, m.From, m.To);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -161,14 +162,14 @@ namespace DiscordChatExporter.ViewModels
|
|||
MessengerInstance.Send(new ShowExportSetupMessage(SelectedGuild, channel));
|
||||
}
|
||||
|
||||
private async void Export(Channel channel, string filePath, ExportFormat format)
|
||||
private async void Export(Channel channel, string filePath, ExportFormat format, DateTime? from, DateTime? to)
|
||||
{
|
||||
IsBusy = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Get messages
|
||||
var messages = await _dataService.GetChannelMessagesAsync(_cachedToken, channel.Id);
|
||||
var messages = await _dataService.GetChannelMessagesAsync(_cachedToken, channel.Id, from, to);
|
||||
|
||||
// Group them
|
||||
var messageGroups = _messageGroupService.GroupMessages(messages);
|
||||
|
|
|
@ -33,6 +33,27 @@ UserControl "DiscordChatExporter.Views.ExportSetupDialog" {
|
|||
}
|
||||
}
|
||||
|
||||
// Date range
|
||||
Grid {
|
||||
#TwoColumns("*", "*")
|
||||
|
||||
DatePicker {
|
||||
Grid.Column: 0
|
||||
Margin: "16 16 8 8"
|
||||
HintAssist.Hint: "From"
|
||||
HintAssist.IsFloating: true
|
||||
SelectedDate: bind From
|
||||
}
|
||||
|
||||
DatePicker {
|
||||
Grid.Column: 1
|
||||
Margin: "8 16 16 8"
|
||||
HintAssist.Hint: "To"
|
||||
HintAssist.IsFloating: true
|
||||
SelectedDate: bind To
|
||||
}
|
||||
}
|
||||
|
||||
// Buttons
|
||||
@StackPanelHorizontal {
|
||||
HorizontalAlignment: Right
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue