Skip to content

Commit bfaed12

Browse files
authored
Merge pull request #52 from shin902/translate-comments-to-japanese
docs: ソースコードの英語コメントを日本語に翻訳
2 parents 2773b42 + 3edcfdd commit bfaed12

16 files changed

Lines changed: 241 additions & 241 deletions

src/channels/discord.test.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
22

3-
// --- Mocks ---
3+
// --- モック ---
44

5-
// Mock registry (registerChannel runs at import time)
5+
// レジストリのモック(registerChannel はインポート時に実行される)
66
vi.mock('./registry.js', () => ({ registerChannel: vi.fn() }));
77

8-
// Mock env reader (used by the factory, not needed in unit tests)
8+
// 環境変数リーダーのモック(ファクトリで使用されるが、ユニットテストでは不要)
99
vi.mock('../env.js', () => ({ readEnvFile: vi.fn(() => ({})) }));
1010

11-
// Mock config
11+
// 設定のモック
1212
vi.mock('../config.js', () => ({
1313
ASSISTANT_NAME: 'Andy',
1414
TRIGGER_PATTERN: /^@Andy\b/i,
1515
}));
1616

17-
// Mock logger
17+
// ロガーのモック
1818
vi.mock('../logger.js', () => ({
1919
logger: {
2020
debug: vi.fn(),
@@ -24,7 +24,7 @@ vi.mock('../logger.js', () => ({
2424
},
2525
}));
2626

27-
// --- discord.js mock ---
27+
// --- discord.js のモック ---
2828

2929
type Handler = (...args: any[]) => any;
3030

@@ -76,7 +76,7 @@ vi.mock('discord.js', () => {
7676

7777
async login(_token: string) {
7878
this._ready = true;
79-
// Fire the ready event
79+
// ready イベントを発火させる
8080
const readyHandlers = this.eventHandlers.get('ready') || [];
8181
for (const h of readyHandlers) {
8282
h({ user: this.user });
@@ -99,10 +99,10 @@ vi.mock('discord.js', () => {
9999
}
100100
}
101101

102-
// Mock TextChannel type
102+
// TextChannel 型のモック
103103
class TextChannel {}
104104

105-
// Mock ThreadChannel type
105+
// ThreadChannel 型のモック
106106
class ThreadChannel {}
107107

108108
return {
@@ -117,7 +117,7 @@ vi.mock('discord.js', () => {
117117

118118
import { DiscordChannel, DiscordChannelOpts } from './discord.js';
119119

120-
// --- Test helpers ---
120+
// --- テスト用ヘルパー ---
121121

122122
function createTestOpts(
123123
overrides?: Partial<DiscordChannelOpts>,
@@ -159,7 +159,7 @@ function createMessage(overrides: {
159159
}) {
160160
const channelId = overrides.channelId ?? '1234567890123456';
161161
const authorId = overrides.authorId ?? '55512345';
162-
const botId = '999888777'; // matches mock client user id
162+
const botId = '999888777'; // モッククライアントのユーザーIDと一致
163163
const isThreadChannel = overrides.isThread ?? false;
164164

165165
const mentionsMap = new Map();
@@ -216,7 +216,7 @@ async function triggerMessage(message: any) {
216216
for (const h of handlers) await h(message);
217217
}
218218

219-
// --- Tests ---
219+
// --- テスト ---
220220

221221
describe('DiscordChannel', () => {
222222
beforeEach(() => {
@@ -227,7 +227,7 @@ describe('DiscordChannel', () => {
227227
vi.restoreAllMocks();
228228
});
229229

230-
// --- Connection lifecycle ---
230+
// --- 接続ライフサイクル ---
231231

232232
describe('connection lifecycle', () => {
233233
it('resolves connect() when client is ready', async () => {
@@ -269,7 +269,7 @@ describe('DiscordChannel', () => {
269269
});
270270
});
271271

272-
// --- Text message handling ---
272+
// --- テキストメッセージ処理 ---
273273

274274
describe('text message handling', () => {
275275
it('delivers message for registered channel', async () => {
@@ -436,7 +436,7 @@ describe('DiscordChannel', () => {
436436
});
437437
});
438438

439-
// --- @mention translation ---
439+
// --- @メンション変換 ---
440440

441441
describe('@mention translation', () => {
442442
it('translates <@botId> mention to trigger format', async () => {
@@ -471,8 +471,8 @@ describe('DiscordChannel', () => {
471471
});
472472
await triggerMessage(msg);
473473

474-
// Should NOT prepend @Andy — already starts with trigger
475-
// But the <@botId> should still be stripped
474+
// @Andy を先頭に付加しない — すでにトリガーで始まっている
475+
// ただし <@botId> は除去される
476476
expect(opts.onMessage).toHaveBeenCalledWith(
477477
'dc:1234567890123456',
478478
expect.objectContaining({
@@ -521,7 +521,7 @@ describe('DiscordChannel', () => {
521521
});
522522
});
523523

524-
// --- Attachments ---
524+
// --- 添付ファイル ---
525525

526526
describe('attachments', () => {
527527
it('stores image attachment with placeholder', async () => {
@@ -641,7 +641,7 @@ describe('DiscordChannel', () => {
641641
});
642642
});
643643

644-
// --- Reply context ---
644+
// --- リプライ文脈 ---
645645

646646
describe('reply context', () => {
647647
it('includes reply author in content', async () => {
@@ -665,7 +665,7 @@ describe('DiscordChannel', () => {
665665
});
666666
});
667667

668-
// --- sendMessage ---
668+
// --- メッセージ送信 ---
669669

670670
describe('sendMessage', () => {
671671
it('sends message via channel', async () => {
@@ -701,7 +701,7 @@ describe('DiscordChannel', () => {
701701
new Error('Channel not found'),
702702
);
703703

704-
// Should not throw
704+
// 例外を投げないこと
705705
await expect(
706706
channel.sendMessage('dc:1234567890123456', 'Will fail'),
707707
).resolves.toBeUndefined();
@@ -711,10 +711,10 @@ describe('DiscordChannel', () => {
711711
const opts = createTestOpts();
712712
const channel = new DiscordChannel('test-token', new Set(), opts);
713713

714-
// Don't connect — client is null
714+
// 接続しない — client null
715715
await channel.sendMessage('dc:1234567890123456', 'No client');
716716

717-
// No error, no API call
717+
// エラーも API 呼び出しもない
718718
});
719719

720720
it('splits messages exceeding 2000 characters', async () => {
@@ -737,7 +737,7 @@ describe('DiscordChannel', () => {
737737
});
738738
});
739739

740-
// --- createThread ---
740+
// --- スレッド作成 ---
741741

742742
describe('createThread', () => {
743743
it('creates message-linked thread when messageId is provided', async () => {
@@ -831,7 +831,7 @@ describe('DiscordChannel', () => {
831831
});
832832
});
833833

834-
// --- ownsJid ---
834+
// --- JID の所有判定 ---
835835

836836
describe('ownsJid', () => {
837837
it('owns dc: JIDs', () => {
@@ -871,7 +871,7 @@ describe('DiscordChannel', () => {
871871
});
872872
});
873873

874-
// --- setTyping ---
874+
// --- タイピング表示 ---
875875

876876
describe('setTyping', () => {
877877
it('sends typing indicator when isTyping is true', async () => {
@@ -897,22 +897,22 @@ describe('DiscordChannel', () => {
897897

898898
await channel.setTyping('dc:1234567890123456', false);
899899

900-
// channels.fetch should NOT be called
900+
// channels.fetch は呼ばれないこと
901901
expect(currentClient().channels.fetch).not.toHaveBeenCalled();
902902
});
903903

904904
it('does nothing when client is not initialized', async () => {
905905
const opts = createTestOpts();
906906
const channel = new DiscordChannel('test-token', new Set(), opts);
907907

908-
// Don't connect
908+
// 接続しない
909909
await channel.setTyping('dc:1234567890123456', true);
910910

911-
// No error
911+
// エラーは出ない
912912
});
913913
});
914914

915-
// --- Channel properties ---
915+
// --- チャンネルプロパティ ---
916916

917917
describe('channel properties', () => {
918918
it('has name "discord"', () => {
@@ -925,7 +925,7 @@ describe('DiscordChannel', () => {
925925
});
926926
});
927927

928-
// --- Allowed bot filtering ---
928+
// --- 許可Botフィルタリング ---
929929

930930
describe('allowed bot filtering', () => {
931931
const ALLOWED_BOT_ID = '111222333444555666';
@@ -1019,7 +1019,7 @@ describe('DiscordChannel', () => {
10191019
});
10201020
});
10211021

1022-
// --- Thread detection ---
1022+
// --- スレッド検出 ---
10231023

10241024
describe('thread detection', () => {
10251025
it('sets is_thread=true and place_type=public_thread for thread messages', async () => {
@@ -1123,7 +1123,7 @@ describe('DiscordChannel', () => {
11231123
});
11241124
await triggerMessage(msg);
11251125

1126-
// Should deliver even though thread itself is not registered yet
1126+
// スレッド自体はまだ登録されていないが配信されること
11271127
expect(opts.onMessage).toHaveBeenCalledWith(
11281128
`dc:${threadId}`,
11291129
expect.objectContaining({
@@ -1143,7 +1143,7 @@ describe('DiscordChannel', () => {
11431143
folder: 'test-server',
11441144
trigger: '@Andy',
11451145
added_at: '2024-01-01T00:00:00.000Z',
1146-
// no thread_defaults
1146+
// thread_defaults なし
11471147
},
11481148
})),
11491149
});

src/channels/discord.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class DiscordChannel implements Channel {
101101
const sender = message.author.id;
102102
const msgId = message.id;
103103

104-
// Determine chat name
104+
// チャット名を決定する
105105
let chatName: string;
106106
if (message.guild) {
107107
if (isThread && message.channel.isThread()) {
@@ -116,16 +116,16 @@ export class DiscordChannel implements Channel {
116116
chatName = senderName;
117117
}
118118

119-
// Resolve parent JID for thread messages
119+
// スレッドメッセージの親JIDを解決する
120120
let parentJid: string | undefined;
121121
if (isThread && message.channel.isThread() && message.channel.parentId) {
122122
parentJid = `dc:${message.channel.parentId}`;
123123
}
124124

125-
// Translate Discord @bot mentions into TRIGGER_PATTERN format.
126-
// Discord mentions look like <@botUserId> — these won't match
127-
// TRIGGER_PATTERN (e.g., ^@Andy\b), so we prepend the trigger
128-
// when the bot is @mentioned.
125+
// Discord @bot メンションを TRIGGER_PATTERN 形式に変換する。
126+
// Discord のメンションは <@botUserId> のような形式で、
127+
// TRIGGER_PATTERN(例: ^@Andy\b)には一致しないため、
128+
// bot @mentioned されたときにトリガーを先頭に付加する。
129129
if (this.client?.user) {
130130
const botId = this.client.user.id;
131131
const isBotMentioned =
@@ -134,18 +134,18 @@ export class DiscordChannel implements Channel {
134134
content.includes(`<@!${botId}>`);
135135

136136
if (isBotMentioned) {
137-
// Strip the <@botId> mention to avoid visual clutter
137+
// 視覚的なノイズを避けるため <@botId> メンションを除去する
138138
content = content
139139
.replace(new RegExp(`<@!?${botId}>`, 'g'), '')
140140
.trim();
141-
// Prepend trigger if not already present
141+
// トリガーがまだ先頭にない場合は付加する
142142
if (!TRIGGER_PATTERN.test(content)) {
143143
content = `@${ASSISTANT_NAME} ${content}`;
144144
}
145145
}
146146
}
147147

148-
// Handle attachments — store placeholders so the agent knows something was sent
148+
// 添付ファイルを処理 — プレースホルダーを保存してエージェントに送信内容を伝える
149149
if (message.attachments.size > 0) {
150150
const attachmentDescriptions = [...message.attachments.values()].map(
151151
(att) => {
@@ -168,7 +168,7 @@ export class DiscordChannel implements Channel {
168168
}
169169
}
170170

171-
// Handle reply context — include who the user is replying to
171+
// リプライ文脈を処理 — 誰への返信かを含める
172172
if (message.reference?.messageId) {
173173
try {
174174
const repliedTo = await message.channel.messages.fetch(
@@ -180,11 +180,11 @@ export class DiscordChannel implements Channel {
180180
repliedTo.author.username;
181181
content = `[Reply to ${replyAuthor}] ${content}`;
182182
} catch {
183-
// Referenced message may have been deleted
183+
// 参照元メッセージが削除されている可能性がある
184184
}
185185
}
186186

187-
// Store chat metadata for discovery
187+
// 発見用にチャットメタデータを保存する
188188
const isGroup = message.guild !== null;
189189
this.opts.onChatMetadata(
190190
chatJid,
@@ -194,15 +194,15 @@ export class DiscordChannel implements Channel {
194194
isGroup,
195195
);
196196

197-
// Only deliver full message for registered groups.
198-
// Exception: thread messages from channels whose parent has thread_defaults
199-
// are allowed through so index.ts can auto-register the thread group.
197+
// 登録済みグループのみ完全なメッセージを配信する。
198+
// 例外: thread_defaults を持つ親チャンネルのスレッドメッセージは、
199+
// index.ts がスレッドグループを自動登録できるよう通過させる。
200200
const group = this.opts.registeredGroups()[chatJid];
201201
if (!group) {
202202
if (parentJid) {
203203
const parentGroup = this.opts.registeredGroups()[parentJid];
204204
if (parentGroup?.thread_defaults) {
205-
// Auto-registration candidate — fall through to deliver the message
205+
// 自動登録候補 — メッセージ配信をそのまま続行する
206206
} else {
207207
logger.debug(
208208
{ chatJid, chatName },
@@ -219,9 +219,9 @@ export class DiscordChannel implements Channel {
219219
}
220220
}
221221

222-
// Deliver message — startMessageLoop() will pick it up.
223-
// InboundMessage extends NewMessage with Discord-specific metadata
224-
// (place_type, actor_role, is_thread, parent_jid) that is callback-only and not persisted.
222+
// メッセージを配信 — startMessageLoop() が取得する。
223+
// InboundMessage NewMessage を拡張し、Discord 固有のメタデータ
224+
// (place_type, actor_role, is_thread, parent_jid) を含むが、これらはコールバック専用で永続化されない。
225225
const inbound: InboundMessage = {
226226
id: msgId,
227227
chat_jid: chatJid,
@@ -243,7 +243,7 @@ export class DiscordChannel implements Channel {
243243
);
244244
});
245245

246-
// Handle errors gracefully
246+
// エラーを適切に処理する
247247
this.client.on(Events.Error, (err) => {
248248
logger.error({ err: err.message }, 'Discord client error');
249249
});
@@ -292,7 +292,7 @@ export class DiscordChannel implements Channel {
292292

293293
const textChannel = channel as TextChannel;
294294

295-
// Discord has a 2000 character limit per message — split if needed
295+
// Discord は1メッセージあたり2000文字の制限がある — 必要に応じて分割する
296296
const MAX_LENGTH = 2000;
297297
if (text.length <= MAX_LENGTH) {
298298
await textChannel.send(text);

0 commit comments

Comments
 (0)