Skip to content

Commit 48fad49

Browse files
committed
設定とUIの更新: Nostr機能の追加
`FormAI.cs` でのインポートの整理、`FormMain.cs` に新しいプライベート変数 `_addNostrNpub1`、`_isSummarizing`、`_summarizeByEventCount` を追加し、サマリー処理の重複を防ぐためのフラグを導入しました。 `FormSetting.Designer.cs` では、`checkBoxAddNostrNpub1` を追加し、UI の `TabIndex` を調整しました。さらに、`Setting.cs` で `MentionMode` のデフォルト値を変更し、`AddNostrNpub1` プロパティを追加しました。
1 parent 6e79348 commit 48fad49

4 files changed

Lines changed: 72 additions & 30 deletions

File tree

kako/FormAI.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using GenerativeAI;
22
using GenerativeAI.Types;
33
using System.Diagnostics;
4-
using System.Linq;
54

65
namespace kako
76
{

kako/FormMain.cs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

kako/FormSetting.Designer.cs

Lines changed: 22 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kako/Setting.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public class Data
2929
public bool UsePetname { get; set; } = true;
3030
public bool SummarizeEveryHour { get; set; } = false;
3131
public int SummarizeMinutes { get; set; } = 0;
32-
public bool MentionMode { get; set; } = true;
32+
public bool MentionMode { get; set; } = false;
33+
public bool AddNostrNpub1 { get; set; } = false;
3334
public bool SummarizeByEventCount { get; set; } = false;
3435
public int EventThreshold { get; set; } = 100;
3536
public List<string> ForceCommands { get; set; } = [];
@@ -112,6 +113,11 @@ public static bool MentionMode
112113
get => _data.MentionMode;
113114
set => _data.MentionMode = value;
114115
}
116+
public static bool AddNostrNpub1
117+
{
118+
get => _data.AddNostrNpub1;
119+
set => _data.AddNostrNpub1 = value;
120+
}
115121
public static bool SummarizeByEventCount
116122
{
117123
get => _data.SummarizeByEventCount;

0 commit comments

Comments
 (0)