|
1 | 1 | import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id"; |
2 | 2 | import { listCombinedAccountIds } from "openclaw/plugin-sdk/account-resolution"; |
3 | 3 | import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; |
4 | | -import { |
5 | | -hasConfiguredSecretInput, |
6 | | -normalizeSecretInputString, |
7 | | -} from "openclaw/plugin-sdk/secret-input"; |
| 4 | +import { inspectDiscordConfiguredToken } from "./account-token-inspect.js"; |
8 | 5 | import { resolveDefaultDiscordAccountId } from "./accounts.js"; |
9 | 6 | import { mergeDiscordAccountConfig, resolveDiscordAccountConfig } from "./accounts.js"; |
10 | 7 | import type { DiscordAccountConfig } from "./runtime-api.js"; |
@@ -20,29 +17,6 @@ type InspectedDiscordSetupAccount = {
|
20 | 17 | config: DiscordAccountConfig; |
21 | 18 | }; |
22 | 19 | |
23 | | -function inspectConfiguredToken(value: unknown): { |
24 | | -token: string; |
25 | | -tokenSource: "config"; |
26 | | -tokenStatus: "available" | "configured_unavailable"; |
27 | | -} | null { |
28 | | -const normalized = normalizeSecretInputString(value); |
29 | | -if (normalized) { |
30 | | -return { |
31 | | -token: normalized.replace(/^Bot\s+/i, ""), |
32 | | -tokenSource: "config", |
33 | | -tokenStatus: "available", |
34 | | -}; |
35 | | -} |
36 | | -if (hasConfiguredSecretInput(value)) { |
37 | | -return { |
38 | | -token: "", |
39 | | -tokenSource: "config", |
40 | | -tokenStatus: "configured_unavailable", |
41 | | -}; |
42 | | -} |
43 | | -return null; |
44 | | -} |
45 | | - |
46 | 20 | export function listDiscordSetupAccountIds(cfg: OpenClawConfig): string[] { |
47 | 21 | const accounts = cfg.channels?.discord?.accounts; |
48 | 22 | return listCombinedAccountIds({ |
@@ -82,7 +56,7 @@ export function inspectDiscordSetupAccount(params: {
|
82 | 56 | accountConfig && |
83 | 57 | Object.prototype.hasOwnProperty.call(accountConfig as Record<string, unknown>, "token"), |
84 | 58 | ); |
85 | | -const accountToken = inspectConfiguredToken(accountConfig?.token); |
| 59 | +const accountToken = inspectDiscordConfiguredToken(accountConfig?.token); |
86 | 60 | if (accountToken) { |
87 | 61 | return { |
88 | 62 | accountId, |
@@ -106,7 +80,7 @@ export function inspectDiscordSetupAccount(params: {
|
106 | 80 | }; |
107 | 81 | } |
108 | 82 | |
109 | | -const channelToken = inspectConfiguredToken(params.cfg.channels?.discord?.token); |
| 83 | +const channelToken = inspectDiscordConfiguredToken(params.cfg.channels?.discord?.token); |
110 | 84 | if (channelToken) { |
111 | 85 | return { |
112 | 86 | accountId, |
|