From c6337061696f9bdc6d604765a5023e8d0992597d Mon Sep 17 00:00:00 2001 From: "T.T" Date: Tue, 19 Apr 2022 22:29:47 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E6=A3=92=E8=AA=AD=E3=81=BF=E3=81=A1?= =?UTF-8?q?=E3=82=83=E3=82=93=E3=81=ABTwitch=E3=81=AE=E3=82=A8=E3=83=A2?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=81=AEID=E3=82=92=E8=AA=AD=E3=82=93?= =?UTF-8?q?=E3=81=A7=E3=82=82=E3=82=89=E3=81=88=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BouyomiPlugin/ConfigView.xaml | 2 ++ BouyomiPlugin/ConfigViewModel.cs | 8 ++++++++ BouyomiPlugin/Options.cs | 2 ++ BouyomiPlugin/main.cs | 9 ++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/BouyomiPlugin/ConfigView.xaml b/BouyomiPlugin/ConfigView.xaml index 0da9875a..e75135ce 100644 --- a/BouyomiPlugin/ConfigView.xaml +++ b/BouyomiPlugin/ConfigView.xaml @@ -187,6 +187,7 @@ + @@ -196,6 +197,7 @@ + diff --git a/BouyomiPlugin/ConfigViewModel.cs b/BouyomiPlugin/ConfigViewModel.cs index 79fc7354..ca143642 100644 --- a/BouyomiPlugin/ConfigViewModel.cs +++ b/BouyomiPlugin/ConfigViewModel.cs @@ -297,6 +297,14 @@ public bool IsTwitchCommentNickname get => _options.IsTwitchCommentNickname; set => _options.IsTwitchCommentNickname = value; } + /// + /// TwitchのコメントのエモートIDを読み上げるか + /// + public bool IsTwitchCommentEmoteId + { + get => _options.IsTwitchCommentEmoteId; + set => _options.IsTwitchCommentEmoteId = value; + } ///// ///// Twitchのアイテムを読み上げるか ///// diff --git a/BouyomiPlugin/Options.cs b/BouyomiPlugin/Options.cs index f4d5fa22..e301d902 100644 --- a/BouyomiPlugin/Options.cs +++ b/BouyomiPlugin/Options.cs @@ -53,6 +53,7 @@ class Options : DynamicOptionsBase public bool IsTwitchDisconnect { get { return GetValue(); } set { SetValue(value); } } public bool IsTwitchComment { get { return GetValue(); } set { SetValue(value); } } public bool IsTwitchCommentNickname { get { return GetValue(); } set { SetValue(value); } } + public bool IsTwitchCommentEmoteId { get { return GetValue(); } set { SetValue(value); } } //ニコ生 public bool IsNicoConnect { get { return GetValue(); } set { SetValue(value); } } @@ -178,6 +179,7 @@ protected override void Init() Dict.Add(nameof(IsTwitchDisconnect), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); Dict.Add(nameof(IsTwitchComment), new Item { DefaultValue = true, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); Dict.Add(nameof(IsTwitchCommentNickname), new Item { DefaultValue = true, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); + Dict.Add(nameof(IsTwitchCommentEmoteId), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); //ニコ生 Dict.Add(nameof(IsNicoConnect), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); diff --git a/BouyomiPlugin/main.cs b/BouyomiPlugin/main.cs index 280a3cc8..e0e55c6b 100644 --- a/BouyomiPlugin/main.cs +++ b/BouyomiPlugin/main.cs @@ -291,7 +291,14 @@ private static (string name, string comment) GetData(ISiteMessage message, Optio { name = (twitchMessage as ITwitchComment).DisplayName; } - comment = (twitchMessage as ITwitchComment).CommentItems.ToText(); + if (options.IsTwitchCommentEmoteId) + { + comment = (twitchMessage as ITwitchComment).CommentItems.ToTextWithImageAlt(); + } + else + { + comment = (twitchMessage as ITwitchComment).CommentItems.ToText(); + } } break; } From b317c3c37c2733bd5776a9cbd7866dda422c9400 Mon Sep 17 00:00:00 2001 From: "T.T" Date: Sun, 12 Jun 2022 18:15:56 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=80=8C=E8=AA=AD=E3=82=93=E3=81=A7?= =?UTF-8?q?=E3=82=82=E3=82=89=E3=81=86=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=80=8D=E3=82=BF=E3=83=96=E3=81=AE=E5=B7=A6=E5=81=B4?= =?UTF-8?q?=E3=82=92=E8=A9=B0=E3=82=81=E3=81=A6=E5=8F=B3=E5=81=B4=E3=82=92?= =?UTF-8?q?=E5=A2=97=E3=82=84=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BouyomiPlugin/ConfigView.xaml | 46 +++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/BouyomiPlugin/ConfigView.xaml b/BouyomiPlugin/ConfigView.xaml index e75135ce..a6ee4493 100644 --- a/BouyomiPlugin/ConfigView.xaml +++ b/BouyomiPlugin/ConfigView.xaml @@ -61,8 +61,8 @@ - - + + @@ -106,6 +106,8 @@ + + @@ -121,6 +123,8 @@ + + @@ -135,6 +139,8 @@ + + @@ -164,6 +170,8 @@ + + @@ -194,6 +202,8 @@ + + @@ -228,6 +238,8 @@ + + @@ -242,6 +254,8 @@ + + @@ -275,6 +289,8 @@ + + @@ -289,6 +305,8 @@ + + @@ -318,6 +336,8 @@ + + @@ -348,6 +368,8 @@ + + @@ -362,6 +384,8 @@ + + @@ -393,6 +417,8 @@ + + @@ -426,6 +452,8 @@ + + @@ -459,6 +487,8 @@ + + @@ -494,6 +524,8 @@ + + @@ -511,6 +543,8 @@ + + @@ -544,6 +578,8 @@ + + @@ -577,6 +613,8 @@ + + @@ -604,6 +642,8 @@ + + @@ -628,6 +668,8 @@ + + From a0a721cd5a5b7d2e8ba45914df1422ac9a0a30b4 Mon Sep 17 00:00:00 2001 From: "T.T" Date: Thu, 16 Jun 2022 02:58:11 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=83=BB=E8=AA=AD=E3=81=BF=E4=B8=8A?= =?UTF-8?q?=E3=81=92=E3=82=8B=E3=82=A8=E3=83=A2=E3=83=BC=E3=83=88=E3=81=AE?= =?UTF-8?q?=E6=95=B0=E3=82=92=E5=88=B6=E9=99=90=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=20=E3=83=BB?= =?UTF-8?q?=E9=80=A3=E7=B6=9A=E3=81=99=E3=82=8B=E5=90=8C=E4=B8=80=E3=82=A8?= =?UTF-8?q?=E3=83=A2=E3=83=BC=E3=83=88=E3=82=92=E3=82=B9=E3=82=AD=E3=83=83?= =?UTF-8?q?=E3=83=97=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BouyomiPlugin/ConfigView.xaml | 24 ++++++++++++++++- BouyomiPlugin/ConfigView.xaml.cs | 40 ++++++++++++++++++++++++++++ BouyomiPlugin/ConfigViewModel.cs | 16 ++++++++++++ BouyomiPlugin/Converter.cs | 19 ++++++++++++++ BouyomiPlugin/Options.cs | 4 +++ BouyomiPlugin/main.cs | 45 +++++++++++++++++++++++++++++++- 6 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 BouyomiPlugin/Converter.cs diff --git a/BouyomiPlugin/ConfigView.xaml b/BouyomiPlugin/ConfigView.xaml index a6ee4493..11baa566 100644 --- a/BouyomiPlugin/ConfigView.xaml +++ b/BouyomiPlugin/ConfigView.xaml @@ -8,6 +8,9 @@ d:DesignHeight="1500" d:DataContext="{d:DesignInstance local:ConfigViewModel, IsDesignTimeCreatable=True}" Title="棒読みちゃん連携プラグイン" Width="439" Background="#F0F0F0"> + + + @@ -196,6 +199,8 @@ + + @@ -207,7 +212,24 @@ - + + + + + + + + + + diff --git a/BouyomiPlugin/ConfigView.xaml.cs b/BouyomiPlugin/ConfigView.xaml.cs index bd014282..23f3760d 100644 --- a/BouyomiPlugin/ConfigView.xaml.cs +++ b/BouyomiPlugin/ConfigView.xaml.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -23,6 +24,7 @@ public partial class ConfigView : Window public ConfigView() { InitializeComponent(); + DataObject.AddPastingHandler(TwitchMaxEmotes, TextBoxPastingEventHandler); _isForceClose = false; } protected override void OnClosing(CancelEventArgs e) @@ -46,5 +48,43 @@ public void ForceClose() _isForceClose = true; this.Close(); } + + private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) + { + // 数字のみ入力可 + if (!Regex.IsMatch(e.Text, "[0-9]")) + { + e.Handled = true; + } + } + + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + { + if (e.Source is TextBox t) + { + if ((0 < t.MaxLength) && (t.MaxLength < t.Text.Length)) + { + int start = t.SelectionStart; + t.Text = t.Text.Substring(0, 3); + t.SelectionStart = start; + } + } + } + + private static void TextBoxPastingEventHandler(object sender, DataObjectPastingEventArgs e) + { + if (e.Source is TextBox t) + { + if (e.DataObject.GetData(typeof(string)) is string s) + { + // 数字のみ貼り付け可 + t.SelectedText = Regex.Replace(s, "[^0-9]", ""); + t.SelectionStart += t.SelectionLength; + t.SelectionLength = 0; + e.CancelCommand(); + e.Handled = true; + } + } + } } } diff --git a/BouyomiPlugin/ConfigViewModel.cs b/BouyomiPlugin/ConfigViewModel.cs index ca143642..9a54030c 100644 --- a/BouyomiPlugin/ConfigViewModel.cs +++ b/BouyomiPlugin/ConfigViewModel.cs @@ -305,6 +305,22 @@ public bool IsTwitchCommentEmoteId get => _options.IsTwitchCommentEmoteId; set => _options.IsTwitchCommentEmoteId = value; } + /// + /// TwitchのコメントのエモートIDを何個まで読み上げるか + /// + public int TwitchMaxEmotes + { + get { return _options.TwitchMaxEmotes; } + set { _options.TwitchMaxEmotes = value; } + } + /// + /// Twitchのコメントの連続する同一エモートを省略するか + /// + public bool IsTwitchSkipSameEmote + { + get { return _options.IsTwitchSkipSameEmote; } + set { _options.IsTwitchSkipSameEmote = value; } + } ///// ///// Twitchのアイテムを読み上げるか ///// diff --git a/BouyomiPlugin/Converter.cs b/BouyomiPlugin/Converter.cs new file mode 100644 index 00000000..9efee51a --- /dev/null +++ b/BouyomiPlugin/Converter.cs @@ -0,0 +1,19 @@ +using System; +using System.Globalization; +using System.Linq; +using System.Windows.Data; +namespace BouyomiPlugin +{ + public class AndConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + return values?.All(value => (bool)value) == true; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/BouyomiPlugin/Options.cs b/BouyomiPlugin/Options.cs index e301d902..2cbc6ca5 100644 --- a/BouyomiPlugin/Options.cs +++ b/BouyomiPlugin/Options.cs @@ -54,6 +54,8 @@ class Options : DynamicOptionsBase public bool IsTwitchComment { get { return GetValue(); } set { SetValue(value); } } public bool IsTwitchCommentNickname { get { return GetValue(); } set { SetValue(value); } } public bool IsTwitchCommentEmoteId { get { return GetValue(); } set { SetValue(value); } } + public bool IsTwitchSkipSameEmote { get { return GetValue(); } set { SetValue(value); } } + public int TwitchMaxEmotes { get { return GetValue(); } set { SetValue(value); } } //ニコ生 public bool IsNicoConnect { get { return GetValue(); } set { SetValue(value); } } @@ -180,6 +182,8 @@ protected override void Init() Dict.Add(nameof(IsTwitchComment), new Item { DefaultValue = true, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); Dict.Add(nameof(IsTwitchCommentNickname), new Item { DefaultValue = true, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); Dict.Add(nameof(IsTwitchCommentEmoteId), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); + Dict.Add(nameof(IsTwitchSkipSameEmote), new Item { DefaultValue = true, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); + Dict.Add(nameof(TwitchMaxEmotes), new Item { DefaultValue = 3, Predicate = n => true, Serializer = n => n.ToString(), Deserializer = n => int.Parse(n) }); //ニコ生 Dict.Add(nameof(IsNicoConnect), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) }); diff --git a/BouyomiPlugin/main.cs b/BouyomiPlugin/main.cs index e0e55c6b..2ae0874a 100644 --- a/BouyomiPlugin/main.cs +++ b/BouyomiPlugin/main.cs @@ -52,6 +52,49 @@ public static string ToTextWithImageAlt(this IEnumerable parts) } return s; } + public static string ToTextWithImageAlt(this IEnumerable parts, int maxImages, bool skipSameImage) + { + int n = 0; + string s = ""; + string previousImage = ""; + if (parts != null) + { + foreach (var part in parts) + { + if (part is IMessageText text) + { + if (!string.IsNullOrWhiteSpace(text.Text)) + { + previousImage = ""; + } + s += text; + } + else if (part is IMessageImage image) + { + if ((n < maxImages) && (!skipSameImage || !string.Equals(previousImage, image.Alt))) + { + s += image.Alt; + n++; + } + previousImage = image.Alt; + } + else if(part is IMessageRemoteSvg remoteSvg) + { + if ((n < maxImages) && (!skipSameImage || !string.Equals(previousImage, remoteSvg.Alt))) + { + s += remoteSvg.Alt; + n++; + } + previousImage = remoteSvg.Alt; + } + else + { + + } + } + } + return s; + } } [Export(typeof(IPlugin))] public class BouyomiPlugin : IPlugin, IDisposable @@ -293,7 +336,7 @@ private static (string name, string comment) GetData(ISiteMessage message, Optio } if (options.IsTwitchCommentEmoteId) { - comment = (twitchMessage as ITwitchComment).CommentItems.ToTextWithImageAlt(); + comment = (twitchMessage as ITwitchComment).CommentItems.ToTextWithImageAlt(options.TwitchMaxEmotes, options.IsTwitchSkipSameEmote); } else {