Compare commits

...

2 Commits

Author SHA1 Message Date
Alexey Golub 7b614ed448 Update version 2019-02-10 17:27:45 +02:00
Alexey Golub 6531462220 Fix getting last message when there's no date range
Fixes #137
2019-02-10 17:26:18 +02:00
5 changed files with 16 additions and 11 deletions
+4
View File
@@ -1,3 +1,7 @@
### v2.9.1 (10-Feb-2019)
- Fixed an issue where some of the last messages in a channel would sometimes not get exported.
### v2.9 (09-Feb-2019) ### v2.9 (09-Feb-2019)
- Added categories to channel list in GUI. Channels are now also grouped by category. - Added categories to channel list in GUI. Channels are now also grouped by category.
@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework> <TargetFramework>net461</TargetFramework>
<Version>2.9</Version> <Version>2.9.1</Version>
<Company>Tyrrrz</Company> <Company>Tyrrrz</Company>
<Copyright>Copyright (c) 2017-2018 Alexey Golub</Copyright> <Copyright>Copyright (c) 2017-2018 Alexey Golub</Copyright>
<ApplicationIcon>..\favicon.ico</ApplicationIcon> <ApplicationIcon>..\favicon.ico</ApplicationIcon>
@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net461</TargetFramework> <TargetFramework>net461</TargetFramework>
<Version>2.9</Version> <Version>2.9.1</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -41,10 +41,15 @@ namespace DiscordChatExporter.Core.Services
: new AuthenticationHeaderValue(token.Value); : new AuthenticationHeaderValue(token.Value);
// Add parameters // Add parameters
foreach (var parameter in parameters) foreach (var parameter in parameters.ExceptBlank())
{ {
var key = parameter.SubstringUntil("="); var key = parameter.SubstringUntil("=");
var value = parameter.SubstringAfter("="); var value = parameter.SubstringAfter("=");
// Skip empty values
if (value.IsBlank())
continue;
request.RequestUri = request.RequestUri.SetQueryParameter(key, value); request.RequestUri = request.RequestUri.SetQueryParameter(key, value);
} }
@@ -123,13 +128,9 @@ namespace DiscordChatExporter.Core.Services
{ {
var result = new List<Message>(); var result = new List<Message>();
// Get the snowflakes for the selected range
var firstId = from != null ? from.Value.ToSnowflake() : "0";
var lastId = to != null ? to.Value.ToSnowflake() : DateTime.MaxValue.ToSnowflake();
// Get the last message // Get the last message
var response = await GetApiResponseAsync(token, "channels", $"{channelId}/messages", var response = await GetApiResponseAsync(token, "channels", $"{channelId}/messages",
"limit=1", $"before={lastId}"); "limit=1", $"before={to?.ToSnowflake()}");
var lastMessage = response.Select(ParseMessage).FirstOrDefault(); var lastMessage = response.Select(ParseMessage).FirstOrDefault();
// If the last message doesn't exist or it's outside of range - return // If the last message doesn't exist or it's outside of range - return
@@ -140,7 +141,7 @@ namespace DiscordChatExporter.Core.Services
} }
// Get other messages // Get other messages
var offsetId = firstId; var offsetId = from?.ToSnowflake() ?? "0";
while (true) while (true)
{ {
// Get message batch // Get message batch
@@ -3,5 +3,5 @@
[assembly: AssemblyTitle("DiscordChatExporter")] [assembly: AssemblyTitle("DiscordChatExporter")]
[assembly: AssemblyCompany("Tyrrrz")] [assembly: AssemblyCompany("Tyrrrz")]
[assembly: AssemblyCopyright("Copyright (c) 2017-2018 Alexey Golub")] [assembly: AssemblyCopyright("Copyright (c) 2017-2018 Alexey Golub")]
[assembly: AssemblyVersion("2.9")] [assembly: AssemblyVersion("2.9.1")]
[assembly: AssemblyFileVersion("2.9")] [assembly: AssemblyFileVersion("2.9.1")]