@@ -55,6 +55,7 @@ public partial class FormMain : Form
5555 private bool _summarizeEveryHour ;
5656 private int _summarizeMinutes ;
5757 private bool _mentionMode ;
58+ private bool _addNostrNpub1 ;
5859 private bool _summarizeByEventCount ;
5960 private int _eventThreshold ;
6061 private List < string > _forceCommands = [ ] ;
@@ -83,6 +84,9 @@ public partial class FormMain : Form
8384 // スタミナ管理
8485 private int _callReplyCount = 0 ;
8586 private bool _alreadyPostedBreakMessage = false ;
87+
88+ // まとめ中
89+ private bool _isSummarizing = false ;
8690 #endregion
8791
8892 #region コンストラクタ
@@ -150,6 +154,7 @@ public FormMain()
150154 _summarizeEveryHour = Setting . SummarizeEveryHour ;
151155 _summarizeMinutes = Setting . SummarizeMinutes ;
152156 _mentionMode = Setting . MentionMode ;
157+ _addNostrNpub1 = Setting . AddNostrNpub1 ;
153158 _summarizeByEventCount = Setting . SummarizeByEventCount ;
154159 _eventThreshold = Setting . EventThreshold ;
155160 _forceCommands = Setting . ForceCommands ;
@@ -843,7 +848,7 @@ private async Task MentionAsync(string content)
843848 var newEvent = new NostrEvent ( )
844849 {
845850 Kind = 1 ,
846- Content = "nostr:" + _director + " " + content . Replace ( "\r \n " , "\n " ) ,
851+ Content = ( _addNostrNpub1 ? "nostr:" + _director + " " : "" ) + content . Replace ( "\r \n " , "\n " ) ,
847852 Tags = tags
848853 } ;
849854
@@ -979,6 +984,8 @@ private async void ButtonSetting_Click(object sender, EventArgs e)
979984 _formSetting . checkBoxSummarizeEveryHour . Checked = _summarizeEveryHour ;
980985 _formSetting . numericUpDownSummarizeMinutes . Value = _summarizeMinutes ;
981986 _formSetting . checkBoxMentionMode . Checked = _mentionMode ;
987+ _formSetting . checkBoxAddNostrNpub1 . Checked = _addNostrNpub1 ;
988+ _formSetting . checkBoxSummarizeByEventCount . Checked = _summarizeByEventCount ;
982989 _formSetting . numericUpDownEventThreshold . Value = _eventThreshold ;
983990 _formSetting . textBoxForceCommands . Text = string . Join ( "\r \n " , _forceCommands ) ;
984991 _formSetting . textBoxCallCommands . Text = string . Join ( "\r \n " , _callCommands ) ;
@@ -1005,6 +1012,7 @@ private async void ButtonSetting_Click(object sender, EventArgs e)
10051012 _summarizeEveryHour = _formSetting . checkBoxSummarizeEveryHour . Checked ;
10061013 _summarizeMinutes = ( int ) _formSetting . numericUpDownSummarizeMinutes . Value ;
10071014 _mentionMode = _formSetting . checkBoxMentionMode . Checked ;
1015+ _addNostrNpub1 = _formSetting . checkBoxAddNostrNpub1 . Checked ;
10081016 _summarizeByEventCount = _formSetting . checkBoxSummarizeByEventCount . Checked ;
10091017 _eventThreshold = ( int ) _formSetting . numericUpDownEventThreshold . Value ;
10101018 _forceCommands = [ .. _formSetting . textBoxForceCommands . Text . Split ( [ "\r \n " ] , StringSplitOptions . RemoveEmptyEntries ) ] ;
@@ -1084,6 +1092,7 @@ private async void ButtonSetting_Click(object sender, EventArgs e)
10841092 Setting . SummarizeEveryHour = _summarizeEveryHour ;
10851093 Setting . SummarizeMinutes = _summarizeMinutes ;
10861094 Setting . MentionMode = _mentionMode ;
1095+ Setting . AddNostrNpub1 = _addNostrNpub1 ;
10871096 Setting . SummarizeByEventCount = _summarizeByEventCount ;
10881097 Setting . EventThreshold = _eventThreshold ;
10891098 Setting . ForceCommands = _forceCommands ;
@@ -1686,29 +1695,46 @@ private async void DailyTimerCallback(object? state)
16861695 // まとめ投稿
16871696 private async Task SummarizeAndPostAsync ( )
16881697 {
1689- if ( ! _formAI . IsInitialized )
1698+ if ( _isSummarizing )
16901699 {
1691- LastCreatedAt = DateTimeOffset . MinValue ;
1692- LatestCreatedAt = DateTimeOffset . MinValue ;
1700+ return ;
16931701 }
1694- bool success = await _formAI . SummarizeNotesAsync ( ) ;
1695- // 1秒待つ
1696- await Task . Delay ( 1000 ) ;
1697- string answerText = string . Empty ;
1698- Invoke ( ( MethodInvoker ) ( ( ) => answerText = _formAI . textBoxAnswer . Text . TrimEnd ( '\r ' , '\n ' ) ) ) ;
1699- if ( string . IsNullOrEmpty ( _director ) || ! _mentionMode )
1702+ _isSummarizing = true ;
1703+
1704+ try
17001705 {
1701- await PostAsync ( answerText ) ;
1706+ if ( ! _formAI . IsInitialized )
1707+ {
1708+ LastCreatedAt = DateTimeOffset . MinValue ;
1709+ LatestCreatedAt = DateTimeOffset . MinValue ;
1710+ }
1711+ bool success = await _formAI . SummarizeNotesAsync ( ) ;
1712+ // 1秒待つ
1713+ await Task . Delay ( 1000 ) ;
1714+ string answerText = string . Empty ;
1715+ Invoke ( ( MethodInvoker ) ( ( ) => answerText = _formAI . textBoxAnswer . Text . TrimEnd ( '\r ' , '\n ' ) ) ) ;
1716+ if ( string . IsNullOrEmpty ( _director ) || ! _mentionMode )
1717+ {
1718+ await PostAsync ( answerText ) ;
1719+ }
1720+ else
1721+ {
1722+ await MentionAsync ( answerText ) ;
1723+ }
1724+ if ( success )
1725+ {
1726+ dataGridViewNotes . Invoke ( ( MethodInvoker ) ( ( ) => dataGridViewNotes . Rows . Clear ( ) ) ) ;
1727+ GC . Collect ( ) ;
1728+ GC . WaitForPendingFinalizers ( ) ;
1729+ }
17021730 }
1703- else
1731+ catch ( Exception ex )
17041732 {
1705- await MentionAsync ( answerText ) ;
1733+ Debug . WriteLine ( $ "定時投稿エラー: { ex . Message } " ) ;
17061734 }
1707- if ( success )
1735+ finally
17081736 {
1709- dataGridViewNotes . Invoke ( ( MethodInvoker ) ( ( ) => dataGridViewNotes . Rows . Clear ( ) ) ) ;
1710- GC . Collect ( ) ;
1711- GC . WaitForPendingFinalizers ( ) ;
1737+ _isSummarizing = false ;
17121738 }
17131739 }
17141740 #endregion
0 commit comments