mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-11 18:36:45 +02:00
Use var
This commit is contained in:
parent
34afce2a66
commit
fb3b14f1ce
3 changed files with 24 additions and 24 deletions
|
@ -17,11 +17,11 @@ namespace DiscordChatExporter
|
|||
{
|
||||
// Parse the arguments
|
||||
var argsDic = new Dictionary<string, string>(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())
|
||||
|
|
|
@ -19,10 +19,10 @@ namespace DiscordChatExporter.Services
|
|||
foreach (var messageJson in messagesJson)
|
||||
{
|
||||
// Get basic data
|
||||
string id = messageJson.Value<string>("id");
|
||||
var id = messageJson.Value<string>("id");
|
||||
var timeStamp = messageJson.Value<DateTime>("timestamp");
|
||||
var editedTimeStamp = messageJson.Value<DateTime?>("edited_timestamp");
|
||||
string content = messageJson.Value<string>("content");
|
||||
var content = messageJson.Value<string>("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<string>("id");
|
||||
string authorName = authorJson.Value<string>("username");
|
||||
string authorAvatarHash = authorJson.Value<string>("avatar");
|
||||
var authorId = authorJson.Value<string>("id");
|
||||
var authorName = authorJson.Value<string>("username");
|
||||
var authorAvatarHash = authorJson.Value<string>("avatar");
|
||||
|
||||
// Get attachment
|
||||
var attachmentsJson = messageJson["attachments"];
|
||||
var attachments = new List<Attachment>();
|
||||
foreach (var attachmentJson in attachmentsJson)
|
||||
{
|
||||
string attachmentId = attachmentJson.Value<string>("id");
|
||||
string attachmentUrl = attachmentJson.Value<string>("url");
|
||||
string attachmentFileName = attachmentJson.Value<string>("filename");
|
||||
bool attachmentIsImage = attachmentJson["width"] != null;
|
||||
var attachmentId = attachmentJson.Value<string>("id");
|
||||
var attachmentUrl = attachmentJson.Value<string>("url");
|
||||
var attachmentFileName = attachmentJson.Value<string>("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);
|
||||
|
|
|
@ -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($"<div>Channel ID: <b>{chatLog.ChannelId}</b></div>"));
|
||||
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($"<div>Participants: <b>{participants}</b></div>"));
|
||||
infoHtml.AppendChild(HtmlNode.CreateNode($"<div>Messages: <b>{chatLog.Messages.Count:N0}</b></div>"));
|
||||
|
||||
|
@ -155,11 +155,11 @@ namespace DiscordChatExporter.Services
|
|||
var messageBodyHtml = messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-body\"></div>"));
|
||||
|
||||
// Author
|
||||
string authorName = HtmlDocument.HtmlEncode(messageGroup.Author.Name);
|
||||
var authorName = HtmlDocument.HtmlEncode(messageGroup.Author.Name);
|
||||
messageBodyHtml.AppendChild(HtmlNode.CreateNode($"<span class=\"msg-user\">{authorName}</span>"));
|
||||
|
||||
// Date
|
||||
string timeStamp = HtmlDocument.HtmlEncode(messageGroup.FirstTimeStamp.ToString("g"));
|
||||
var timeStamp = HtmlDocument.HtmlEncode(messageGroup.FirstTimeStamp.ToString("g"));
|
||||
messageBodyHtml.AppendChild(HtmlNode.CreateNode($"<span class=\"msg-date\">{timeStamp}</span>"));
|
||||
|
||||
// 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($"<div class=\"msg-content\">{content}</div>"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue