diff --git a/DiscordArchiver/DiscordArchiver.csproj b/DiscordArchiver/DiscordArchiver.csproj index e399c9f..6dfffa4 100644 --- a/DiscordArchiver/DiscordArchiver.csproj +++ b/DiscordArchiver/DiscordArchiver.csproj @@ -32,28 +32,8 @@ 4 - - ..\packages\Discord.Net.0.9.0-rc3-3\lib\net45\Discord.Net.dll - True - - - ..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.dll - True - - - ..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.Concurrent.dll - True - - - ..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.Enlightenment.dll - True - - - ..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True @@ -64,10 +44,6 @@ - - ..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll - True - diff --git a/DiscordArchiver/Program.cs b/DiscordArchiver/Program.cs index 511b51b..3ea94b4 100644 --- a/DiscordArchiver/Program.cs +++ b/DiscordArchiver/Program.cs @@ -16,9 +16,10 @@ class Program { public static string BaseUrl = "https://discordapp.com/api/channels/{0}/messages?token={1}&before={2}&limit={3}"; public static string Channel, Token, Out = "out.json", Before = "", After = ""; - public static int Limit = 50; + public static int Limit = 100; static void Main(string[] args) { + Channel = args[0]; Token = args[1]; @@ -35,47 +36,53 @@ static void Main(string[] args) { int.TryParse(args[5], out Limit); } - List fullLogs = new List(); + var fullLogs = new List(); + + var counter = 0; + var exit = false; + var bw = new BackgroundWorker(); - int counter = 0; - bool exit = false; - BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (sender, eventArgs) => { while (true) { counter++; - Console.WriteLine($"Downloading Log Part {counter}"); + Console.WriteLine($"Downloading Logs Part {counter}"); - string currentLog = ""; - using (WebClient wc = new WebClient()) { + var currentLog = ""; + using (var wc = new WebClient()) { currentLog = wc.DownloadString(string.Format(BaseUrl, Channel, Token, Before, Limit)); } - Console.WriteLine($"Downloaded Log Part {counter}"); - - Console.WriteLine($"Parsing Log Part {counter}"); + Console.WriteLine($"Downloaded Log Part {counter}, Parsing"); - JArray jar = JArray.Parse(currentLog); + var jar = JArray.Parse(currentLog); Before = jar[jar.Count - 1]["id"].ToString(); - - int g = -1; - int mg = -1; - foreach (JToken jToken in jar) { + Console.WriteLine($"Before: {Before}"); + var g = -1; + var mg = -1; + foreach (var jToken in jar) { g++; - if ((string) jToken["id"] != After) continue; + if ((string)jToken["id"] != After) continue; mg = g; break; } if (mg > -1) { exit = true; - for (int i = mg; i < jar.Count - 1; i++) { + for (var i = mg; i < jar.Count - 1; i++) { jar.RemoveAt(i); } } - - fullLogs.InsertRange(0,JArray.Parse(currentLog).Select(jToken => jToken.ToObject()).Reverse().ToList()); - Thread.Sleep(300); + + fullLogs.InsertRange(0, JArray.Parse(currentLog).Select(jToken => jToken.ToObject()).Reverse().ToList()); + + if (counter % 50 == 0) { + Console.WriteLine($"Writing partial logs to file {Out}"); + File.WriteAllText(Out, JsonConvert.SerializeObject(fullLogs, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto })); + } + + Thread.Sleep(500); + if (jar.Count < Limit || exit) break; } }; diff --git a/DiscordArchiver/data/DAuthor.cs b/DiscordArchiver/data/DAuthor.cs index 6067d48..bcb304c 100644 --- a/DiscordArchiver/data/DAuthor.cs +++ b/DiscordArchiver/data/DAuthor.cs @@ -1,11 +1,9 @@ namespace DiscordArchiver.data { public class DAuthor { - public string username; - public string discriminator; - public string id; + public ushort discriminator; + public ulong id; public string avatar; - } -} +} \ No newline at end of file diff --git a/DiscordArchiver/data/DMessage.cs b/DiscordArchiver/data/DMessage.cs index 2c8d844..b79a24e 100644 --- a/DiscordArchiver/data/DMessage.cs +++ b/DiscordArchiver/data/DMessage.cs @@ -1,18 +1,12 @@ using System; namespace DiscordArchiver.data { - public class DMessage { - public DAttachment[] attachments; - public bool tts; - public DEmbed[] embeds; - public DateTime? timestamp; - public bool mention_everyone; - public string id; - public DateTime? edited_timestamp; + public DateTime timestamp; + public ulong id; public DAuthor author; public string content; - public string channel_id; + public ulong channel_id; public DAuthor[] mentions; } -} \ No newline at end of file +} diff --git a/DiscordArchiver/packages.config b/DiscordArchiver/packages.config index 53be512..a808feb 100644 --- a/DiscordArchiver/packages.config +++ b/DiscordArchiver/packages.config @@ -1,7 +1,7 @@  - + diff --git a/README.md b/README.md index 0e54ffd..8f588ac 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ Dl and archive Discord chat logs Usage: -DiscordArchiver.exe [outputfile] [before message id] [after message id] [message limit per request] +DiscordArchiver.exe (channelid) (token) [outputfile] [before message id] [after message id] [message limit per request]