From fb3b14f1cecfb15b1a53f069d9a1bce8a3f9009c Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Fri, 1 Sep 2017 21:16:18 +0300 Subject: [PATCH] Use var --- DiscordChatExporter/Program.cs | 10 ++++----- .../Services/DiscordApiService.cs | 22 +++++++++---------- .../Services/HtmlExportService.cs | 16 +++++++------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/DiscordChatExporter/Program.cs b/DiscordChatExporter/Program.cs index d040672..83fa3ea 100644 --- a/DiscordChatExporter/Program.cs +++ b/DiscordChatExporter/Program.cs @@ -17,11 +17,11 @@ namespace DiscordChatExporter { // Parse the arguments var argsDic = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (string arg in args) + foreach (var arg in args) { var match = Regex.Match(arg, "/(.*?):\"?(.*?)\"?$"); - string key = match.Groups[1].Value; - string value = match.Groups[2].Value; + var key = match.Groups[1].Value; + var value = match.Groups[2].Value; if (key.IsBlank()) continue; @@ -30,8 +30,8 @@ namespace DiscordChatExporter } // Extract required arguments - string token = argsDic.GetOrDefault("token"); - string channelId = argsDic.GetOrDefault("channelId"); + var token = argsDic.GetOrDefault("token"); + var channelId = argsDic.GetOrDefault("channelId"); // Verify arguments if (token.IsBlank() || channelId.IsBlank()) diff --git a/DiscordChatExporter/Services/DiscordApiService.cs b/DiscordChatExporter/Services/DiscordApiService.cs index 81426e1..0b00bae 100644 --- a/DiscordChatExporter/Services/DiscordApiService.cs +++ b/DiscordChatExporter/Services/DiscordApiService.cs @@ -19,10 +19,10 @@ namespace DiscordChatExporter.Services foreach (var messageJson in messagesJson) { // Get basic data - string id = messageJson.Value("id"); + var id = messageJson.Value("id"); var timeStamp = messageJson.Value("timestamp"); var editedTimeStamp = messageJson.Value("edited_timestamp"); - string content = messageJson.Value("content"); + var content = messageJson.Value("content"); // Lazy workaround for calls if (messageJson["call"] != null) @@ -30,19 +30,19 @@ namespace DiscordChatExporter.Services // Get author var authorJson = messageJson["author"]; - string authorId = authorJson.Value("id"); - string authorName = authorJson.Value("username"); - string authorAvatarHash = authorJson.Value("avatar"); + var authorId = authorJson.Value("id"); + var authorName = authorJson.Value("username"); + var authorAvatarHash = authorJson.Value("avatar"); // Get attachment var attachmentsJson = messageJson["attachments"]; var attachments = new List(); foreach (var attachmentJson in attachmentsJson) { - string attachmentId = attachmentJson.Value("id"); - string attachmentUrl = attachmentJson.Value("url"); - string attachmentFileName = attachmentJson.Value("filename"); - bool attachmentIsImage = attachmentJson["width"] != null; + var attachmentId = attachmentJson.Value("id"); + var attachmentUrl = attachmentJson.Value("url"); + var attachmentFileName = attachmentJson.Value("filename"); + var attachmentIsImage = attachmentJson["width"] != null; var attachment = new Attachment(attachmentId, attachmentUrl, attachmentFileName, attachmentIsImage); attachments.Add(attachment); @@ -65,12 +65,12 @@ namespace DiscordChatExporter.Services while (true) { // Form request url - string url = $"{ApiRoot}/channels/{channelId}/messages?token={token}&limit=100"; + var url = $"{ApiRoot}/channels/{channelId}/messages?token={token}&limit=100"; if (beforeId.IsNotBlank()) url += $"&before={beforeId}"; // Get response - string response = await _httpClient.GetStringAsync(url); + var response = await _httpClient.GetStringAsync(url); // Parse var messages = ParseMessages(response); diff --git a/DiscordChatExporter/Services/HtmlExportService.cs b/DiscordChatExporter/Services/HtmlExportService.cs index aaba431..359a0f8 100644 --- a/DiscordChatExporter/Services/HtmlExportService.cs +++ b/DiscordChatExporter/Services/HtmlExportService.cs @@ -14,7 +14,7 @@ namespace DiscordChatExporter.Services { private HtmlDocument GetTemplate() { - string resourcePath = "DiscordChatExporter.Resources.HtmlExportService.Template.html"; + var resourcePath = "DiscordChatExporter.Resources.HtmlExportService.Template.html"; var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream(resourcePath); @@ -31,7 +31,7 @@ namespace DiscordChatExporter.Services private string GetStyle(Theme theme) { - string resourcePath = $"DiscordChatExporter.Resources.HtmlExportService.{theme}Theme.css"; + var resourcePath = $"DiscordChatExporter.Resources.HtmlExportService.{theme}Theme.css"; var assembly = Assembly.GetExecutingAssembly(); var stream = assembly.GetManifestResourceStream(resourcePath); @@ -56,7 +56,7 @@ namespace DiscordChatExporter.Services var groupFirst = groupBuffer.FirstOrDefault(); // Group break condition - bool breakCondition = + var breakCondition = groupFirst != null && ( message.Author.Id != groupFirst.Author.Id || @@ -125,7 +125,7 @@ namespace DiscordChatExporter.Services public void Export(string filePath, ChatLog chatLog, Theme theme) { var doc = GetTemplate(); - string style = GetStyle(theme); + var style = GetStyle(theme); // Set theme var themeHtml = doc.GetElementbyId("theme"); @@ -134,7 +134,7 @@ namespace DiscordChatExporter.Services // Info var infoHtml = doc.GetElementbyId("info"); infoHtml.AppendChild(HtmlNode.CreateNode($"
Channel ID: {chatLog.ChannelId}
")); - string participants = HtmlDocument.HtmlEncode(chatLog.Participants.Select(u => u.Name).JoinToString(", ")); + var participants = HtmlDocument.HtmlEncode(chatLog.Participants.Select(u => u.Name).JoinToString(", ")); infoHtml.AppendChild(HtmlNode.CreateNode($"
Participants: {participants}
")); infoHtml.AppendChild(HtmlNode.CreateNode($"
Messages: {chatLog.Messages.Count:N0}
")); @@ -155,11 +155,11 @@ namespace DiscordChatExporter.Services var messageBodyHtml = messageHtml.AppendChild(HtmlNode.CreateNode("
")); // Author - string authorName = HtmlDocument.HtmlEncode(messageGroup.Author.Name); + var authorName = HtmlDocument.HtmlEncode(messageGroup.Author.Name); messageBodyHtml.AppendChild(HtmlNode.CreateNode($"{authorName}")); // Date - string timeStamp = HtmlDocument.HtmlEncode(messageGroup.FirstTimeStamp.ToString("g")); + var timeStamp = HtmlDocument.HtmlEncode(messageGroup.FirstTimeStamp.ToString("g")); messageBodyHtml.AppendChild(HtmlNode.CreateNode($"{timeStamp}")); // Individual messages @@ -168,7 +168,7 @@ namespace DiscordChatExporter.Services // Content if (message.Content.IsNotBlank()) { - string content = FormatMessageContent(message.Content); + var content = FormatMessageContent(message.Content); var contentHtml = messageBodyHtml.AppendChild( HtmlNode.CreateNode($"
{content}
"));