mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 21:24:31 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -63,7 +63,9 @@ function buildDiscordCommandOptions(params: {
|
||||
}): CommandOptions | undefined {
|
||||
const { command, cfg } = params;
|
||||
const args = command.args;
|
||||
if (!args || args.length === 0) return undefined;
|
||||
if (!args || args.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return args.map((arg) => {
|
||||
const required = arg.required ?? false;
|
||||
if (arg.type === "number") {
|
||||
@@ -121,7 +123,9 @@ function readDiscordCommandArgs(
|
||||
interaction: CommandInteraction,
|
||||
definitions?: CommandArgDefinition[],
|
||||
): CommandArgs | undefined {
|
||||
if (!definitions || definitions.length === 0) return undefined;
|
||||
if (!definitions || definitions.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
const values: CommandArgValues = {};
|
||||
for (const definition of definitions) {
|
||||
let value: string | number | boolean | null | undefined;
|
||||
@@ -140,7 +144,9 @@ function readDiscordCommandArgs(
|
||||
}
|
||||
|
||||
function chunkItems<T>(items: T[], size: number): T[][] {
|
||||
if (size <= 0) return [items];
|
||||
if (size <= 0) {
|
||||
return [items];
|
||||
}
|
||||
const rows: T[][] = [];
|
||||
for (let i = 0; i < items.length; i += size) {
|
||||
rows.push(items.slice(i, i + size));
|
||||
@@ -168,16 +174,24 @@ function decodeDiscordCommandArgValue(value: string): string {
|
||||
}
|
||||
|
||||
function isDiscordUnknownInteraction(error: unknown): boolean {
|
||||
if (!error || typeof error !== "object") return false;
|
||||
if (!error || typeof error !== "object") {
|
||||
return false;
|
||||
}
|
||||
const err = error as {
|
||||
discordCode?: number;
|
||||
status?: number;
|
||||
message?: string;
|
||||
rawBody?: { code?: number; message?: string };
|
||||
};
|
||||
if (err.discordCode === 10062 || err.rawBody?.code === 10062) return true;
|
||||
if (err.status === 404 && /Unknown interaction/i.test(err.message ?? "")) return true;
|
||||
if (/Unknown interaction/i.test(err.rawBody?.message ?? "")) return true;
|
||||
if (err.discordCode === 10062 || err.rawBody?.code === 10062) {
|
||||
return true;
|
||||
}
|
||||
if (err.status === 404 && /Unknown interaction/i.test(err.message ?? "")) {
|
||||
return true;
|
||||
}
|
||||
if (/Unknown interaction/i.test(err.rawBody?.message ?? "")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -213,14 +227,18 @@ function buildDiscordCommandArgCustomId(params: {
|
||||
function parseDiscordCommandArgData(
|
||||
data: ComponentData,
|
||||
): { command: string; arg: string; value: string; userId: string } | null {
|
||||
if (!data || typeof data !== "object") return null;
|
||||
if (!data || typeof data !== "object") {
|
||||
return null;
|
||||
}
|
||||
const coerce = (value: unknown) =>
|
||||
typeof value === "string" || typeof value === "number" ? String(value) : "";
|
||||
const rawCommand = coerce(data.command);
|
||||
const rawArg = coerce(data.arg);
|
||||
const rawValue = coerce(data.value);
|
||||
const rawUser = coerce(data.user);
|
||||
if (!rawCommand || !rawArg || !rawValue || !rawUser) return null;
|
||||
if (!rawCommand || !rawArg || !rawValue || !rawUser) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
command: decodeDiscordCommandArgValue(rawCommand),
|
||||
arg: decodeDiscordCommandArgValue(rawArg),
|
||||
@@ -273,7 +291,9 @@ async function handleDiscordCommandArgInteraction(
|
||||
components: [],
|
||||
}),
|
||||
);
|
||||
if (!updated) return;
|
||||
if (!updated) {
|
||||
return;
|
||||
}
|
||||
const commandArgs = createCommandArgsWithValue({
|
||||
argName: parsed.arg,
|
||||
value: parsed.value,
|
||||
@@ -502,7 +522,9 @@ async function dispatchDiscordCommandInteraction(params: {
|
||||
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
const user = interaction.user;
|
||||
if (!user) return;
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
const channel = interaction.channel;
|
||||
const channelType = channel?.type;
|
||||
const isDirectMessage = channelType === ChannelType.DM;
|
||||
@@ -851,25 +873,35 @@ async function deliverDiscordInteractionReply(params: {
|
||||
maxLines: maxLinesPerMessage,
|
||||
chunkMode,
|
||||
});
|
||||
if (!chunks.length && text) chunks.push(text);
|
||||
if (!chunks.length && text) {
|
||||
chunks.push(text);
|
||||
}
|
||||
const caption = chunks[0] ?? "";
|
||||
await sendMessage(caption, media);
|
||||
for (const chunk of chunks.slice(1)) {
|
||||
if (!chunk.trim()) continue;
|
||||
if (!chunk.trim()) {
|
||||
continue;
|
||||
}
|
||||
await interaction.followUp({ content: chunk });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!text.trim()) return;
|
||||
if (!text.trim()) {
|
||||
return;
|
||||
}
|
||||
const chunks = chunkDiscordTextWithMode(text, {
|
||||
maxChars: textLimit,
|
||||
maxLines: maxLinesPerMessage,
|
||||
chunkMode,
|
||||
});
|
||||
if (!chunks.length && text) chunks.push(text);
|
||||
if (!chunks.length && text) {
|
||||
chunks.push(text);
|
||||
}
|
||||
for (const chunk of chunks) {
|
||||
if (!chunk.trim()) continue;
|
||||
if (!chunk.trim()) {
|
||||
continue;
|
||||
}
|
||||
await sendMessage(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user