mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:21:23 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -45,7 +45,9 @@ type DiscordClientOpts = {
|
||||
|
||||
function resolveToken(params: { explicit?: string; accountId: string; fallbackToken?: string }) {
|
||||
const explicit = normalizeDiscordToken(params.explicit);
|
||||
if (explicit) return explicit;
|
||||
if (explicit) {
|
||||
return explicit;
|
||||
}
|
||||
const fallback = normalizeDiscordToken(params.fallbackToken);
|
||||
if (!fallback) {
|
||||
throw new Error(
|
||||
@@ -183,14 +185,18 @@ function normalizeDiscordPollInput(input: PollInput): RESTAPIPoll {
|
||||
}
|
||||
|
||||
function getDiscordErrorCode(err: unknown) {
|
||||
if (!err || typeof err !== "object") return undefined;
|
||||
if (!err || typeof err !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const candidate =
|
||||
"code" in err && err.code !== undefined
|
||||
? err.code
|
||||
: "rawError" in err && err.rawError && typeof err.rawError === "object"
|
||||
? (err.rawError as { code?: unknown }).code
|
||||
: undefined;
|
||||
if (typeof candidate === "number") return candidate;
|
||||
if (typeof candidate === "number") {
|
||||
return candidate;
|
||||
}
|
||||
if (typeof candidate === "string" && /^\d+$/.test(candidate)) {
|
||||
return Number(candidate);
|
||||
}
|
||||
@@ -206,7 +212,9 @@ async function buildDiscordSendError(
|
||||
hasMedia: boolean;
|
||||
},
|
||||
) {
|
||||
if (err instanceof DiscordSendError) return err;
|
||||
if (err instanceof DiscordSendError) {
|
||||
return err;
|
||||
}
|
||||
const code = getDiscordErrorCode(err);
|
||||
if (code === DISCORD_CANNOT_DM) {
|
||||
return new DiscordSendError(
|
||||
@@ -214,7 +222,9 @@ async function buildDiscordSendError(
|
||||
{ kind: "dm-blocked" },
|
||||
);
|
||||
}
|
||||
if (code !== DISCORD_MISSING_PERMISSIONS) return err;
|
||||
if (code !== DISCORD_MISSING_PERMISSIONS) {
|
||||
return err;
|
||||
}
|
||||
|
||||
let missing: string[] = [];
|
||||
try {
|
||||
@@ -288,7 +298,9 @@ async function sendDiscordText(
|
||||
maxLines: maxLinesPerMessage,
|
||||
chunkMode,
|
||||
});
|
||||
if (!chunks.length && text) chunks.push(text);
|
||||
if (!chunks.length && text) {
|
||||
chunks.push(text);
|
||||
}
|
||||
if (chunks.length === 1) {
|
||||
const res = (await request(
|
||||
() =>
|
||||
@@ -344,7 +356,9 @@ async function sendDiscordMedia(
|
||||
chunkMode,
|
||||
})
|
||||
: [];
|
||||
if (!chunks.length && text) chunks.push(text);
|
||||
if (!chunks.length && text) {
|
||||
chunks.push(text);
|
||||
}
|
||||
const caption = chunks[0] ?? "";
|
||||
const messageReference = replyTo ? { message_id: replyTo, fail_if_not_exists: false } : undefined;
|
||||
const res = (await request(
|
||||
@@ -365,7 +379,9 @@ async function sendDiscordMedia(
|
||||
"media",
|
||||
)) as { id: string; channel_id: string };
|
||||
for (const chunk of chunks.slice(1)) {
|
||||
if (!chunk.trim()) continue;
|
||||
if (!chunk.trim()) {
|
||||
continue;
|
||||
}
|
||||
await sendDiscordText(
|
||||
rest,
|
||||
channelId,
|
||||
|
||||
Reference in New Issue
Block a user