discord-bridge 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/package.json +1 -1
- package/server/index.js +31 -11
package/README.md
CHANGED
|
@@ -100,7 +100,6 @@ npm update -g discord-bridge
|
|
|
100
100
|
|
|
101
101
|
```bash
|
|
102
102
|
export DISCORD_BRIDGE_TOKEN="your_bot_token_here"
|
|
103
|
-
export DISCORD_BRIDGE_USER_ID="your_user_id_here"
|
|
104
103
|
```
|
|
105
104
|
|
|
106
105
|
設定後、`source ~/.zshrc` で反映してください(新しいターミナルを開く場合は不要です)。
|
|
@@ -111,11 +110,14 @@ Claude Code / Codex CLI を使うプロジェクトのルートに `.discord-bri
|
|
|
111
110
|
|
|
112
111
|
```json
|
|
113
112
|
{
|
|
114
|
-
"channelId": "your_channel_id_here"
|
|
113
|
+
"channelId": "your_channel_id_here",
|
|
114
|
+
"allowedUserIds": ["your_user_id_here"]
|
|
115
115
|
}
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
`allowedUserIds` に複数のユーザー ID を指定すると、全員の発言に応答します。1人目のユーザーが質問通知(`/ask`)のメンション対象になります。
|
|
119
|
+
|
|
120
|
+
> **Note**: `channelId` と `allowedUserIds` は秘密情報ではありませんが、プロジェクト固有の設定です。チームで共有する場合はそのままコミットし、個人用の場合は `.gitignore` に追加してください。
|
|
119
121
|
|
|
120
122
|
### 4. スキルのインストール
|
|
121
123
|
|
|
@@ -190,7 +192,7 @@ Discord で「戻ったよ」と伝えます。
|
|
|
190
192
|
| Bot がオフライン | `DISCORD_BRIDGE_TOKEN` が正しいか |
|
|
191
193
|
| メッセージが届かない | MESSAGE CONTENT INTENT が有効か |
|
|
192
194
|
| チャンネルが見つからない | `.discord-bridge.json` の `channelId` が正しいか |
|
|
193
|
-
| 返答が受信されない | `
|
|
195
|
+
| 返答が受信されない | `.discord-bridge.json` の `allowedUserIds` が正しいか |
|
|
194
196
|
|
|
195
197
|
## ライセンス
|
|
196
198
|
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import path from "path";
|
|
|
14
14
|
|
|
15
15
|
const CONFIG = {
|
|
16
16
|
token: process.env.DISCORD_BRIDGE_TOKEN,
|
|
17
|
-
|
|
17
|
+
allowedUserIds: [],
|
|
18
18
|
host: "127.0.0.1",
|
|
19
19
|
port: parseInt(process.env.DISCORD_BRIDGE_PORT || "13456", 10),
|
|
20
20
|
defaultTimeout: 5 * 60 * 1000,
|
|
@@ -24,14 +24,16 @@ const CONFIG = {
|
|
|
24
24
|
sseKeepAliveInterval: 30 * 1000,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
function isAllowedUser(authorId) {
|
|
28
|
+
return CONFIG.allowedUserIds.includes(authorId);
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
function validateConfig() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
throw new Error(
|
|
33
|
-
`Missing required environment variables: ${missing.join(", ")}`
|
|
34
|
-
);
|
|
32
|
+
if (!CONFIG.token) {
|
|
33
|
+
throw new Error("Missing required environment variable: DISCORD_BRIDGE_TOKEN");
|
|
34
|
+
}
|
|
35
|
+
if (CONFIG.allowedUserIds.length === 0) {
|
|
36
|
+
throw new Error("Missing required field in .discord-bridge.json: allowedUserIds (must have at least one entry)");
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -95,7 +97,7 @@ async function initDiscord() {
|
|
|
95
97
|
});
|
|
96
98
|
|
|
97
99
|
discordClient.on("messageCreate", (message) => {
|
|
98
|
-
if (message.author.id
|
|
100
|
+
if (!isAllowedUser(message.author.id)) return;
|
|
99
101
|
if (message.author.bot) return;
|
|
100
102
|
|
|
101
103
|
const chId = message.channel.id;
|
|
@@ -295,7 +297,7 @@ app.post("/ask", async (req, res) => {
|
|
|
295
297
|
fields,
|
|
296
298
|
});
|
|
297
299
|
|
|
298
|
-
await sendMessage(channelId, `<@${CONFIG.
|
|
300
|
+
await sendMessage(channelId, `<@${CONFIG.allowedUserIds[0]}>`, [embed]);
|
|
299
301
|
|
|
300
302
|
try {
|
|
301
303
|
const reply = await waitForReply(channelId, timeoutMs);
|
|
@@ -428,7 +430,7 @@ app.get("/messages", async (req, res) => {
|
|
|
428
430
|
const ch = await fetchChannel(channelId);
|
|
429
431
|
const fetched = await ch.messages.fetch({ limit: remaining });
|
|
430
432
|
const history = fetched
|
|
431
|
-
.filter((m) => m.author.id
|
|
433
|
+
.filter((m) => isAllowedUser(m.author.id) && !m.author.bot)
|
|
432
434
|
.map((m) => ({
|
|
433
435
|
content: m.content,
|
|
434
436
|
attachments: m.attachments.map((a) => ({
|
|
@@ -451,7 +453,25 @@ app.get("/messages", async (req, res) => {
|
|
|
451
453
|
// Lifecycle
|
|
452
454
|
// ---------------------------------------------------------------------------
|
|
453
455
|
|
|
456
|
+
async function loadProjectConfig() {
|
|
457
|
+
const configPath = path.join(process.cwd(), ".discord-bridge.json");
|
|
458
|
+
let projectConfig;
|
|
459
|
+
try {
|
|
460
|
+
const raw = await readFile(configPath, "utf-8");
|
|
461
|
+
projectConfig = JSON.parse(raw);
|
|
462
|
+
} catch {
|
|
463
|
+
throw new Error(`.discord-bridge.json not found or invalid JSON in ${process.cwd()}`);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (Array.isArray(projectConfig.allowedUserIds)) {
|
|
467
|
+
CONFIG.allowedUserIds = projectConfig.allowedUserIds.filter(
|
|
468
|
+
(id) => typeof id === "string"
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
454
473
|
async function main() {
|
|
474
|
+
await loadProjectConfig();
|
|
455
475
|
validateConfig();
|
|
456
476
|
await initDiscord();
|
|
457
477
|
|