From 979e26d01aa7be99feed3c6bc75283e6619aba1e Mon Sep 17 00:00:00 2001 From: k0ta0uchi Date: Thu, 14 Nov 2019 07:43:50 +0900 Subject: [PATCH] =?UTF-8?q?#124=20Twitch=E3=81=AEDisplayName=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TwitchSitePlugin/CommentProvider.cs | 8 +++++++- TwitchSitePlugin/ICommentData.cs | 1 + TwitchSitePlugin/Tools.cs | 4 ++++ TwitchSitePlugin/TwitchCommentViewModel.cs | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/TwitchSitePlugin/CommentProvider.cs b/TwitchSitePlugin/CommentProvider.cs index 43f26a8d..2896e4c1 100644 --- a/TwitchSitePlugin/CommentProvider.cs +++ b/TwitchSitePlugin/CommentProvider.cs @@ -325,17 +325,22 @@ private void OnMessageReceived(Result result) { var commentData = ParsePrivMsg(result); var userId = commentData.UserId; + var displayName = commentData.DisplayName; var isFirstComment = _commentCounter.UpdateCount(userId); var user = GetUser(userId); if (_siteOptions.NeedAutoSubNickname) { SitePluginCommon.Utils.SetNickname(commentData.Message, user, _siteOptions.NeedAutoSubNicknameStr); } + if (displayName != commentData.Username) + { + displayName += " (" + commentData.Username + ")"; + } var message = new TwitchComment(result.Raw) { CommentItems = Tools.GetMessageItems(result), Id = commentData.Id, - NameItems = new List { MessagePartFactory.CreateMessageText(commentData.Username) }, + NameItems = new List { MessagePartFactory.CreateMessageText(displayName) }, PostTime = commentData.SentAt.ToString("HH:mm:ss"), UserId = commentData.UserId, }; @@ -497,6 +502,7 @@ class CommentData : ICommentData { public string UserId { get; set; } public string Username { get; set; } + public string DisplayName { get; set; } public string Message { get; set; } public string Emotes { get; set; } public string Id { get; set; } diff --git a/TwitchSitePlugin/ICommentData.cs b/TwitchSitePlugin/ICommentData.cs index 3b2c202a..72ed0fbc 100644 --- a/TwitchSitePlugin/ICommentData.cs +++ b/TwitchSitePlugin/ICommentData.cs @@ -7,6 +7,7 @@ interface ICommentData string Message { get; } string UserId { get; } string Username { get; } + string DisplayName { get; } System.DateTime SentAt { get; } } } \ No newline at end of file diff --git a/TwitchSitePlugin/Tools.cs b/TwitchSitePlugin/Tools.cs index e64827bf..4417e161 100644 --- a/TwitchSitePlugin/Tools.cs +++ b/TwitchSitePlugin/Tools.cs @@ -39,6 +39,10 @@ public static ICommentData ParsePrivMsg(Result result) { commentData.UserId = userId; } + if (result.Tags.TryGetValue("display-name", out string displayName)) + { + commentData.DisplayName = displayName; + } if(result.Tags.TryGetValue("tmi-sent-ts", out string ts)) { var unix = new DateTime(1970, 1, 1).AddMilliseconds(long.Parse(ts)); diff --git a/TwitchSitePlugin/TwitchCommentViewModel.cs b/TwitchSitePlugin/TwitchCommentViewModel.cs index d75eea74..a8adb2b0 100644 --- a/TwitchSitePlugin/TwitchCommentViewModel.cs +++ b/TwitchSitePlugin/TwitchCommentViewModel.cs @@ -8,6 +8,7 @@ class TwitchCommentViewModel : CommentViewModelBase { public override MessageType MessageType { get; protected set; } public override string UserId { get; } + public string DisplayName { get; } private readonly ITwitchSiteOptions _siteOptions; public TwitchCommentViewModel(ICommentOptions options, ITwitchSiteOptions siteOptions, ICommentData commentData, bool isFirstComment, ICommentProvider commentProvider, IUser user) @@ -17,6 +18,7 @@ public TwitchCommentViewModel(ICommentOptions options, ITwitchSiteOptions siteOp _siteOptions = siteOptions; Id = commentData.Id; UserId = commentData.UserId; + DisplayName = commentData.DisplayName; PostTime = commentData.SentAt.ToString("HH:mm:ss"); var name = commentData.Username;